Package org.stringtemplate.v4

Examples of org.stringtemplate.v4.AutoIndentWriter


    // error information possible, but actually writing output files stops
    // after the first error is reported
    int errorCount = g.tool.errMgr.getNumErrors();

    if ( g.isLexer() ) {
      ST lexer = gen.generateLexer();
      if (g.tool.errMgr.getNumErrors() == errorCount) {
        writeRecognizer(lexer, gen);
      }
    }
    else {
      ST parser = gen.generateParser();
      if (g.tool.errMgr.getNumErrors() == errorCount) {
        writeRecognizer(parser, gen);
      }
      if ( g.tool.gen_listener ) {
        ST listener = gen.generateListener();
        if (g.tool.errMgr.getNumErrors() == errorCount) {
          gen.writeListener(listener);
        }
        if (gen.getTarget().wantsBaseListener()) {
          ST baseListener = gen.generateBaseListener();
          if (g.tool.errMgr.getNumErrors() == errorCount) {
            gen.writeBaseListener(baseListener);
          }
        }
      }
      if ( g.tool.gen_visitor ) {
        ST visitor = gen.generateVisitor();
        if (g.tool.errMgr.getNumErrors() == errorCount) {
          gen.writeVisitor(visitor);
        }
        if (gen.getTarget().wantsBaseVisitor()) {
          ST baseVisitor = gen.generateBaseVisitor();
          if (g.tool.errMgr.getNumErrors() == errorCount) {
            gen.writeBaseVisitor(baseVisitor);
          }
        }
      }
View Full Code Here


      column = offendingToken.getCharPositionInLine();
    }
    if ( g!=null ) {
      file = g.getFileName();
    }
    ST st = getMessageTemplate();
    if ( arg!=null ) {
      st.add("arg", arg);
    }
    if ( arg2!=null ) {
      st.add("arg2", arg2);
    }
    return super.toString(st);
  }
View Full Code Here

    String fileName = probe.dfa.nfa.grammar.getFileName();
    if ( fileName!=null ) {
      file = fileName;
    }

    ST st = getMessageTemplate();

    if ( probe.dfa.isTokensRuleDecision() ) {
      // alts are token rules, convert to the names instead of numbers
      for (int i = 0; i < alts.size(); i++) {
        Integer altI = alts.get(i);
        String tokenName =
          probe.getTokenNameForTokensRuleAlt(altI);
        // reset the line/col to the token definition
        NFAState ruleStart =
          probe.dfa.nfa.grammar.getRuleStartState(tokenName);
        line = ruleStart.associatedASTNode.getLine();
        column = ruleStart.associatedASTNode.getCharPositionInLine();
        st.add("tokens", tokenName);
      }
    }
    else {
      // regular alt numbers, show the alts
      st.add("alts", alts);
    }

    return super.toString(st);
  }
View Full Code Here

    if ( fileName!=null ) {
      file = fileName;
    }
    List<Label> labels = probe.getSampleNonDeterministicInputSequence(problemState);
    String input = probe.getInputSequenceDisplay(labels);
    ST st = getMessageTemplate();
    List<Integer> alts = new ArrayList<Integer>();
    alts.addAll(problemState.getAltSet());
    Collections.sort(alts);
    st.add("danglingAlts", alts);
    st.add("input", input);

    return super.toString(st);
  }
View Full Code Here

    column = decisionASTNode.getCharPositionInLine();
    String fileName = probe.dfa.nfa.grammar.getFileName();
    if ( fileName!=null ) {
      file = fileName;
    }
    ST st = getMessageTemplate();
    // convert to string key to avoid 3.1 ST bug
    Map<String, Set<Token>> altToLocationsWithStringKey = new LinkedHashMap<String, Set<Token>>();
    List<Integer> alts = new ArrayList<Integer>();
    alts.addAll(altToLocations.keySet());
    Collections.sort(alts);
    for (Integer altI : alts) {
      altToLocationsWithStringKey.put(altI.toString(), altToLocations.get(altI));
      /*
      List<String> tokens = new ArrayList<String>();
      for (Token t : altToLocations.get(altI)) {
        tokens.add(t.toString());
      }
      Collections.sort(tokens);
      System.out.println("tokens=\n"+tokens);
      */
    }
    st.add("altToLocations", altToLocationsWithStringKey);

    List<Label> sampleInputLabels = problemState.dfa.probe.getSampleNonDeterministicInputSequence(problemState);
    String input = problemState.dfa.probe.getInputSequenceDisplay(sampleInputLabels);
    st.add("upon", input);

    st.add("hasPredicateBlockedByAction", problemState.dfa.hasPredicateBlockedByAction);

    return super.toString(st);
  }
View Full Code Here

    setFileName(fileName);
    // ensure we have the composite set to something
    if ( composite.delegateGrammarTreeRoot==null ) {
      composite.setDelegationRoot(this);
    }
    STGroup lexerGrammarSTG = new STGroupString(lexerGrammarTemplate);
    lexerGrammarST = lexerGrammarSTG.getInstanceOf("grammar");
    target = CodeGenerator.loadLanguageTarget((String) getOption("language"));
  }
View Full Code Here

  public Grammar(Tool tool) {
    setTool(tool);
    builtFromString = true;
    composite = new CompositeGrammar(this);
    STGroup lexerGrammarSTG = new STGroupString(lexerGrammarTemplate);
    lexerGrammarST = lexerGrammarSTG.getInstanceOf("grammar");
    target = CodeGenerator.loadLanguageTarget((String)getOption("language"));
  }
View Full Code Here

        // new output dir for each test
        tmpdir = new File(System.getProperty("java.io.tmpdir"),
              "antlr-"+getClass().getName()+"-"+
              System.currentTimeMillis()).getAbsolutePath();
        ErrorManager.resetErrorState();
        STGroup.defaultGroup = new STGroup();
    }
View Full Code Here

    return getBadWords().contains(idNode.getText());
  }

  @Override
  protected STGroup loadTemplates() {
    STGroup result = targetTemplates.get();
    if (result == null) {
      result = super.loadTemplates();
      result.registerRenderer(String.class, new JavaStringRenderer(), true);
      targetTemplates.set(result);
    }

    return result;
  }
View Full Code Here

  public static void setLocale(Locale locale) {
    ErrorManager.locale = locale;
    String language = locale.getLanguage();
    String fileName = "org/antlr/tool/templates/messages/languages/"+language+".stg";
    try {
      messages = new STGroupFile(fileName);
    }
    catch (IllegalArgumentException iae) {
      if ( language.equals(Locale.US.getLanguage()) ) {
        rawError("ANTLR installation corrupted; cannot find English messages file "+fileName);
        panic();
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.