Package org.antlr.v4.tool

Examples of org.antlr.v4.tool.Grammar


    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }

  @Test public void testPEGAchillesHeel() throws Exception {
    Grammar g = new Grammar(
      "parser grammar T;\n"+
      "a : A | A B ;");
    String expecting =
      "max type 2\n" +
        "0:RULE_START 0\n" +
        "1:RULE_STOP 0\n" +
        "2:BASIC 0\n" +
        "3:BASIC 0\n" +
        "4:BASIC 0\n" +
        "5:BLOCK_START 0 6\n" +
        "6:BLOCK_END 0\n" +
        "7:BASIC 0\n" +
        "rule 0:0\n" +
        "0->5 EPSILON 0,0,0\n" +
        "2->6 ATOM 1,0,0\n" +
        "3->4 ATOM 1,0,0\n" +
        "4->6 ATOM 2,0,0\n" +
        "5->2 EPSILON 0,0,0\n" +
        "5->3 EPSILON 0,0,0\n" +
        "6->1 EPSILON 0,0,0\n" +
        "0:5\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here


    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }

  @Test public void test3Alts() throws Exception {
    Grammar g = new Grammar(
      "parser grammar T;\n"+
      "a : A | A B | A B C ;");
    String expecting =
      "max type 3\n" +
        "0:RULE_START 0\n" +
        "1:RULE_STOP 0\n" +
        "2:BASIC 0\n" +
        "3:BASIC 0\n" +
        "4:BASIC 0\n" +
        "5:BASIC 0\n" +
        "6:BASIC 0\n" +
        "7:BASIC 0\n" +
        "8:BLOCK_START 0 9\n" +
        "9:BLOCK_END 0\n" +
        "10:BASIC 0\n" +
        "rule 0:0\n" +
        "0->8 EPSILON 0,0,0\n" +
        "2->9 ATOM 1,0,0\n" +
        "3->4 ATOM 1,0,0\n" +
        "4->9 ATOM 2,0,0\n" +
        "5->6 ATOM 1,0,0\n" +
        "6->7 ATOM 2,0,0\n" +
        "7->9 ATOM 3,0,0\n" +
        "8->2 EPSILON 0,0,0\n" +
        "8->3 EPSILON 0,0,0\n" +
        "8->5 EPSILON 0,0,0\n" +
        "9->1 EPSILON 0,0,0\n" +
        "0:8\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }

  @Test public void testSimpleLoop() throws Exception {
    Grammar g = new Grammar(
      "parser grammar T;\n"+
      "a : A+ B ;");
    String expecting =
      "max type 2\n" +
        "0:RULE_START 0\n" +
        "1:RULE_STOP 0\n" +
        "2:BASIC 0\n" +
        "3:PLUS_BLOCK_START 0 4\n" +
        "4:BLOCK_END 0\n" +
        "5:PLUS_LOOP_BACK 0\n" +
        "6:LOOP_END 0 5\n" +
        "7:BASIC 0\n" +
        "8:BASIC 0\n" +
        "9:BASIC 0\n" +
        "rule 0:0\n" +
        "0->3 EPSILON 0,0,0\n" +
        "2->4 ATOM 1,0,0\n" +
        "3->2 EPSILON 0,0,0\n" +
        "4->5 EPSILON 0,0,0\n" +
        "5->3 EPSILON 0,0,0\n" +
        "5->6 EPSILON 0,0,0\n" +
        "6->7 EPSILON 0,0,0\n" +
        "7->8 ATOM 2,0,0\n" +
        "8->1 EPSILON 0,0,0\n" +
        "0:5\n";
    ATN atn = createATN(g, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(g.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

    @Test public void testArgs() throws Exception {
        for (int i = 0; i < argPairs.length; i+=2) {
            String input = argPairs[i];
            String expected = argPairs[i+1];
      Grammar dummy = new Grammar("grammar T; a:'a';");
      String actual = ScopeParser.parseTypedArgList(null, input, dummy).attributes.toString();
            assertEquals(expected, actual);
        }
    }
View Full Code Here

  List<ANTLRMessage> checkRuleDFA(String gtext, String ruleName, String expecting)
    throws Exception
  {
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(gtext, equeue);
    ATN atn = createATN(g, false);
    ATNState s = atn.ruleToStartState[g.getRule(ruleName).index];
    if ( s==null ) {
      System.err.println("no such rule: "+ruleName);
      return null;
    }
    ATNState t = s.transition(0).target;
View Full Code Here

  List<ANTLRMessage> checkRuleDFA(String gtext, int decision, String expecting)
    throws Exception
  {
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(gtext, equeue);
    ATN atn = createATN(g, false);
    DecisionState blk = atn.decisionToState.get(decision);
    checkRuleDFA(g, blk, expecting);
    return equeue.all;
  }
View Full Code Here

    STGroup group = new STGroupString(templates);
    ST st = group.getInstanceOf(name);
    st.add(actionName, action);
    String grammar = st.render();
    ErrorQueue equeue = new ErrorQueue();
    Grammar g = new Grammar(grammar, equeue);
    if ( g.ast!=null && !g.ast.hasErrors ) {
      SemanticPipeline sem = new SemanticPipeline(g);
      sem.process();

      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();
      String output = outputFileST.render();
View Full Code Here

  public void checkForQualifiedRuleIssues(Grammar g, List<GrammarAST> qualifiedRuleRefs) {
    for (GrammarAST dot : qualifiedRuleRefs) {
      GrammarAST grammar = (GrammarAST)dot.getChild(0);
      GrammarAST rule = (GrammarAST)dot.getChild(1);
            g.tool.log("semantics", grammar.getText()+"."+rule.getText());
      Grammar delegate = g.getImportedGrammar(grammar.getText());
      if ( delegate==null ) {
        errMgr.grammarError(ErrorType.NO_SUCH_GRAMMAR_SCOPE,
                      g.fileName, grammar.token, grammar.getText(),
                      rule.getText());
      }
View Full Code Here

  public void processGrammarsOnCommandLine() {
    List<GrammarRootAST> sortedGrammars = sortGrammarByTokenVocab(grammarFiles);

    for (GrammarRootAST t : sortedGrammars) {
      final Grammar g = createGrammar(t);
      g.fileName = t.fileName;
      if ( gen_dependencies ) {
        BuildDependencyGenerator dep =
          new BuildDependencyGenerator(this, g);
        /*
 
View Full Code Here

        return Grammar.parserOptions.contains(key);
    }
  }

  void checkImport(Token importID) {
    Grammar delegate = g.getImportedGrammar(importID.getText());
    if ( delegate==null ) return;
    List<Integer> validDelegators = validImportTypes.get(delegate.getType());
    if ( validDelegators!=null && !validDelegators.contains(g.getType()) ) {
      g.tool.errMgr.grammarError(ErrorType.INVALID_IMPORT,
                     g.fileName,
                     importID,
                     g, delegate);
View Full Code Here

TOP

Related Classes of org.antlr.v4.tool.Grammar

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.