use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestAmbigParseTrees method testAmbigAltInLeftRecursiveBelowStartRule.
@Test
@Ignore("Cannot currently determine outer alternatives for left-factored non-precedence rules")
public void testAmbigAltInLeftRecursiveBelowStartRule() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "SELF : 'self' ;\n" + "ID : [a-z]+ ;\n" + "DOT : '.' ;\n");
Grammar g = new Grammar("parser grammar T;\n" + "s : e ;\n" + "e : p | e DOT ID ;\n" + "p : SELF" + " | SELF DOT ID" + " ;", lg);
String startRule = "s";
String input = "self.x";
String expectedAmbigAlts = "{1, 2}";
// decision in p
int decision = 1;
String expectedOverallTree = "(s:1 (e:2 (e:1 (p:1 self)) . x))";
String[] expectedParseTrees = { "(e:2 (e:1 (p:1 self)) . x)", "(p:2 self . x)" };
testAmbiguousTrees(lg, g, startRule, input, decision, expectedAmbigAlts, expectedOverallTree, expectedParseTrees);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNConstruction method testLexerIsntSetMultiCharString.
@Test
public void testLexerIsntSetMultiCharString() throws Exception {
LexerGrammar g = new LexerGrammar("lexer grammar P;\n" + "A : ('0x' | '0X') ;");
String expecting = "s0->RuleStart_A_1\n" + "RuleStart_A_1->BlockStart_7\n" + "BlockStart_7->s3\n" + "BlockStart_7->s5\n" + "s3-'0'->s4\n" + "s5-'0'->s6\n" + "s4-'x'->BlockEnd_8\n" + "s6-'X'->BlockEnd_8\n" + "BlockEnd_8->RuleStop_A_2\n";
checkTokensRule(g, null, expecting);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNConstruction method testCharSetUnicodePropertyEscape.
@Test
public void testCharSetUnicodePropertyEscape() throws Exception {
// The Gothic script is long dead and unlikely to change (which would
// cause this test to fail)
LexerGrammar g = new LexerGrammar("lexer grammar P;\n" + "A : [\\p{Gothic}] ;");
String expecting = "s0->RuleStart_A_1\n" + "RuleStart_A_1->s3\n" + "s3-{66352..66378}->s4\n" + "s4->RuleStop_A_2\n";
checkTokensRule(g, null, expecting);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNConstruction method testRangeOrRange.
@Test
public void testRangeOrRange() throws Exception {
LexerGrammar g = new LexerGrammar("lexer grammar P;\n" + "A : ('a'..'c' 'h' | 'q' 'j'..'l') ;");
String expecting = "s0->RuleStart_A_1\n" + "RuleStart_A_1->BlockStart_7\n" + "BlockStart_7->s3\n" + "BlockStart_7->s5\n" + "s3-'a'..'c'->s4\n" + "s5-'q'->s6\n" + "s4-'h'->BlockEnd_8\n" + "s6-'j'..'l'->BlockEnd_8\n" + "BlockEnd_8->RuleStop_A_2\n";
checkTokensRule(g, null, expecting);
}
use of org.antlr.v4.tool.LexerGrammar in project antlr4 by tunnelvisionlabs.
the class TestATNConstruction method checkTokensRule.
void checkTokensRule(LexerGrammar g, String modeName, String expecting) {
// }
if (modeName == null)
modeName = "DEFAULT_MODE";
if (g.modes.get(modeName) == null) {
System.err.println("no such mode " + modeName);
return;
}
ParserATNFactory f = new LexerATNFactory(g);
ATN nfa = f.createATN();
ATNState startState = nfa.modeNameToStartState.get(modeName);
ATNPrinter serializer = new ATNPrinter(g, startState);
String result = serializer.asString();
// System.out.print(result);
assertEquals(expecting, result);
}
Aggregations