Search in sources :

Example 1 with CasedStreamProvider

use of org.snt.inmemantlr.stream.CasedStreamProvider 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());
    Assertions.assertTrue(mfiles.size() > 0);
    GenericParser mparser = null;
    try {
        mparser = new GenericParser(mfiles.toArray(new File[mfiles.size()]));
    } catch (FileNotFoundException e) {
        Assertions.assertTrue(false);
    }
    Assertions.assertNotNull(mparser);
    DefaultTreeListener mdt = new DefaultTreeListener();
    boolean compile;
    try {
        mparser.compile();
        compile = true;
    } catch (CompilationException e) {
        compile = false;
    }
    mparser.setStreamProvider(new CasedStreamProvider(GenericParser.CaseSensitiveType.UPPER));
    mparser.setListener(mdt);
    Assertions.assertTrue(compile);
    // 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);
}
Also used : java.util(java.util) FileUtils(org.snt.inmemantlr.utils.FileUtils) LoggerFactory(org.slf4j.LoggerFactory) ParsingException(org.snt.inmemantlr.exceptions.ParsingException) IllegalWorkflowException(org.snt.inmemantlr.exceptions.IllegalWorkflowException) CompilationException(org.snt.inmemantlr.exceptions.CompilationException) 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) CompilationException(org.snt.inmemantlr.exceptions.CompilationException) CasedStreamProvider(org.snt.inmemantlr.stream.CasedStreamProvider) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) DefaultTreeListener(org.snt.inmemantlr.listener.DefaultTreeListener) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Example 2 with CasedStreamProvider

use of org.snt.inmemantlr.stream.CasedStreamProvider in project inmemantlr by julianthome.

the class TestExternalGrammars method testPHP.

@Test
public void testPHP() {
    if (!toCheck("php"))
        return;
    Subject s = subjects.get("php");
    s.g4.removeIf(f -> f.getName().equals("PHPLexer_CSharpSharwell.g4") || f.getName().equals("PHPLexer_Python.g4"));
    GenericParser gp = null;
    try {
        gp = new GenericParser(s.g4.toArray(new File[s.g4.size()]));
    } catch (FileNotFoundException e) {
        Assertions.assertTrue(false);
    }
    boolean compile;
    try {
        gp.compile();
        compile = true;
    } catch (CompilationException e) {
        compile = false;
    }
    gp.setStreamProvider(new CasedStreamProvider(GenericParser.CaseSensitiveType.LOWER));
    Assertions.assertTrue(compile);
    s.examples = s.examples.stream().filter(f -> !f.getName().contains("alternativeSyntax.php")).collect(Collectors.toSet());
    verify(gp, s.examples, s.nexamples, s.entrypoint);
}
Also used : CompilationException(org.snt.inmemantlr.exceptions.CompilationException) CasedStreamProvider(org.snt.inmemantlr.stream.CasedStreamProvider) FileNotFoundException(java.io.FileNotFoundException) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Example 3 with CasedStreamProvider

use of org.snt.inmemantlr.stream.CasedStreamProvider in project inmemantlr by julianthome.

the class TestExternalGrammars method testPlsql.

