Unit tests for ('a' | 'ab') in lexers
This commit is contained in:
parent
37425b70d0
commit
94d3de748e
|
@ -68,12 +68,12 @@ public class TestATNLexerInterpreter extends BaseTest {
|
|||
LexerGrammar lg = new LexerGrammar(
|
||||
"lexer grammar L;\n"+
|
||||
"A : 'xy'\n" +
|
||||
" | 'xyz'\n" + // this alt shouldn't be reachable since the alts are ordered
|
||||
" | 'xyz'\n" + // this alt is preferred since there are no non-greedy configs
|
||||
" ;\n" +
|
||||
"Z : 'z'\n" +
|
||||
" ;\n");
|
||||
checkLexerMatches(lg, "xy", "A, EOF");
|
||||
checkLexerMatches(lg, "xyz", "A, Z, EOF");
|
||||
checkLexerMatches(lg, "xyz", "A, EOF");
|
||||
}
|
||||
|
||||
@Test public void testShortLongRule2() throws Exception {
|
||||
|
@ -102,12 +102,12 @@ public class TestATNLexerInterpreter extends BaseTest {
|
|||
LexerGrammar lg = new LexerGrammar(
|
||||
"lexer grammar L;\n"+
|
||||
"A : 'xy'\n" +
|
||||
" | 'xy' .\n" + // should not pursue '.' since alts are ordered
|
||||
" | 'xy' .\n" + // this alt is preferred since there are no non-greedy configs
|
||||
" ;\n" +
|
||||
"Z : 'z'\n" +
|
||||
" ;\n");
|
||||
checkLexerMatches(lg, "xy", "A, EOF");
|
||||
checkLexerMatches(lg, "xyz", "A, Z, EOF");
|
||||
checkLexerMatches(lg, "xyz", "A, EOF");
|
||||
}
|
||||
|
||||
@Test public void testWildcardNonQuirkWhenSplitBetweenTwoRules() throws Exception {
|
||||
|
|
|
@ -236,6 +236,36 @@ public class TestLexerExec extends BaseTest {
|
|||
"line 3:16 token recognition error at: 'x'\n", stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test public void testGreedyConfigs() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
"I : ('a' | 'ab') {System.out.println(getText());} ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;\n" +
|
||||
"J : .;\n";
|
||||
String found = execLexer("L.g4", grammar, "L", "ab");
|
||||
String expecting =
|
||||
"ab\n" +
|
||||
"[@0,0:1='ab',<1>,1:0]\n" +
|
||||
"[@1,2:1='<EOF>',<-1>,1:2]\n";
|
||||
assertEquals(expecting, found);
|
||||
}
|
||||
|
||||
@Test public void testNonGreedyConfigs() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
"I : .*? ('a' | 'ab') {System.out.println(getText());} ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;\n" +
|
||||
"J : . {System.out.println(getText());};\n";
|
||||
String found = execLexer("L.g4", grammar, "L", "ab");
|
||||
String expecting =
|
||||
"a\n" +
|
||||
"b\n" +
|
||||
"[@0,0:0='a',<1>,1:0]\n" +
|
||||
"[@1,1:1='b',<3>,1:1]\n" +
|
||||
"[@2,2:1='<EOF>',<-1>,1:2]\n";
|
||||
assertEquals(expecting, found);
|
||||
}
|
||||
|
||||
@Test public void testActionExecutedInDFA() throws Exception {
|
||||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
|
|
Loading…
Reference in New Issue