Search in sources :

Example 1 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project SQLWindowing by hbutani.

the class ParseUtils method parse.

public static QuerySpec parse(String query) throws WindowingException {
    Windowing2Lexer lexer;
    CommonTokenStream tokens;
    Windowing2Parser parser = null;
    CommonTree t;
    CommonTreeNodeStream nodes;
    QSpecBuilder2 qSpecBldr = null;
    String err;
    try {
        lexer = new Windowing2Lexer(new ANTLRStringStream(query));
        tokens = new CommonTokenStream(lexer);
        parser = new Windowing2Parser(tokens);
        parser.setTreeAdaptor(TranslateUtils.adaptor);
        t = (CommonTree) parser.query().getTree();
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
    } catch (WindowingException we) {
        throw we;
    } catch (Throwable te) {
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        throw new WindowingException("Parse Error:" + te.toString(), te);
    }
    TranslateUtils.unescapeStringLiterals((ASTNode) t);
    try {
        nodes = new CommonTreeNodeStream(t);
        nodes.setTokenStream(tokens);
        qSpecBldr = new QSpecBuilder2(nodes);
        qSpecBldr.query();
        err = qSpecBldr.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        return qSpecBldr.getQuerySpec();
    } catch (WindowingException we) {
        throw we;
    } catch (Throwable te) {
        err = qSpecBldr.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        throw new WindowingException("Parse Error:" + te.toString(), te);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) WindowingException(com.sap.hadoop.windowing.WindowingException) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Example 2 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project nifi by apache.

the class ExpressionCompiler method compileTree.

private Tree compileTree(final String expression) throws AttributeExpressionLanguageParsingException {
    try {
        final CharStream input = new ANTLRStringStream(expression);
        final AttributeExpressionLexer lexer = new AttributeExpressionLexer(input);
        final CommonTokenStream lexerTokenStream = new CommonTokenStream(lexer);
        final AttributeExpressionParser parser = new AttributeExpressionParser(lexerTokenStream);
        final Tree ast = (Tree) parser.query().getTree();
        final Tree tree = ast.getChild(0);
        // ensure that we are able to build the evaluators, so that we validate syntax
        final Evaluator<?> evaluator = buildEvaluator(tree);
        verifyMappingEvaluatorReduced(evaluator);
        return tree;
    } catch (final AttributeExpressionLanguageParsingException e) {
        throw e;
    } catch (final Exception e) {
        throw new AttributeExpressionLanguageParsingException(e);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) AttributeExpressionParser(org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser) Tree(org.antlr.runtime.tree.Tree) AttributeExpressionLexer(org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionLexer) AttributeExpressionLanguageParsingException(org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageParsingException) CharStream(org.antlr.runtime.CharStream) AttributeExpressionLanguageException(org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException) UnknownHostException(java.net.UnknownHostException) AttributeExpressionLanguageParsingException(org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageParsingException)

Example 3 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project nifi by apache.

the class HL7Query method createTokenStream.

private static CommonTokenStream createTokenStream(final String expression) throws HL7QueryParsingException {
    final CharStream input = new ANTLRStringStream(expression);
    final HL7QueryLexer lexer = new HL7QueryLexer(input);
    return new CommonTokenStream(lexer);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) HL7QueryLexer(org.apache.nifi.hl7.query.antlr.HL7QueryLexer) CharStream(org.antlr.runtime.CharStream)

Example 4 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project xtext-eclipse by eclipse.

the class AbstractSmokeTest method testSkipTokensInBetween.

@Test
public void testSkipTokensInBetween() throws Exception {
    for (String string : getSmokeTestModels()) {
        List<CommonToken> tokenList = Lists.newArrayList();
        {
            Lexer lexer = lexerProvider.get();
            lexer.setCharStream(new ANTLRStringStream(string));
            Token token = lexer.nextToken();
            while (token != Token.EOF_TOKEN) {
                tokenList.add((CommonToken) token);
                token = lexer.nextToken();
            }
        }
        for (CommonToken token : tokenList) {
            int start = token.getStartIndex();
            int length = token.getText().length();
            logProgress(token);
            processModel(string.substring(0, start) + string.substring(start + length));
        }
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Lexer(org.eclipse.xtext.parser.antlr.Lexer) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Example 5 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project xtext-eclipse by eclipse.

the class AbstractSmokeTest method testSkipTokensInBetweenWithoutResourceSet.

@Test
public void testSkipTokensInBetweenWithoutResourceSet() throws Exception {
    for (String string : getSmokeTestModels()) {
        List<CommonToken> tokenList = Lists.newArrayList();
        {
            Lexer lexer = lexerProvider.get();
            lexer.setCharStream(new ANTLRStringStream(string));
            Token token = lexer.nextToken();
            while (token != Token.EOF_TOKEN) {
                tokenList.add((CommonToken) token);
                token = lexer.nextToken();
            }
        }
        for (CommonToken token : tokenList) {
            int start = token.getStartIndex();
            int length = token.getText().length();
            logProgress(token);
            processModelWithoutResourceSet(string.substring(0, start) + string.substring(start + length));
        }
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Lexer(org.eclipse.xtext.parser.antlr.Lexer) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)115 CommonTokenStream (org.antlr.runtime.CommonTokenStream)62 Token (org.antlr.runtime.Token)29 Test (org.junit.Test)28 CharStream (org.antlr.runtime.CharStream)23 CommonToken (org.antlr.runtime.CommonToken)20 RecognitionException (org.antlr.runtime.RecognitionException)18 Lexer (org.eclipse.xtext.parser.antlr.Lexer)16 ActionSplitter (org.antlr.v4.parse.ActionSplitter)12 TokenStream (org.antlr.runtime.TokenStream)10 ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)10 ExprParser (org.apache.drill.common.expression.parser.ExprParser)10 CommonTree (org.antlr.runtime.tree.CommonTree)9 InternalSimpleExpressionsTestLanguageLexer (org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer)8 File (java.io.File)4 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)4 Tree (org.antlr.runtime.tree.Tree)4 ExprParser.parse_return (org.apache.drill.common.expression.parser.ExprParser.parse_return)4 ApexLexer (apex.jorje.parser.impl.ApexLexer)3 ArrayList (java.util.ArrayList)3