Search in sources :

Example 61 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project drools by kiegroup.

the class DSLTokenizedMappingFile method buildFileMappingWalker.

private DSLMapWalker buildFileMappingWalker(final List<ParserError> errors, CharStream stream) throws RecognitionException {
    DSLMapLexer lexer = new DSLMapLexer(stream);
    CommonTokenStream tokens = new CommonTokenStream();
    tokens.setTokenSource(lexer);
    DSLMapParser parser = new DSLMapParser(tokens);
    DSLMapParser.mapping_file_return example = parser.mapping_file();
    CommonTree tree = (CommonTree) example.getTree();
    // logger.info(tree.toStringTree());
    CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
    DSLMapWalker walker = new DSLMapWalker(nodes);
    errors.addAll(lexer.getErrors());
    errors.addAll(parser.getErrors());
    return walker;
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Example 62 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project drools by kiegroup.

the class JavaExprAnalyzer method parse.

private JavaParser parse(final String expr) {
    final CharStream charStream = new ANTLRStringStream(expr);
    final JavaLexer lexer = new JavaLexer(charStream);
    final TokenStream tokenStream = new CommonTokenStream(lexer);
    return new JavaParser(tokenStream);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) JavaParser(org.drools.compiler.rule.builder.dialect.java.parser.JavaParser) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) JavaLexer(org.drools.compiler.rule.builder.dialect.java.parser.JavaLexer) CharStream(org.antlr.runtime.CharStream)

Example 63 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project jwt by emweb.

the class CssParser method parseFile.

public StyleSheet parseFile(CharSequence stylesheetContents) {
    Css21LexerExt lex = null;
    Css21ParserExt parser = null;
    try {
        lex = new Css21LexerExt(new ANTLRFileStream(stylesheetContents.toString()));
        CommonTokenStream tokens = new CommonTokenStream(lex);
        parser = new Css21ParserExt(tokens);
        currentStylesheet = new StyleSheetImpl();
        parser.styleSheet();
        lastError_ = lex.lastError_ + parser.lastError_;
        return !lex.hasError_ && !parser.hasError_ ? currentStylesheet : null;
    } catch (RecognitionException e) {
        // e.printStackTrace();
        lastError_ = lex.lastError_ + parser.lastError_;
        return null;
    } catch (IOException e) {
        // e.printStackTrace();
        lastError_ = "file" + stylesheetContents + "not found.";
        return null;
    }
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) ANTLRFileStream(org.antlr.runtime.ANTLRFileStream) IOException(java.io.IOException) RecognitionException(org.antlr.runtime.RecognitionException)

Example 64 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project jwt by emweb.

the class CssParser method parse.

public StyleSheet parse(CharSequence stylesheetContents) {
    Css21LexerExt lex = new Css21LexerExt(new ANTLRStringStream(stylesheetContents.toString()));
    CommonTokenStream tokens = new CommonTokenStream(lex);
    Css21ParserExt parser = new Css21ParserExt(tokens);
    currentStylesheet = new StyleSheetImpl();
    try {
        parser.styleSheet();
        lastError_ = lex.lastError_ + parser.lastError_;
        return !lex.hasError_ && !parser.hasError_ ? currentStylesheet : null;
    } catch (RecognitionException e) {
        e.printStackTrace();
        lastError_ = lex.lastError_ + parser.lastError_;
        return null;
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) RecognitionException(org.antlr.runtime.RecognitionException)

Example 65 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project drill by axbaretto.

the class TestEvaluationVisitor method getExpr.

private LogicalExpression getExpr(String expr) throws Exception {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExprParser parser = new ExprParser(tokens);
    parse_return ret = parser.parse();
    return ret.e;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser.parse_return(org.apache.drill.common.expression.parser.ExprParser.parse_return) ExprParser(org.apache.drill.common.expression.parser.ExprParser)

Aggregations

CommonTokenStream (org.antlr.runtime.CommonTokenStream)93 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)62 RecognitionException (org.antlr.runtime.RecognitionException)25 CharStream (org.antlr.runtime.CharStream)22 CommonTree (org.antlr.runtime.tree.CommonTree)21 TokenStream (org.antlr.runtime.TokenStream)17 File (java.io.File)12 Test (org.junit.Test)12 CommonToken (org.antlr.runtime.CommonToken)10 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)10 ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)10 ExprParser (org.apache.drill.common.expression.parser.ExprParser)10 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)8 ANTLRInputStream (org.antlr.runtime.ANTLRInputStream)8 InternalSimpleExpressionsTestLanguageLexer (org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer)8 InputStreamReader (java.io.InputStreamReader)6 Token (org.antlr.runtime.Token)6 JPA2Lexer (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer)5 JPA2Parser (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser)5