use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestExternalGrammars method testTSql.
@Test
public void testTSql() {
if (!toCheck("tsql"))
return;
Subject s = subjects.get("tsql");
Set<File> mfiles = s.g4.stream().filter(v -> v.getName().matches("TSql(Lexer|Parser).g4")).collect(Collectors.toSet());
assertFalse(mfiles.isEmpty());
GenericParser mparser = null;
try {
mparser = new GenericParser(mfiles.toArray(new File[0]));
} catch (FileNotFoundException e) {
fail();
}
assertNotNull(mparser);
DefaultTreeListener mdt = new DefaultTreeListener();
assertDoesNotThrow(mparser::compile);
mparser.setStreamProvider(new CasedStreamProvider(CaseSensitiveType.UPPER));
mparser.setListener(mdt);
// seems to cause issues when running on windows
s.examples.removeIf(f -> f.getName().equals("full_width_chars.sql"));
verify(mparser, s.examples, s.nexamples, s.entrypoint);
}
use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestExternalGrammars method testObjc.
@Test
public void testObjc() {
if (!toCheck("objc"))
return;
Subject s = subjects.get("objc");
s.g4.add(new File("src/test/resources/grammars-v4/objc/one-step" + "-processing/ObjectiveCLexer.g4"));
s.g4.add(new File("src/test/resources/grammars-v4/objc/one-step" + "-processing/ObjectiveCPreprocessorParser.g4"));
GenericParser gp = null;
try {
gp = new GenericParser(s.g4.toArray(new File[0]));
} catch (FileNotFoundException e) {
fail();
}
DefaultTreeListener mdt = new DefaultTreeListener();
assertDoesNotThrow(gp::compile);
gp.setListener(mdt);
s.examples.removeIf(p -> p.getName().contains("AllInOne.m"));
verify(gp, s.examples, s.nexamples, s.entrypoint);
}
use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestMalformed method testGeneration.
@Test
public void testGeneration() {
GenericParser gp = assertDoesNotThrow(() -> new GenericParser(grammar));
Assertions.assertNotNull(gp);
boolean compile;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
Assertions.assertTrue(compile);
String s = FileUtils.loadFileContent(sfile.getAbsolutePath());
Assertions.assertTrue(s != null && !s.isEmpty());
DefaultTreeListener dlist = new DefaultTreeListener();
gp.setListener(dlist);
assertThrows(ParsingException.class, () -> gp.parse(s));
}
use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestGenericParser method testParser.
@Test
public void testParser() {
GenericParser gp = null;
try {
gp = new GenericParser(grammar);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Assertions.assertNotNull(gp);
// Incorrect workflows
boolean thrown = false;
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
Assertions.assertTrue(thrown);
boolean compile;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
Assertions.assertTrue(compile);
// Incorrect workflows
thrown = false;
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
if (e instanceof RedundantCompilationException)
compile = true;
else
compile = false;
}
Assertions.assertTrue(compile);
thrown = false;
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
Assertions.assertFalse(thrown);
thrown = false;
Assertions.assertNotSame(null, gp.getListener());
// Correct workflow
gp.setListener(new DefaultListener());
Assertions.assertNotNull(gp.getListener());
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
if (e instanceof RedundantCompilationException)
compile = true;
else
compile = false;
}
Assertions.assertTrue(compile);
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
Assertions.assertFalse(thrown);
}
use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestGenericParser method testCompilationError.
@Test
public void testCompilationError() {
GenericParser gp = null;
try {
gp = new GenericParser(fgrammar);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Assertions.assertNotNull(gp);
// Incorrect workflows
boolean thrown = false;
try {
gp.parse(sfile);
} catch (IllegalWorkflowException | FileNotFoundException | ParsingException e) {
thrown = true;
}
Assertions.assertTrue(thrown);
boolean compile = true;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
if (e instanceof CompilationErrorException) {
compile = false;
}
}
Assertions.assertFalse(compile);
}
Aggregations