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;
}
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());
}
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());
}
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());
}
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;
}
Aggregations