Search in sources :

Example 1 with MemoryTuple

use of org.snt.inmemantlr.memobjects.MemoryTuple in project inmemantlr by julianthome.

the class TestMemObjects method testAntlrObjectAccess.

@Test
public void testAntlrObjectAccess() {
    GenericParser gp = null;
    try {
        gp = new GenericParser(grammar);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    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());
    MemoryTupleSet set = gp.getAllCompiledObjects();
    Assertions.assertTrue(set != null && set.size() == 4);
    for (MemoryTuple tup : set) {
        LOGGER.debug("tuple name {}", tup.getClassName());
        // for printing the source code
        LOGGER.debug("source {}", tup.getSource().getClassName());
        // for printing the byte code
        for (MemoryByteCode mc : tup.getByteCodeObjects()) {
            Objects.requireNonNull(mc, "MemoryByteCode must not be null");
            LOGGER.debug("bc name: {}", mc.getClassName());
            if (!mc.isInnerClass()) {
                mc.getClassName().equals(tup.getSource().getClassName());
            } else {
                mc.getClassName().startsWith(tup.getSource().getClassName());
            }
        }
    }
}
Also used : MemoryByteCode(org.snt.inmemantlr.memobjects.MemoryByteCode) MemoryTupleSet(org.snt.inmemantlr.memobjects.MemoryTupleSet) MemoryTuple(org.snt.inmemantlr.memobjects.MemoryTuple) FileNotFoundException(java.io.FileNotFoundException) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 Test (org.junit.jupiter.api.Test)1 GenericParser (org.snt.inmemantlr.GenericParser)1 MemoryByteCode (org.snt.inmemantlr.memobjects.MemoryByteCode)1 MemoryTuple (org.snt.inmemantlr.memobjects.MemoryTuple)1 MemoryTupleSet (org.snt.inmemantlr.memobjects.MemoryTupleSet)1