Search in sources :

Example 41 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by tunnelvisionlabs.

the class TestATNLexerInterpreter method testLexerWildcardExplicitNonGreedyPlusLoop.

@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);
}
Also used : LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 42 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by tunnelvisionlabs.

the class TestATNLexerInterpreter method testLexerTwoRules.

@Test
public void testLexerTwoRules() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'a' ;\n" + "B : 'b' ;\n");
    String expecting = "A, B, A, B, EOF";
    checkLexerMatches(lg, "abab", expecting);
}
Also used : LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 43 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by tunnelvisionlabs.

the class TestATNLexerInterpreter method testShortLongRule.

@Test
public void testShortLongRule() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "A : 'xy'\n" + // this alt is preferred since there are no non-greedy configs
    "  | 'xyz'\n" + "  ;\n" + "Z : 'z'\n" + "  ;\n");
    checkLexerMatches(lg, "xy", "A, EOF");
    checkLexerMatches(lg, "xyz", "A, EOF");
}
Also used : LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 44 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by tunnelvisionlabs.

the class TestATNLexerInterpreter method testWildOnEndFirstAlt.

@Test
public void testWildOnEndFirstAlt() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + // should pursue '.' since xyz hits stop first, before 2nd alt
    "A : 'xy' .\n" + "  | 'xy'\n" + "  ;\n" + "Z : 'z'\n" + "  ;\n");
    checkLexerMatches(lg, "xy", "A, EOF");
    checkLexerMatches(lg, "xyz", "A, EOF");
}
Also used : LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Example 45 with EOF

use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by tunnelvisionlabs.

the class TestATNLexerInterpreter method testShortLongRule2.

@Test
public void testShortLongRule2() throws Exception {
    LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + // make sure nongreedy mech cut off doesn't kill this alt
    "A : 'xyz'\n" + "  | 'xy'\n" + "  ;\n");
    checkLexerMatches(lg, "xy", "A, EOF");
    checkLexerMatches(lg, "xyz", "A, EOF");
}
Also used : LexerGrammar(org.antlr.v4.tool.LexerGrammar) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)218 LexerGrammar (org.antlr.v4.tool.LexerGrammar)182 Grammar (org.antlr.v4.tool.Grammar)110 CommonToken (org.antlr.v4.runtime.CommonToken)35 JavadocContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocContext)31 TextContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.TextContext)29 Token (org.antlr.v4.runtime.Token)19 ArrayList (java.util.ArrayList)18 ATN (org.antlr.v4.runtime.atn.ATN)18 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)18 DescriptionContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.DescriptionContext)15 ParseTree (org.antlr.v4.runtime.tree.ParseTree)13 HtmlElementContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.HtmlElementContext)12 JavadocTagContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocTagContext)12 JavadocInlineTagContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocInlineTagContext)10 ReferenceContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.ReferenceContext)10 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)10 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)10 HtmlElementCloseContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.HtmlElementCloseContext)9 HtmlElementOpenContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.HtmlElementOpenContext)9