Package org.antlr.v4.tool

Examples of org.antlr.v4.tool.LexerGrammar


    String expecting = "INT, WS, INT, EOF";
    checkLexerMatches(lg, "32 99", expecting);
  }

  @Test public void testRecursiveLexerRuleRef() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "CMT : '/*' (CMT | ~'*')+ '*/' ;\n" +
      "WS : (' '|'\\n')+ ;");
    String expecting = "CMT, WS, CMT, EOF";
    checkLexerMatches(lg, "/* ick */\n/* /*nested*/ */", expecting);
View Full Code Here


    String expecting = "CMT, WS, CMT, EOF";
    checkLexerMatches(lg, "/* ick */\n/* /*nested*/ */", expecting);
  }

  @Test public void testRecursiveLexerRuleRefWithWildcard() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "CMT : '/*' (CMT | .)*? '*/' ;\n" +
      "WS : (' '|'\\n')+ ;");

    String expecting = "CMT, WS, CMT, WS, EOF";
View Full Code Here

              "/* /*nested*/ */\n",
              expecting);
  }

  @Test public void testLexerWildcardGreedyLoopByDefault() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "CMT : '//' .* '\\n' ;\n");
    String expecting = "CMT, EOF";
    checkLexerMatches(lg, "//x\n//y\n", expecting);
  }
View Full Code Here

    String expecting = "CMT, EOF";
    checkLexerMatches(lg, "//x\n//y\n", expecting);
  }

  @Test public void testLexerWildcardLoopExplicitNonGreedy() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "CMT : '//' .*? '\\n' ;\n");
    String expecting = "CMT, CMT, EOF";
    checkLexerMatches(lg, "//x\n//y\n", expecting);
  }
View Full Code Here

    String expecting = "CMT, CMT, EOF";
    checkLexerMatches(lg, "//x\n//y\n", expecting);
  }

  @Test public void testLexerEscapeInString() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "STR : '[' ('~' ']' | .)* ']' ;\n");
    checkLexerMatches(lg, "[a~]b]", "STR, EOF");
    checkLexerMatches(lg, "[a]", "STR, EOF");
  }
View Full Code Here

    checkLexerMatches(lg, "[a~]b]", "STR, EOF");
    checkLexerMatches(lg, "[a]", "STR, EOF");
  }

  @Test public void testLexerWildcardGreedyPlusLoopByDefault() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "CMT : '//' .+ '\\n' ;\n");
    String expecting = "CMT, EOF";
    checkLexerMatches(lg, "//x\n//y\n", expecting);
  }
View Full Code Here

    String expecting = "CMT, EOF";
    checkLexerMatches(lg, "//x\n//y\n", expecting);
  }

  @Test public void testLexerWildcardExplicitNonGreedyPlusLoop() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "CMT : '//' .+? '\\n' ;\n");
    String expecting = "CMT, CMT, EOF";
    checkLexerMatches(lg, "//x\n//y\n", expecting);
  }
View Full Code Here

    checkLexerMatches(lg, "//x\n//y\n", expecting);
  }

  // does not fail since ('*/')? can't match and have rule succeed
  @Test public void testLexerGreedyOptionalShouldWorkAsWeExpect() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "CMT : '/*' ('*/')? '*/' ;\n");
    String expecting = "CMT, EOF";
    checkLexerMatches(lg, "/**/", expecting);
  }
View Full Code Here

    String expecting = "CMT, EOF";
    checkLexerMatches(lg, "/**/", expecting);
  }

  @Test public void testGreedyBetweenRules() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "A : '<a>' ;\n" +
      "B : '<' .+ '>' ;\n");
    String expecting = "B, EOF";
    checkLexerMatches(lg, "<a><x>", expecting);
View Full Code Here

    String expecting = "B, EOF";
    checkLexerMatches(lg, "<a><x>", expecting);
  }

  @Test public void testNonGreedyBetweenRules() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "A : '<a>' ;\n" +
      "B : '<' .+? '>' ;\n");
    String expecting = "A, B, EOF";
    checkLexerMatches(lg, "<a><x>", expecting);
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.