use of org.snt.inmemantlr.tool.ToolCustomizer in project inmemantlr by julianthome.
the class TestArtifactSerialization method testBroken.
@Test
public void testBroken() throws IOException {
try (InputStream sgrammar = getClass().getClassLoader().getResourceAsStream("inmemantlr/Simple.g4")) {
sgrammarcontent = FileUtils.getStringFromStream(sgrammar);
}
ToolCustomizer tc = new ToolCustomizer() {
@Override
public void customize(Tool t) {
t.genPackage = "com.github.inmemantlr.parser";
}
};
GenericParser gp = new GenericParser(tc, sgrammarcontent);
DefaultTreeListener t = new DefaultTreeListener();
gp.setListener(t);
boolean compile;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
gp.writeAntlrAritfactsTo("/tmp/test/out");
}
use of org.snt.inmemantlr.tool.ToolCustomizer in project inmemantlr by julianthome.
the class TestExternalGrammars method testStringTemplate.
@Test
public void testStringTemplate() {
// skip for the time being -- grammar issue
if (true)
return;
if (!toCheck("stringtemplate"))
return;
Subject s = subjects.get("stringtemplate");
// LOGGER.info("G4 {}", s.g4);
// Exam
ToolCustomizer tc = t -> t.genPackage = "org.antlr.parser.st4";
GenericParser gp = getParserForSubject(s, tc);
DefaultTreeListener dt = new DefaultTreeListener();
gp.setListener(dt);
try {
File util = new File("src/test/resources/grammars-v4/stringtemplate/" + "src/main/java/org/antlr/parser/st4/LexerAdaptor.java");
gp.addUtilityJavaFiles(util);
} catch (FileNotFoundException e) {
Assertions.assertFalse(true);
}
boolean compile;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
LOGGER.debug("name {}", gp.getParserName());
gp.setParserName("org.antlr.parser.st4.STParser");
gp.setLexerName("org.antlr.parser.st4.STLexer");
Assertions.assertTrue(compile);
s.examples = s.examples.stream().filter(f -> f.getName().contains("example1.st")).collect(Collectors.toSet());
verify(gp, s.examples, s.nexamples, s.entrypoint);
}
use of org.snt.inmemantlr.tool.ToolCustomizer in project inmemantlr by julianthome.
the class TestExternalGrammars method testAntlr4.
@Test
public void testAntlr4() {
if (!toCheck("antlr4"))
return;
Subject s = subjects.get("antlr4");
// Exam
ToolCustomizer tc = t -> t.genPackage = "org.antlr.parser.antlr4";
Set<File> files = s.g4.stream().filter(v -> v.getName().matches("" + "(ANTLRv4" + "(Lexer|Parser)|LexBasic).g4")).collect(Collectors.toSet());
Assertions.assertTrue(files.size() > 0);
GenericParser gp = null;
try {
gp = new GenericParser(tc, files.toArray(new File[files.size()]));
} catch (FileNotFoundException e) {
Assertions.assertTrue(false);
}
DefaultTreeListener dt = new DefaultTreeListener();
gp.setListener(dt);
try {
File util = new File("src/test/resources/grammars-v4/antlr4/src/main/java" + "/org" + "/antlr/parser/antlr4/LexerAdaptor.java");
gp.addUtilityJavaFiles(util);
} catch (FileNotFoundException e) {
Assertions.assertFalse(true);
}
boolean compile;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
s.examples.removeIf(f -> f.getName().contains("three.g4"));
Assertions.assertTrue(compile);
verify(gp, s.examples, s.nexamples, s.entrypoint);
}
Aggregations