Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.AutoIndentWriter


    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

    if (lexerAction != null) {
      return action(ID, lexerAction);
    }

    // fall back to standard action generation for the command
    ST cmdST = codegenTemplates.getInstanceOf("Lexer" +
                          CharSupport.capitalize(ID.getText())+
                          "Command");
    if (cmdST == null) {
      g.tool.errMgr.grammarError(ErrorType.INVALID_LEXER_COMMAND, g.fileName, ID.token, ID.getText());
      return epsilon(ID);
    }

    if (cmdST.impl.formalArguments == null || !cmdST.impl.formalArguments.containsKey("arg")) {
      g.tool.errMgr.grammarError(ErrorType.UNWANTED_LEXER_COMMAND_ARGUMENT, g.fileName, ID.token, ID.getText());
      return epsilon(ID);
    }

    cmdST.add("arg", arg.getText());
    return action(cmdST.render());
  }
View Full Code Here

    if (lexerAction != null) {
      return action(ID, lexerAction);
    }

    // fall back to standard action generation for the command
    ST cmdST = codegenTemplates.getInstanceOf("Lexer" +
                          CharSupport.capitalize(ID.getText())+
                          "Command");
    if (cmdST == null) {
      g.tool.errMgr.grammarError(ErrorType.INVALID_LEXER_COMMAND, g.fileName, ID.token, ID.getText());
      return epsilon(ID);
    }

    if (cmdST.impl.formalArguments != null && cmdST.impl.formalArguments.containsKey("arg")) {
      g.tool.errMgr.grammarError(ErrorType.MISSING_LEXER_COMMAND_ARGUMENT, g.fileName, ID.token, ID.getText());
      return epsilon(ID);
    }

    return action(cmdST.render());
  }
View Full Code Here

TOP

Related Classes of org.stringtemplate.v4.AutoIndentWriter

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.