use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.
the class TestCompositeGrammars method testBigTreeOfImports.
@Test
public void testBigTreeOfImports() throws Exception {
ErrorQueue equeue = new ErrorQueue();
String slave = "parser grammar T;\n" + "tokens{T}\n" + "x : T ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "T.g4", slave);
slave = "parser grammar S;\n" + "import T;\n" + "tokens{S}\n" + "y : S ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "S.g4", slave);
slave = "parser grammar C;\n" + "tokens{C}\n" + "i : C ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "C.g4", slave);
slave = "parser grammar B;\n" + "tokens{B}\n" + "j : B ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "B.g4", slave);
slave = "parser grammar A;\n" + "import B,C;\n" + "tokens{A}\n" + "k : A ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "A.g4", slave);
String master = "grammar M;\n" + "import S,A;\n" + "tokens{M}\n" + "a : M ;\n";
writeFile(getTempDirPath(), "M.g4", master);
Grammar g = new Grammar(getTempDirPath() + "/M.g4", master, equeue);
assertEquals("[]", equeue.errors.toString());
assertEquals("[]", equeue.warnings.toString());
String expectedTokenIDToTypeMap = "{EOF=-1, M=1, S=2, T=3, A=4, B=5, C=6}";
String expectedStringLiteralToTypeMap = "{}";
String expectedTypeToTokenList = "[M, S, T, A, B, C]";
assertEquals(expectedTokenIDToTypeMap, g.tokenNameToTypeMap.toString());
assertEquals(expectedStringLiteralToTypeMap, g.stringLiteralToTypeMap.toString());
assertEquals(expectedTypeToTokenList, realElements(g.typeToTokenList).toString());
boolean ok = rawGenerateAndBuildRecognizer("M.g4", master, "MParser", null);
// should be ok
boolean expecting = true;
assertEquals(expecting, ok);
}
use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.
the class TestLookaheadTrees method testAlts2.
@Test
public void testAlts2() throws Exception {
LexerGrammar lg = new LexerGrammar(lexerText);
Grammar g = new Grammar("parser grammar T;\n" + "s : e? SEMI EOF ;\n" + "e : ID\n" + " | e BANG" + " ;\n", lg);
String startRuleName = "s";
// (...)* in e.
int decision = 1;
testLookaheadTrees(lg, g, "a;", startRuleName, decision, new String[] { // Decision for alt 1 is error as no ! char, but alt 2 (exit) is good.
"(e:2 (e:1 a) <error ;>)", // root s:1 is included to show ';' node
"(s:1 (e:1 a) ; <EOF>)" });
}
use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.
the class TestLookaheadTrees method testIncludeEOF.
@Test
public void testIncludeEOF() throws Exception {
LexerGrammar lg = new LexerGrammar(lexerText);
Grammar g = new Grammar("parser grammar T;\n" + "s : e ;\n" + "e : ID DOT ID EOF\n" + " | ID DOT ID EOF\n" + " ;\n", lg);
int decision = 0;
testLookaheadTrees(lg, g, "a.b", "s", decision, new String[] { "(e:1 a . b <EOF>)", "(e:2 a . b <EOF>)" });
}
use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.
the class TestLookaheadTrees method testAlts.
@Test
public void testAlts() throws Exception {
LexerGrammar lg = new LexerGrammar(lexerText);
Grammar g = new Grammar("parser grammar T;\n" + "s : e SEMI EOF ;\n" + "e : ID DOT ID\n" + " | ID LPAREN RPAREN\n" + " ;\n", lg);
String startRuleName = "s";
int decision = 0;
testLookaheadTrees(lg, g, "a.b;", startRuleName, decision, new String[] { "(e:1 a . b)", "(e:2 a <error .>)" });
}
use of org.antlr.v4.runtime.Recognizer.EOF in project antlr4 by antlr.
the class TestATNLexerInterpreter method testLexerNotSMPSetMatchesBMP.
@Test
public void testLexerNotSMPSetMatchesBMP() throws Exception {
LexerGrammar lg = new LexerGrammar("lexer grammar L;\n" + "ID : ~('\\u{1F4A9}'|'\\u{1F4AA}')\n ;");
String expecting = "ID, EOF";
checkLexerMatches(lg, "\u611B", expecting);
}
Aggregations