Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.ST


    // TODO: actually set the right Grammar instance to get the filename
    // TODO: have to update all v2 grammar files for this. or use errormanager and tool to get the current grammar
    if (g != null) {
      file = g.getFileName();
    }
    ST st = getMessageTemplate();
    if ( arg!=null ) {
      st.add("arg", arg);
    }
    return super.toString(st);
  }
View Full Code Here


    errors = 0;
    warnings = 0;
  }

  public ST getMessageTemplate(ANTLRMessage msg) {
    ST messageST = msg.getMessageTemplate(tool.longMessages);
    ST locationST = getLocationFormat();
    ST reportST = getReportFormat(msg.getErrorType().severity);
    ST messageFormatST = getMessageFormat();

    boolean locationValid = false;
    if (msg.line != -1) {
      locationST.add("line", msg.line);
      locationValid = true;
    }
    if (msg.charPosition != -1) {
      locationST.add("column", msg.charPosition);
      locationValid = true;
    }
    if (msg.fileName != null) {
      File f = new File(msg.fileName);
      // Don't show path to file in messages; too long.
      String displayFileName = msg.fileName;
      if ( f.exists() ) {
        displayFileName = f.getName();
      }
      locationST.add("file", displayFileName);
      locationValid = true;
    }

    messageFormatST.add("id", msg.getErrorType().code);
    messageFormatST.add("text", messageST);

    if (locationValid) reportST.add("location", locationST);
    reportST.add("message", messageFormatST);
    //((DebugST)reportST).inspect();
//    reportST.impl.dump();
View Full Code Here

    public ST getLocationFormat() {
        return format.getInstanceOf("location");
    }

    public ST getReportFormat(ErrorSeverity severity) {
        ST st = format.getInstanceOf("report");
        st.add("type", severity.getText());
        return st;
    }
View Full Code Here

        e.printStackTrace(System.err);
    }

  public void panic(ErrorType errorType, Object... args) {
    ToolMessage msg = new ToolMessage(errorType, args);
    ST msgST = getMessageTemplate(msg);
    String outputMsg = msgST.render();
    if ( formatWantsSingleLineMessage() ) {
      outputMsg = outputMsg.replace('\n', ' ');
    }
    panic(outputMsg);
  }
View Full Code Here

    return args;
    }

  public ST getMessageTemplate(boolean verbose) {
    ST messageST = new ST(getErrorType().msg);
    messageST.impl.name = errorType.name();

    messageST.add("verbose", verbose);
    Object[] args = getArgs();
    for (int i=0; i<args.length; i++) {
      String attr = "arg";
      if ( i>0 ) attr += i + 1;
      messageST.add(attr, args[i]);
    }
    if ( args.length<2 ) messageST.add("arg2", null); // some messages ref arg2

    Throwable cause = getCause();
    if ( cause!=null ) {
      messageST.add("exception", cause);
      messageST.add("stackTrace", cause.getStackTrace());
    }
    else {
      messageST.add("exception", null); // avoid ST error msg
      messageST.add("stackTrace", null);
    }

    return messageST;
  }
View Full Code Here

  }

  // --------- get transformed rules ----------------

  public String getArtificialOpPrecRule() {
    ST ruleST = recRuleTemplates.getInstanceOf("recRule");
    ruleST.add("ruleName", ruleName);
    ST ruleArgST = codegenTemplates.getInstanceOf("recRuleArg");
    ruleST.add("argName", ruleArgST);
    ST setResultST = codegenTemplates.getInstanceOf("recRuleSetResultAction");
    ruleST.add("setResultAction", setResultST);
    ruleST.add("userRetvals", retvals);

    LinkedHashMap<Integer, LeftRecursiveRuleAltInfo> opPrecRuleAlts = new LinkedHashMap<Integer, LeftRecursiveRuleAltInfo>();
    opPrecRuleAlts.putAll(binaryAlts);
    opPrecRuleAlts.putAll(ternaryAlts);
    opPrecRuleAlts.putAll(suffixAlts);
    for (int alt : opPrecRuleAlts.keySet()) {
      LeftRecursiveRuleAltInfo altInfo = opPrecRuleAlts.get(alt);
      ST altST = recRuleTemplates.getInstanceOf("recRuleAlt");
      ST predST = codegenTemplates.getInstanceOf("recRuleAltPredicate");
      predST.add("opPrec", precedence(alt));
      predST.add("ruleName", ruleName);
      altST.add("pred", predST);
      altST.add("alt", altInfo);
      altST.add("precOption", LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME);
      altST.add("opPrec", precedence(alt));
      ruleST.add("opAlts", altST);
View Full Code Here

      throw new IllegalStateException(String.format("No %s instance is available.", Tool.class.getName()));
    }

    StringBuilder buf = new StringBuilder();
    for (ANTLRMessage m : all) {
      ST st = tool.errMgr.getMessageTemplate(m);
      buf.append(st.render());
      buf.append("\n");
    }

    return buf.toString();
  }
View Full Code Here

      ATNFactory factory = new ParserATNFactory(g);
      if (g.isLexer()) factory = new LexerATNFactory((LexerGrammar) g);
      g.atn = factory.createATN();

      CodeGenerator gen = new CodeGenerator(g);
      ST outputFileST = gen.generateParser();

//      STViz viz = outputFileST.inspect();
//      try {
//        viz.waitForClose();
//      }
View Full Code Here

    System.out.println(msg);
  }

  @Override
  public void error(ANTLRMessage msg) {
    ST msgST = tool.errMgr.getMessageTemplate(msg);
    String outputMsg = msgST.render();
    if (tool.errMgr.formatWantsSingleLineMessage()) {
      outputMsg = outputMsg.replace('\n', ' ');
    }
    System.err.println(outputMsg);
  }
View Full Code Here

    System.err.println(outputMsg);
  }

  @Override
  public void warning(ANTLRMessage msg) {
    ST msgST = tool.errMgr.getMessageTemplate(msg);
    String outputMsg = msgST.render();
    if (tool.errMgr.formatWantsSingleLineMessage()) {
      outputMsg = outputMsg.replace('\n', ' ');
    }
    System.err.println(outputMsg);
  }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.ST

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.