Package org.antlr.v4.tool

Examples of org.antlr.v4.tool.LexerGrammar


    };
    checkDFAConstruction(lg, g, decision, inputs, dfa);
  }

  @Test public void testOptionalRuleChasesGlobalFollow() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n");
    Grammar g = new Grammar(
View Full Code Here


    };
    checkDFAConstruction(lg, g, decision, inputs, dfa);
  }

  @Test public void testLL1Ambig() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n");
    Grammar g = new Grammar(
View Full Code Here

    };
    checkDFAConstruction(lg, g, decision, inputs, dfa);
  }

  @Test public void testLL2Ambig() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n");
    Grammar g = new Grammar(
View Full Code Here

    };
    checkDFAConstruction(lg, g, decision, inputs, dfa);
  }

  @Test public void testRecursiveLeftPrefix() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n" +
      "LP : '(' ;\n" +
View Full Code Here

    };
    checkDFAConstruction(lg, g, decision, inputs, dfa);
  }

  @Test public void testRecursiveLeftPrefixWithAorABIssue() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "A : 'a' ;\n" +
      "B : 'b' ;\n" +
      "C : 'c' ;\n" +
      "LP : '(' ;\n" +
View Full Code Here

  @Test public void testContinuePrediction() throws Exception {
    // Sam found prev def of ambiguity was too restrictive.
    // E.g., (13, 1, []), (13, 2, []), (12, 2, []) should not
    // be declared ambig since (12, 2, []) can take us to
    // unambig state maybe. keep going.
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "ID : 'a'..'z' ;\n" + // one char
      "SEMI : ';' ;\n"+
      "INT : '0'..'9'+ ;\n"
    );
View Full Code Here

    checkPredictedAlt(lg, g, decision, "ab;", 2);
  }

  @Test public void testContinuePrediction2() throws Exception {
    // ID is ambig for first two alts, but ID SEMI lets us move forward with alt 3
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n" +
      "ID : 'a'..'z' ;\n" + // one char
      "SEMI : ';' ;\n"+
      "INT : '0'..'9'+ ;\n"
    );
View Full Code Here

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

  @Test public void testLexerTwoRules() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "A : 'a' ;\n" +
      "B : 'b' ;\n");
    String expecting =
      "max type 2\n" +
      "0:TOKEN_START -1\n" +
      "1:RULE_START 0\n" +
      "2:RULE_STOP 0\n" +
      "3:RULE_START 1\n" +
      "4:RULE_STOP 1\n" +
      "5:BASIC 0\n" +
      "6:BASIC 0\n" +
      "7:BASIC 1\n" +
      "8:BASIC 1\n" +
      "rule 0:1 1\n" +
      "rule 1:3 2\n" +
      "mode 0:0\n" +
      "0->1 EPSILON 0,0,0\n" +
      "0->3 EPSILON 0,0,0\n" +
      "1->5 EPSILON 0,0,0\n" +
      "3->7 EPSILON 0,0,0\n" +
      "5->6 ATOM 97,0,0\n" +
      "6->2 EPSILON 0,0,0\n" +
      "7->8 ATOM 98,0,0\n" +
      "8->4 EPSILON 0,0,0\n" +
      "0:0\n";
    ATN atn = createATN(lg, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

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

  @Test public void testLexerRange() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "INT : '0'..'9' ;\n");
    String expecting =
      "max type 1\n" +
      "0:TOKEN_START -1\n" +
      "1:RULE_START 0\n" +
      "2:RULE_STOP 0\n" +
      "3:BASIC 0\n" +
      "4:BASIC 0\n" +
      "rule 0:1 1\n" +
      "mode 0:0\n" +
      "0->1 EPSILON 0,0,0\n" +
      "1->3 EPSILON 0,0,0\n" +
      "3->4 RANGE 48,57,0\n" +
      "4->2 EPSILON 0,0,0\n" +
      "0:0\n";
    ATN atn = createATN(lg, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

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

  @Test public void testLexerEOF() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "INT : 'a' EOF ;\n");
    String expecting =
      "max type 1\n" +
        "0:TOKEN_START -1\n" +
        "1:RULE_START 0\n" +
        "2:RULE_STOP 0\n" +
        "3:BASIC 0\n" +
        "4:BASIC 0\n" +
        "5:BASIC 0\n" +
        "rule 0:1 1\n" +
        "mode 0:0\n" +
        "0->1 EPSILON 0,0,0\n" +
        "1->3 EPSILON 0,0,0\n" +
        "3->4 ATOM 97,0,0\n" +
        "4->5 ATOM 0,0,1\n" +
        "5->2 EPSILON 0,0,0\n" +
        "0:0\n";
    ATN atn = createATN(lg, true);
    String result = ATNSerializer.getDecoded(atn, Arrays.asList(lg.getTokenNames()));
    assertEquals(expecting, result);
  }
View Full Code Here

TOP

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

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.