@Test
public void testPlsql() {
    if (!toCheck("plsql"))
        return;
    Subject s = subjects.get("plsql");
    Set<File> mfiles = s.g4.stream().filter(v -> v.getName().matches("PlSql" + "(Lexer|Parser).g4")).collect(Collectors.toSet());
    Assertions.assertTrue(mfiles.size() > 0);
    GenericParser mparser = null;
    try {
        mparser = new GenericParser(mfiles.toArray(new File[mfiles.size()]));
    } catch (FileNotFoundException e) {
        Assertions.assertTrue(false);
    }
    Assertions.assertNotNull(mparser);
    DefaultTreeListener mdt = new DefaultTreeListener();
    boolean compile;
    try {
        mparser.compile();
        compile = true;
    } catch (CompilationException e) {
        compile = false;
    }
    mparser.setStreamProvider(new CasedStreamProvider(GenericParser.CaseSensitiveType.UPPER));
    mparser.setListener(mdt);
    Assertions.assertTrue(compile);
    verify(mparser, s.examples, s.nexamples, s.entrypoint);
}
Also used : java.util(java.util) FileUtils(org.snt.inmemantlr.utils.FileUtils) LoggerFactory(org.slf4j.LoggerFactory) ParsingException(org.snt.inmemantlr.exceptions.ParsingException) IllegalWorkflowException(org.snt.inmemantlr.exceptions.IllegalWorkflowException) CompilationException(org.snt.inmemantlr.exceptions.CompilationException) 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) CompilationException(org.snt.inmemantlr.exceptions.CompilationException) CasedStreamProvider(org.snt.inmemantlr.stream.CasedStreamProvider) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) DefaultTreeListener(org.snt.inmemantlr.listener.DefaultTreeListener) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Example 4 with CasedStreamProvider

use of org.snt.inmemantlr.stream.CasedStreamProvider in project inmemantlr by julianthome.

the class TestExternalGrammars method testMySQL.

@Test
public void testMySQL() {
    if (!toCheck("mysql"))
        return;
    Subject s = subjects.get("mysql");
    Set<File> mfiles = s.g4.stream().filter(v -> v.getName().matches("MySql" + "(Lexer|Parser).g4")).collect(Collectors.toSet());
    Assertions.assertTrue(mfiles.size() > 0);
    GenericParser mparser = null;
    try {
        mparser = new GenericParser(mfiles.toArray(new File[mfiles.size()]));
    } catch (FileNotFoundException e) {
        Assertions.assertTrue(false);
    }
    Assertions.assertNotNull(mparser);
    DefaultTreeListener mdt = new DefaultTreeListener();
    boolean compile;
    try {
        mparser.compile();
        compile = true;
    } catch (CompilationException e) {
        compile = false;
    }
    mparser.setStreamProvider(new CasedStreamProvider(GenericParser.CaseSensitiveType.UPPER));
    mparser.setListener(mdt);
    Assertions.assertTrue(compile);
    verify(mparser, s.examples, s.nexamples, s.entrypoint);
}
Also used : java.util(java.util) FileUtils(org.snt.inmemantlr.utils.FileUtils) LoggerFactory(org.slf4j.LoggerFactory) ParsingException(org.snt.inmemantlr.exceptions.ParsingException) IllegalWorkflowException(org.snt.inmemantlr.exceptions.IllegalWorkflowException) CompilationException(org.snt.inmemantlr.exceptions.CompilationException) 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) CompilationException(org.snt.inmemantlr.exceptions.CompilationException) CasedStreamProvider(org.snt.inmemantlr.stream.CasedStreamProvider) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) DefaultTreeListener(org.snt.inmemantlr.listener.DefaultTreeListener) GenericParser(org.snt.inmemantlr.GenericParser) Test(org.junit.jupiter.api.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)4 Test (org.junit.jupiter.api.Test)4 GenericParser (org.snt.inmemantlr.GenericParser)4 CompilationException (org.snt.inmemantlr.exceptions.CompilationException)4 CasedStreamProvider (org.snt.inmemantlr.stream.CasedStreamProvider)4 File (java.io.File)3 IOException (java.io.IOException)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)3 RecognitionException (org.antlr.v4.runtime.RecognitionException)3 FilenameUtils (org.apache.commons.io.FilenameUtils)3 Assertions (org.junit.jupiter.api.Assertions)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 IllegalWorkflowException (org.snt.inmemantlr.exceptions.IllegalWorkflowException)3 ParsingException (org.snt.inmemantlr.exceptions.ParsingException)3 DefaultTreeListener (org.snt.inmemantlr.listener.DefaultTreeListener)3