Package org.antlr.v4.tool

Examples of org.antlr.v4.tool.LexerGrammar


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

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


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

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

  /** only positive sets like (EOF|'\n') can match EOF and not in wildcard or ~foo sets
   *  EOF matches but does not advance cursor.
   */
  @Test public void testEOFInSetAtEndOfLineComment() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "CMT : '//' .* (EOF|'\\n') ;\n");
    String expecting = "CMT, EOF";
    checkLexerMatches(lg, "//", expecting);
  }
View Full Code Here

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

  @Test public void testEOFSuffixInSecondRule() throws Exception {
    LexerGrammar lg = new LexerGrammar(
      "lexer grammar L;\n"+
      "A : 'a' ;\n"+ // shorter than 'a' EOF, despite EOF being 0 width
      "B : 'a' EOF ;\n");
    String expecting = "B, EOF";
    checkLexerMatches(lg, "a", expecting);
View Full Code Here

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

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

    String expecting = "A, EOF";
    checkLexerMatches(lg, "a", expecting);
  }

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

  List<ANTLRMessage> checkLexerDFA(String gtext, String modeName, String expecting)
    throws Exception
  {
    ErrorQueue equeue = new ErrorQueue();
    LexerGrammar g = new LexerGrammar(gtext, equeue);
    g.atn = createATN(g, false);
//    LexerATNToDFAConverter conv = new LexerATNToDFAConverter(g);
//    DFA dfa = conv.createDFA(modeName);
//    g.setLookaheadDFA(0, dfa); // only one decision to worry about
//
View Full Code Here

    g.loadImportedGrammars();

    GrammarTransformPipeline transform = new GrammarTransformPipeline(g, this);
    transform.process();

    LexerGrammar lexerg;
    GrammarRootAST lexerAST;
    if ( g.ast!=null && g.ast.grammarType== ANTLRParser.COMBINED &&
       !g.ast.hasErrors )
    {
      lexerAST = transform.extractImplicitLexer(g); // alters g.ast
      if ( lexerAST!=null ) {
        if (grammarOptions != null) {
          lexerAST.cmdLineOptions = grammarOptions;
        }

        lexerg = new LexerGrammar(this, lexerAST);
        lexerg.fileName = g.fileName;
        lexerg.originalGrammar = g;
        g.implicitLexer = lexerg;
        lexerg.implicitLexerOwner = g;
        processNonCombinedGrammar(lexerg, gencode);
View Full Code Here

    use it for error handling and generally knowing from where a rule
    comes from.
   */
  public Grammar createGrammar(GrammarRootAST ast) {
    final Grammar g;
    if ( ast.grammarType==ANTLRParser.LEXER ) g = new LexerGrammar(this, ast);
    else g = new Grammar(this, ast);

    // ensure each node has pointer to surrounding grammar
    GrammarTransformPipeline.setGrammarPtr(g, ast);
    return g;
View Full Code Here

      if (g.getTokenType(channelName) != Token.INVALID_TYPE) {
        g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_TOKEN, g.fileName, channel.token, channelName);
      }

      if (outermost instanceof LexerGrammar) {
        LexerGrammar lexerGrammar = (LexerGrammar)outermost;
        if (lexerGrammar.modes.containsKey(channelName)) {
          g.tool.errMgr.grammarError(ErrorType.CHANNEL_CONFLICTS_WITH_MODE, g.fileName, channel.token, channelName);
        }
      }
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.