Search in sources :

Example 16 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project jabref by JabRef.

the class VM method charStream2CommonTree.

private static CommonTree charStream2CommonTree(CharStream bst) throws RecognitionException {
    BstLexer lex = new BstLexer(bst);
    CommonTokenStream tokens = new CommonTokenStream(lex);
    BstParser parser = new BstParser(tokens);
    BstParser.program_return r = parser.program();
    return (CommonTree) r.getTree();
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTree(org.antlr.runtime.tree.CommonTree)

Example 17 with CommonTokenStream

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

the class TestBuilder method parsePath.

// modified code from SchemaPath.De class. This should be used sparingly and only in tests if absolutely needed.
public static SchemaPath parsePath(String path) {
    try {
        ExprLexer lexer = new ExprLexer(new ANTLRStringStream(path));
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        ExprParser parser = new ExprParser(tokens);
        ExprParser.parse_return ret = parser.parse();
        if (ret.e instanceof SchemaPath) {
            return (SchemaPath) ret.e;
        } else {
            throw new IllegalStateException("Schema path is not a valid format.");
        }
    } catch (RecognitionException e) {
        throw new RuntimeException(e);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) SchemaPath(org.apache.drill.common.expression.SchemaPath) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser(org.apache.drill.common.expression.parser.ExprParser) RecognitionException(org.antlr.runtime.RecognitionException)

Example 18 with CommonTokenStream

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

the class TreeTest method parseExpression.

private LogicalExpression parseExpression(String expr) throws RecognitionException, IOException {
    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) ExprParser.parse_return(org.apache.drill.common.expression.parser.ExprParser.parse_return)

Example 19 with CommonTokenStream

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

the class WindowingShell method checkQuery.

public void checkQuery(String query) throws WindowingException {
    Windowing2Lexer lexer;
    CommonTokenStream tokens;
    Windowing2Parser parser = null;
    @SuppressWarnings("unused") CommonTree t;
    // CommonTreeNodeStream nodes;
    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 (Throwable te) {
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        throw new WindowingException("Parse Error:" + te.toString(), te);
    }
}
Also used : Windowing2Lexer(com.sap.hadoop.windowing.parser.Windowing2Lexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) Windowing2Parser(com.sap.hadoop.windowing.parser.Windowing2Parser) WindowingException(com.sap.hadoop.windowing.WindowingException)

Example 20 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project Palladio-Editors-Sirius by PalladioSimulator.

the class PCMServices method validExpression.

/**
 * Parses an stochastic expression to determine whether it is valid.
 *
 * @param the
 *            expressionString
 * @return the validity
 */
private boolean validExpression(final String expressionString) {
    final MyPCMStoExLexer lexer = new MyPCMStoExLexer(new ANTLRStringStream(expressionString));
    final MyPCMStoExParser parser = new MyPCMStoExParser(new CommonTokenStream(lexer));
    try {
        parser.expression();
    } catch (final RecognitionException e1) {
        return false;
    }
    if (lexer.hasErrors() || parser.hasErrors()) {
        return false;
    }
    return true;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) MyPCMStoExParser(org.palladiosimulator.pcm.stochasticexpressions.parser.MyPCMStoExParser) CommonTokenStream(org.antlr.runtime.CommonTokenStream) MyPCMStoExLexer(org.palladiosimulator.pcm.stochasticexpressions.parser.MyPCMStoExLexer) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

CommonTokenStream (org.antlr.runtime.CommonTokenStream)47 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)36 RecognitionException (org.antlr.runtime.RecognitionException)12 CommonTree (org.antlr.runtime.tree.CommonTree)12 Test (org.junit.Test)11 CommonToken (org.antlr.runtime.CommonToken)9 CharStream (org.antlr.runtime.CharStream)8 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)8 InternalSimpleExpressionsTestLanguageLexer (org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer)8 TokenStream (org.antlr.runtime.TokenStream)5 File (java.io.File)4 InputStreamReader (java.io.InputStreamReader)4 WindowingException (com.sap.hadoop.windowing.WindowingException)3 FileInputStream (java.io.FileInputStream)3 ANTLRReaderStream (org.antlr.runtime.ANTLRReaderStream)3 Token (org.antlr.runtime.Token)3 TokenSource (org.antlr.runtime.TokenSource)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