use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.
the class TestCompositeGrammars method testImportFileLocationInSubdir.
@Test
public void testImportFileLocationInSubdir() throws Exception {
String slave = "parser grammar S;\n" + "a : B {System.out.println(\"S.a\");} ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
String subdir = getTempDirPath() + PATH_SEP + "sub";
RuntimeTestUtils.mkdir(subdir);
writeFile(subdir, "S.g4", slave);
String master = "grammar M;\n" + "import S;\n" + "s : a ;\n" + // defines B from inherited token space
"B : 'b' ;" + "WS : (' '|'\\n') -> skip ;\n";
writeFile(getTempDirPath(), "M.g4", master);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(getTempDirPath(), "Java", "M.g4", false, "-lib", subdir);
assertEquals(0, equeue.size());
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.
the class TestCompositeGrammars method testImportChannelsIntoLexerGrammar.
@Test
public void testImportChannelsIntoLexerGrammar() throws Exception {
RuntimeTestUtils.mkdir(getTempDirPath());
String master = "lexer grammar M;\n" + "import S;\n" + "channels {CH_A, CH_B}\n" + "A : 'a' -> channel(CH_A);\n" + "B : 'b' -> channel(CH_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 testTokensFileInOutputDirAndImportFileInSubdir.
@Test
public void testTokensFileInOutputDirAndImportFileInSubdir() throws Exception {
String slave = "parser grammar S;\n" + "a : B {System.out.println(\"S.a\");} ;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
String subdir = getTempDirPath() + "/sub";
RuntimeTestUtils.mkdir(subdir);
writeFile(subdir, "S.g4", slave);
String parser = "parser grammar MParser;\n" + "import S;\n" + "options {tokenVocab=MLexer;}\n" + "s : a ;\n";
writeFile(getTempDirPath(), "MParser.g4", parser);
String lexer = "lexer grammar MLexer;\n" + // defines B from inherited token space
"B : 'b' ;" + "WS : (' '|'\\n') -> skip ;\n";
writeFile(getTempDirPath(), "MLexer.g4", lexer);
String outdir = getTempDirPath() + "/out";
RuntimeTestUtils.mkdir(outdir);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(getTempDirPath(), "Java", "MLexer.g4", false, "-o", outdir);
assertEquals(0, equeue.size());
equeue = BaseRuntimeTest.antlrOnString(getTempDirPath(), "Java", "MParser.g4", false, "-o", outdir, "-lib", subdir);
assertEquals(0, equeue.size());
}
use of org.antlr.v4.test.runtime.ErrorQueue in project antlr4 by antlr.
the class TestCompositeGrammars method testNestedComposite.
@Test
public void testNestedComposite() throws Exception {
// Wasn't compiling. http://www.antlr.org/jira/browse/ANTLR-438
ErrorQueue equeue = new ErrorQueue();
String gstr = "lexer grammar L;\n" + "T1: '1';\n" + "T2: '2';\n" + "T3: '3';\n" + "T4: '4';\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "L.g4", gstr);
gstr = "parser grammar G1;\n" + "s: a | b;\n" + "a: T1;\n" + "b: T2;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "G1.g4", gstr);
gstr = "parser grammar G2;\n" + "import G1;\n" + "a: T3;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "G2.g4", gstr);
String G3str = "grammar G3;\n" + "import G2;\n" + "b: T4;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "G3.g4", G3str);
Grammar g = new Grammar(getTempDirPath() + "/G3.g4", G3str, equeue);
String expectedTokenIDToTypeMap = "{EOF=-1, T4=1, T3=2}";
String expectedStringLiteralToTypeMap = "{}";
String expectedTypeToTokenList = "[T4, T3]";
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("G3.g4", G3str, "G3Parser", 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 testErrorInImportedGetsRightFilename.
@Test
public void testErrorInImportedGetsRightFilename() throws Exception {
String slave = "parser grammar S;\n" + "a : 'a' | c;\n";
RuntimeTestUtils.mkdir(getTempDirPath());
writeFile(getTempDirPath(), "S.g4", slave);
String master = "grammar M;\n" + "import S;\n";
writeFile(getTempDirPath(), "M.g4", master);
ErrorQueue equeue = BaseRuntimeTest.antlrOnString(getTempDirPath(), "Java", "M.g4", false, "-lib", getTempDirPath());
ANTLRMessage msg = equeue.errors.get(0);
assertEquals(ErrorType.UNDEFINED_RULE_REF, msg.getErrorType());
assertEquals("c", msg.getArgs()[0]);
assertEquals(2, msg.line);
assertEquals(10, msg.charPosition);
assertEquals("S.g4", new File(msg.fileName).getName());
}
Aggregations