Search in sources :

Example 21 with GenericParser

use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.

the class TestExternalGrammars method testEcma.

@Test
public void testEcma() {
    if (!toCheck("ecmascript"))
        return;
    Subject s = subjects.get("ecmascript");
    GenericParser gp = null;
    try {
        gp = new GenericParser(s.g4.toArray(new File[0]));
    } catch (FileNotFoundException e) {
        fail();
    }
    assertDoesNotThrow(gp::compile);
    verify(gp, s.examples, s.nexamples, s.entrypoint);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Example 22 with GenericParser

use of org.snt.inmemantlr.GenericParser 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());
    assertTrue(!files.isEmpty());
    GenericParser gp = assertDoesNotThrow(() -> new GenericParser(tc, files.toArray(new File[0])));
    DefaultTreeListener dt = new DefaultTreeListener();
    gp.setListener(dt);
    assertDoesNotThrow(() -> gp.addUtilityJavaFiles(new File("src/test/resources/grammars-v4/antlr4/src/main/java/org/antlr/parser/antlr4/LexerAdaptor.java")));
    assertDoesNotThrow(gp::compile);
    s.examples.removeIf(f -> f.getName().contains("three.g4"));
    verify(gp, s.examples, s.nexamples, s.entrypoint);
}
Also used : java.util(java.util) CaseSensitiveType(org.snt.inmemantlr.GenericParser.CaseSensitiveType) FileUtils(org.snt.inmemantlr.utils.FileUtils) LoggerFactory(org.slf4j.LoggerFactory) ParsingException(org.snt.inmemantlr.exceptions.ParsingException) IllegalWorkflowException(org.snt.inmemantlr.exceptions.IllegalWorkflowException) Document(org.w3c.dom.Document) ToolCustomizer(org.snt.inmemantlr.tool.ToolCustomizer) ParseTree(org.snt.inmemantlr.tree.ParseTree) CasedStreamProvider(org.snt.inmemantlr.stream.CasedStreamProvider) GenericParser(org.snt.inmemantlr.GenericParser) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.jupiter.api.Test) RecognitionException(org.antlr.v4.runtime.RecognitionException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) Assertions(org.junit.jupiter.api.Assertions) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) DefaultTreeListener(org.snt.inmemantlr.listener.DefaultTreeListener) FilenameUtils(org.apache.commons.io.FilenameUtils) ToolCustomizer(org.snt.inmemantlr.tool.ToolCustomizer) File(java.io.File) DefaultTreeListener(org.snt.inmemantlr.listener.DefaultTreeListener) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Example 23 with GenericParser

use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.

the class TestExternalGrammars method testR.

@Test
public void testR() {
    if (!toCheck("r"))
        return;
    Subject s = subjects.get("r");
    GenericParser gp = getParserForSubject(s, null);
    assertDoesNotThrow(gp::compile);
    gp.setParserName("RParser");
    verify(gp, s.examples, s.nexamples, s.entrypoint);
}
Also used : GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Example 24 with GenericParser

use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.

the class TestExternalGrammars method testSubject.

private void testSubject(Subject s, boolean skip) {
    LOGGER.debug("test {}", s.name);
    if (specialCases.contains(s.name) && skip) {
        LOGGER.debug("skip {}", s.name);
        return;
    }
    LOGGER.info("test {}", s.name);
    GenericParser gp = getParserForSubject(s, null);
    assertDoesNotThrow(gp::compile);
    LOGGER.debug("successfully compiled grammar");
    DefaultTreeListener dt = new DefaultTreeListener();
    gp.setListener(dt);
    verify(gp, s.examples, s.nexamples, s.entrypoint);
}
Also used : DefaultTreeListener(org.snt.inmemantlr.listener.DefaultTreeListener) GenericParser(org.snt.inmemantlr.GenericParser)

Example 25 with GenericParser

use of org.snt.inmemantlr.GenericParser in project inmemantlr by julianthome.

the class TestExternalGrammars method testSwift3.

@Test
public void testSwift3() {
    if (!toCheck("swift3"))
        return;
    Subject s = subjects.get("swift3");
    GenericParser gp = assertDoesNotThrow(() -> new GenericParser(s.g4.toArray(new File[0])));
    assertDoesNotThrow(() -> {
        File util = new File("src/test/resources/grammars-v4/swift3/src/main/java" + "/SwiftSupport.java");
        gp.addUtilityJavaFiles(util);
    });
    assertDoesNotThrow(gp::compile);
    verify(gp, s.examples, s.nexamples, s.entrypoint);
}
Also used : File(java.io.File) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Aggregations

GenericParser (org.snt.inmemantlr.GenericParser)40 Test (org.junit.jupiter.api.Test)37 DefaultTreeListener (org.snt.inmemantlr.listener.DefaultTreeListener)25 File (java.io.File)18 CompilationException (org.snt.inmemantlr.exceptions.CompilationException)18 ParseTree (org.snt.inmemantlr.tree.ParseTree)16 FileNotFoundException (java.io.FileNotFoundException)15 IllegalWorkflowException (org.snt.inmemantlr.exceptions.IllegalWorkflowException)14 ParsingException (org.snt.inmemantlr.exceptions.ParsingException)14 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 ToolCustomizer (org.snt.inmemantlr.tool.ToolCustomizer)8 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)7 Assertions (org.junit.jupiter.api.Assertions)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 CasedStreamProvider (org.snt.inmemantlr.stream.CasedStreamProvider)7 FileUtils (org.snt.inmemantlr.utils.FileUtils)7 java.util (java.util)6 Collectors (java.util.stream.Collectors)6