use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestDoubleParse method testProcessor.
@Test
public void testProcessor() {
GenericParser gp1 = new GenericParser(sgrammarcontent);
boolean compile;
try {
gp1.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
assertTrue(compile);
GenericParser gp2 = new GenericParser(sgrammarcontent);
try {
gp2.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
assertTrue(compile);
DefaultTreeListener l1 = new DefaultTreeListener();
DefaultTreeListener l2 = new DefaultTreeListener();
assertNotNull(l1.toString());
assertEquals("", l1.toString());
gp1.setListener(l1);
gp2.setListener(l2);
try {
gp1.parse(s1);
gp2.parse(s2);
} catch (IllegalWorkflowException | ParsingException e) {
e.printStackTrace();
}
ParseTree out1 = l1.getParseTree();
ParseTree out2 = l2.getParseTree();
assertNotEquals(out1, out2);
}
use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestGenericParser method testWrongParams1Exception.
@Test
public void testWrongParams1Exception() {
boolean thrown = false;
GenericParser genericParser0 = null;
try {
genericParser0 = new GenericParser((File) null);
fail("Expecting exception: NullPointerException");
} catch (NullPointerException | FileNotFoundException e) {
thrown = true;
}
Assertions.assertTrue(thrown);
}
use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestGenericParser method testWrongParams2Exception.
@Test
public void testWrongParams2Exception() {
boolean thrown = false;
GenericParser genericParser0 = null;
try {
genericParser0 = new GenericParser("xyz");
fail("Expecting exception: Error");
} catch (NullPointerException | Error e) {
thrown = true;
}
Assertions.assertTrue(thrown);
}
use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestGrammarImport method testOncrpc.
@Test
public void testOncrpc() {
File[] fls = { new File("src/test/resources/inmemantlr/xdr.g4"), new File("src/test/resources/inmemantlr/oncrpcv2.g4") };
GenericParser gp = assertDoesNotThrow(() -> new GenericParser(fls));
assertDoesNotThrow(gp::compile);
assertDoesNotThrow(() -> {
gp.parse(new File("src/test/resources/inmemantlr/CalculatorService.x"), "oncrpcv2Specification", CaseSensitiveType.NONE);
});
}
use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.
the class TestLexerGrammar method testInterpreter.
@Test
public void testInterpreter() throws IOException {
try (InputStream sgrammar = getClass().getClassLoader().getResourceAsStream("inmemantlr/LexerGrammar.g4")) {
sgrammarcontent = FileUtils.getStringFromStream(sgrammar);
}
GenericParser gp = new GenericParser(sgrammarcontent);
boolean compile;
try {
gp.compile();
compile = true;
} catch (CompilationException e) {
compile = false;
}
assertTrue(compile);
List<Token> tokens = assertDoesNotThrow(() -> gp.lex("a09"));
assertEquals(2, tokens.size());
}
Aggregations