Search in sources :

Example 41 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project antlr4 by antlr.

the class UseDefAnalyzer method actionIsContextDependent.

public static boolean actionIsContextDependent(ActionAST actionAST) {
    ANTLRStringStream in = new ANTLRStringStream(actionAST.token.getText());
    in.setLine(actionAST.token.getLine());
    in.setCharPositionInLine(actionAST.token.getCharPositionInLine());
    // can't be simple bool with anon class
    final boolean[] dependent = new boolean[] { false };
    ActionSplitterListener listener = new BlankActionSplitterListener() {

        @Override
        public void nonLocalAttr(String expr, Token x, Token y) {
            dependent[0] = true;
        }

        @Override
        public void qualifiedAttr(String expr, Token x, Token y) {
            dependent[0] = true;
        }

        @Override
        public void setAttr(String expr, Token x, Token rhs) {
            dependent[0] = true;
        }

        @Override
        public void setExprAttribute(String expr) {
            dependent[0] = true;
        }

        @Override
        public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) {
            dependent[0] = true;
        }

        @Override
        public void attr(String expr, Token x) {
            dependent[0] = true;
        }
    };
    ActionSplitter splitter = new ActionSplitter(in, listener);
    // forces eval, triggers listener methods
    splitter.getActionTokens();
    return dependent[0];
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ActionSplitter(org.antlr.v4.parse.ActionSplitter) ActionSplitterListener(org.antlr.v4.parse.ActionSplitterListener) Token(org.antlr.runtime.Token)

Example 42 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project antlr4 by antlr.

the class ActionSniffer method examineAction.

public void examineAction() {
    //System.out.println("examine "+actionToken);
    ANTLRStringStream in = new ANTLRStringStream(actionToken.getText());
    in.setLine(actionToken.getLine());
    in.setCharPositionInLine(actionToken.getCharPositionInLine());
    ActionSplitter splitter = new ActionSplitter(in, this);
    // forces eval, triggers listener methods
    node.chunks = splitter.getActionTokens();
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ActionSplitter(org.antlr.v4.parse.ActionSplitter)

Example 43 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project antlr4 by antlr.

the class ActionTranslator method translateActionChunk.

public static List<ActionChunk> translateActionChunk(OutputModelFactory factory, RuleFunction rf, String action, ActionAST node) {
    Token tokenWithinAction = node.token;
    ActionTranslator translator = new ActionTranslator(factory, node);
    translator.rf = rf;
    factory.getGrammar().tool.log("action-translator", "translate " + action);
    String altLabel = node.getAltLabel();
    if (rf != null) {
        translator.nodeContext = rf.ruleCtx;
        if (altLabel != null)
            translator.nodeContext = rf.altLabelCtxs.get(altLabel);
    }
    ANTLRStringStream in = new ANTLRStringStream(action);
    in.setLine(tokenWithinAction.getLine());
    in.setCharPositionInLine(tokenWithinAction.getCharPositionInLine());
    ActionSplitter trigger = new ActionSplitter(in, translator);
    // forces eval, triggers listener methods
    trigger.getActionTokens();
    return translator.chunks;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ActionSplitter(org.antlr.v4.parse.ActionSplitter) Token(org.antlr.runtime.Token)

Example 44 with ANTLRStringStream

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

the class PhysicalOpUnitTestBase method parseExpr.

@Override
protected LogicalExpression parseExpr(String expr) {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExprParser parser = new ExprParser(tokens);
    try {
        return parser.parse().e;
    } catch (RecognitionException e) {
        throw new RuntimeException("Error parsing expression: " + expr);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser(org.apache.drill.common.expression.parser.ExprParser) RecognitionException(org.antlr.runtime.RecognitionException)

Example 45 with ANTLRStringStream

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

the class TestEvaluationVisitor method getExpr.

private LogicalExpression getExpr(String expr) throws Exception {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    //    tokens.fill();
    //    for(Token t : (List<Token>) tokens.getTokens()){
    //      System.out.println(t + "" + t.getType());
    //    }
    //    tokens.rewind();
    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

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)60 CommonTokenStream (org.antlr.runtime.CommonTokenStream)36 Test (org.junit.Test)20 CommonToken (org.antlr.runtime.CommonToken)15 Token (org.antlr.runtime.Token)13 CharStream (org.antlr.runtime.CharStream)11 Lexer (org.eclipse.xtext.parser.antlr.Lexer)10 RecognitionException (org.antlr.runtime.RecognitionException)9 InternalSimpleExpressionsTestLanguageLexer (org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer)8 CommonTree (org.antlr.runtime.tree.CommonTree)6 ActionSplitter (org.antlr.v4.parse.ActionSplitter)6 TokenStream (org.antlr.runtime.TokenStream)5 InternalXtendLexer (org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer)4 WindowingException (com.sap.hadoop.windowing.WindowingException)3 ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)3 ExprParser (org.apache.drill.common.expression.parser.ExprParser)3 CeylonLexer (com.redhat.ceylon.compiler.typechecker.parser.CeylonLexer)2 CeylonParser (com.redhat.ceylon.compiler.typechecker.parser.CeylonParser)2 LineMap (com.sun.tools.javac.util.Position.LineMap)2 File (java.io.File)2