Search in sources :

Example 76 with ANTLRStringStream

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

the class RuleParserTest method testChunkWithParens.

@Test
public void testChunkWithParens() throws Exception {
    String input = "(fnord())";
    createParser(new ANTLRStringStream(input));
    String returnData = parser.chunk(DRL6Lexer.LEFT_PAREN, DRL6Lexer.RIGHT_PAREN, -1);
    assertEquals("fnord()", returnData);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Test(org.junit.Test)

Example 77 with ANTLRStringStream

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

the class RuleParserTest method testChunkWithRandomCharac5ters.

@Test
public void testChunkWithRandomCharac5ters() throws Exception {
    String input = "( %*9dkj)";
    createParser(new ANTLRStringStream(input));
    String returnData = parser.chunk(DRL6Lexer.LEFT_PAREN, DRL6Lexer.RIGHT_PAREN, -1);
    assertEquals("%*9dkj", returnData);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Test(org.junit.Test)

Example 78 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream 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 79 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream 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)

Example 80 with ANTLRStringStream

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

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)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)117 CommonTokenStream (org.antlr.runtime.CommonTokenStream)63 Token (org.antlr.runtime.Token)30 Test (org.junit.Test)28 CharStream (org.antlr.runtime.CharStream)24 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 CommonTree (org.antlr.runtime.tree.CommonTree)10 ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)10 ExprParser (org.apache.drill.common.expression.parser.ExprParser)10 InternalSimpleExpressionsTestLanguageLexer (org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer)8 File (java.io.File)4 ArrayList (java.util.ArrayList)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