Search in sources :

Example 21 with CommonTokenStream

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

the class PartFilterExprUtil method getFilterParser.

public static FilterParser getFilterParser(String filter) throws MetaException {
    FilterLexer lexer = new FilterLexer(new ANTLRNoCaseStringStream(filter));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    FilterParser parser = new FilterParser(tokens);
    try {
        parser.filter();
    } catch (RecognitionException re) {
        throw new MetaException("Error parsing partition filter; lexer error: " + lexer.errorMsg + "; exception " + re);
    }
    if (lexer.errorMsg != null) {
        throw new MetaException("Error parsing partition filter : " + lexer.errorMsg);
    }
    return parser;
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) FilterParser(org.apache.hadoop.hive.metastore.parser.FilterParser) RecognitionException(org.antlr.runtime.RecognitionException) FilterLexer(org.apache.hadoop.hive.metastore.parser.FilterLexer) ANTLRNoCaseStringStream(org.apache.hadoop.hive.metastore.parser.ExpressionTree.ANTLRNoCaseStringStream) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 22 with CommonTokenStream

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

the class LexerErrorTest method testLexerError_02.

@Test
public void testLexerError_02() throws Exception {
    String model = "a 'incomplete string";
    InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
    lexer.setCharStream(new ANTLRStringStream(model));
    CommonTokenStream stream = new CommonTokenStream(lexer);
    @SuppressWarnings("unchecked") List<CommonToken> tokens = stream.getTokens();
    assertEquals(tokens.toString(), 3, tokens.size());
    assertEquals("a", tokens.get(0).getText());
    assertEquals(" ", tokens.get(1).getText());
    assertEquals("'incomplete string", tokens.get(2).getText());
    assertEquals(0, tokens.get(2).getType());
}
Also used : InternalSimpleExpressionsTestLanguageLexer(org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Example 23 with CommonTokenStream

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

the class LexerErrorTest method testLexerError_03.

@Test
public void testLexerError_03() throws Exception {
    String model = "a '\\ incomplete string with bad escape sequence";
    InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
    lexer.setCharStream(new ANTLRStringStream(model));
    CommonTokenStream stream = new CommonTokenStream(lexer);
    @SuppressWarnings("unchecked") List<CommonToken> tokens = stream.getTokens();
    assertEquals(tokens.toString(), 3, tokens.size());
    assertEquals("a", tokens.get(0).getText());
    assertEquals(" ", tokens.get(1).getText());
    assertEquals("'\\ incomplete string with bad escape sequence", tokens.get(2).getText());
    assertEquals(0, tokens.get(2).getType());
}
Also used : InternalSimpleExpressionsTestLanguageLexer(org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Example 24 with CommonTokenStream

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

the class LexerErrorTest method testLexerError_04.

@Test
public void testLexerError_04() throws Exception {
    String model = "a 'incomplete string with bad escape sequence \\";
    InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
    lexer.setCharStream(new ANTLRStringStream(model));
    CommonTokenStream stream = new CommonTokenStream(lexer);
    @SuppressWarnings("unchecked") List<CommonToken> tokens = stream.getTokens();
    assertEquals(tokens.toString(), 3, tokens.size());
    assertEquals("a", tokens.get(0).getText());
    assertEquals(" ", tokens.get(1).getText());
    assertEquals("'incomplete string with bad escape sequence \\", tokens.get(2).getText());
    assertEquals(0, tokens.get(2).getType());
}
Also used : InternalSimpleExpressionsTestLanguageLexer(org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Example 25 with CommonTokenStream

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

the class DrlExprParser method parse.

/**
 * Parse an expression from text
 */
public ConstraintConnectiveDescr parse(final String text) {
    ConstraintConnectiveDescr constraint = null;
    try {
        DRLLexer lexer = DRLFactory.getDRLLexer(new ANTLRStringStream(text), languageLevel);
        CommonTokenStream input = new CommonTokenStream(lexer);
        RecognizerSharedState state = new RecognizerSharedState();
        helper = new ParserHelper(input, state, languageLevel);
        DRLExpressions parser = DRLFactory.getDRLExpressions(input, state, helper, languageLevel);
        parser.setBuildDescr(true);
        // setting initial value just in case
        parser.setLeftMostExpr(null);
        BaseDescr expr = parser.conditionalOrExpression();
        if (expr != null && !parser.hasErrors()) {
            constraint = ConstraintConnectiveDescr.newAnd();
            constraint.addOrMerge(expr);
        }
    } catch (RecognitionException e) {
        helper.reportError(e);
    }
    return constraint;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) DRLExpressions(org.drools.compiler.lang.DRLExpressions) DRLLexer(org.drools.compiler.lang.DRLLexer) ParserHelper(org.drools.compiler.lang.ParserHelper) RecognizerSharedState(org.antlr.runtime.RecognizerSharedState) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) 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