Move lexer predicates test to TestSemPredEvalLexer

This commit is contained in:
Sam Harwell 2012-10-31 21:50:44 -05:00
parent 05363cd5ef
commit 3278997a89
2 changed files with 22 additions and 22 deletions

View File

@ -266,28 +266,6 @@ public class TestLexerExec extends BaseTest {
assertEquals(expecting, found);
}
@Test public void testLexerInputPositionSensitivePredicates() throws Exception {
String grammar =
"lexer grammar L;\n"+
"WORD1 : ID1+ {System.out.println(getText());} ;\n"+
"WORD2 : ID2+ {System.out.println(getText());} ;\n"+
"fragment ID1 : {getCharPositionInLine()<2}? [a-zA-Z];\n"+
"fragment ID2 : {getCharPositionInLine()>=2}? [a-zA-Z];\n"+
"WS : (' '|'\\n') -> skip;\n";
String found = execLexer("L.g4", grammar, "L", "a cde\nabcde\n");
String expecting =
"a\n" +
"cde\n" +
"ab\n" +
"cde\n" +
"[@0,0:0='a',<1>,1:0]\n" +
"[@1,2:4='cde',<2>,1:2]\n" +
"[@2,6:7='ab',<1>,2:0]\n" +
"[@3,8:10='cde',<2>,2:2]\n" +
"[@4,12:11='<EOF>',<-1>,3:0]\n";
assertEquals(expecting, found);
}
@Test public void testActionExecutedInDFA() throws Exception {
String grammar =
"lexer grammar L;\n"+

View File

@ -108,4 +108,26 @@ public class TestSemPredEvalLexer extends BaseTest {
":s1=>1-'f'->:s1=>1\n";
assertEquals(expecting, found);
}
@Test public void testLexerInputPositionSensitivePredicates() throws Exception {
String grammar =
"lexer grammar L;\n"+
"WORD1 : ID1+ {System.out.println(getText());} ;\n"+
"WORD2 : ID2+ {System.out.println(getText());} ;\n"+
"fragment ID1 : {getCharPositionInLine()<2}? [a-zA-Z];\n"+
"fragment ID2 : {getCharPositionInLine()>=2}? [a-zA-Z];\n"+
"WS : (' '|'\\n') -> skip;\n";
String found = execLexer("L.g4", grammar, "L", "a cde\nabcde\n");
String expecting =
"a\n" +
"cde\n" +
"ab\n" +
"cde\n" +
"[@0,0:0='a',<1>,1:0]\n" +
"[@1,2:4='cde',<2>,1:2]\n" +
"[@2,6:7='ab',<1>,2:0]\n" +
"[@3,8:10='cde',<2>,2:2]\n" +
"[@4,12:11='<EOF>',<-1>,3:0]\n";
assertEquals(expecting, found);
}
}