use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.
the class TestCompositeGrammars method testRulesVisibleThroughMultilevelImport.
@Test
public void testRulesVisibleThroughMultilevelImport() throws Exception {
ErrorQueue equeue = new ErrorQueue();
String slave = "parser grammar T;\n" + "x : T ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "T.g4", slave);
String slave2 = // A, B, C token type order
"parser grammar S;\n" + "import T;\n" + "a : S ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "S.g4", slave2);
String master = "grammar M;\n" + "import S;\n" + // x MUST BE VISIBLE TO M
"a : M x ;\n";
writeFile(getTempDirPath(), "M.g4", master);
Grammar g = new Grammar(getTempDirPath() + "/M.g4", master, equeue);
String expectedTokenIDToTypeMap = "{EOF=-1, M=1, T=2}";
String expectedStringLiteralToTypeMap = "{}";
String expectedTypeToTokenList = "[M, T]";
assertEquals(expectedTokenIDToTypeMap, g.tokenNameToTypeMap.toString());
assertEquals(expectedStringLiteralToTypeMap, g.stringLiteralToTypeMap.toString());
assertEquals(expectedTypeToTokenList, realElements(g.typeToTokenList).toString());
assertEquals("unexpected errors: " + equeue, 0, equeue.errors.size());
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.
the class TestCompositeGrammars method testMergeModesIntoLexerGrammar.
@Test
public void testMergeModesIntoLexerGrammar() throws Exception {
RuntimeTestUtils.mkdir(getTempDirPath());
String master = "lexer grammar M;\n" + "import S;\n" + "A : 'a' -> pushMode(X);\n" + "mode X;\n" + "B : 'b';\n";
writeFile(getTempDirPath(), "M.g4", master);
String slave = "lexer grammar S;\n" + "D : 'd';\n" + "mode X;\n" + "C : 'c' -> popMode;\n";
writeFile(getTempDirPath(), "S.g4", slave);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(getTempDirPath(), "Java", "M.g4", false, "-lib", getTempDirPath());
assertEquals(0, equeue.errors.size());
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.
the class TestCompositeGrammars method test3LevelImport.
// Make sure that M can import S that imports T.
@Test
public void test3LevelImport() throws Exception {
ErrorQueue equeue = new ErrorQueue();
String slave = "parser grammar T;\n" + "a : T ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "T.g4", slave);
String slave2 = "parser grammar S;\n" + "import T;\n" + "a : S ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "S.g4", slave2);
String master = "grammar M;\n" + "import S;\n" + "a : M ;\n";
writeFile(getTempDirPath(), "M.g4", master);
Grammar g = new Grammar(getTempDirPath() + "/M.g4", master, equeue);
// S and T aren't imported; overridden
String expectedTokenIDToTypeMap = "{EOF=-1, M=1}";
String expectedStringLiteralToTypeMap = "{}";
String expectedTypeToTokenList = "[M]";
assertEquals(expectedTokenIDToTypeMap, g.tokenNameToTypeMap.toString());
assertEquals(expectedStringLiteralToTypeMap, g.stringLiteralToTypeMap.toString());
assertEquals(expectedTypeToTokenList, realElements(g.typeToTokenList).toString());
assertEquals("unexpected errors: " + equeue, 0, equeue.errors.size());
boolean ok = rawGenerateAndBuildRecognizer("M.g4", master, "MParser", null);
// should be ok
boolean expecting = true;
assertEquals(expecting, ok);
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.
the class TestCompositeGrammars method testImportIntoLexerGrammar.
@Test
public void testImportIntoLexerGrammar() throws Exception {
RuntimeTestUtils.mkdir(getTempDirPath());
String master = "lexer grammar M;\n" + "import S;\n" + "A : 'a';\n" + "B : 'b';\n";
writeFile(getTempDirPath(), "M.g4", master);
String slave = "lexer grammar S;\n" + "C : 'c';\n";
writeFile(getTempDirPath(), "S.g4", slave);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(getTempDirPath(), "Java", "M.g4", false, "-lib", getTempDirPath());
assertEquals(0, equeue.errors.size());
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.
the class TestCompositeGrammars method testEmptyModesInLexerGrammar.
@Test
public void testEmptyModesInLexerGrammar() throws Exception {
RuntimeTestUtils.mkdir(getTempDirPath());
String master = "lexer grammar M;\n" + "import S;\n" + "A : 'a';\n" + "C : 'e';\n" + "B : 'b';\n";
writeFile(getTempDirPath(), "M.g4", master);
String slave = "lexer grammar S;\n" + "D : 'd';\n" + "mode X;\n" + "C : 'c' -> popMode;\n";
writeFile(getTempDirPath(), "S.g4", slave);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(getTempDirPath(), "Java", "M.g4", false, "-lib", getTempDirPath());
assertEquals(0, equeue.errors.size());
}
Aggregations