Package org.stringtemplate.v4.test

Examples of org.stringtemplate.v4.test.TestDebugEvents


      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

    // 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

TOP

Related Classes of org.stringtemplate.v4.test.TestDebugEvents

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.