use of org.antlr.runtime.CommonTokenStream in project drools by kiegroup.
the class JavaExprAnalyzer method parse.
private JavaParser parse(final String expr) {
final CharStream charStream = new ANTLRStringStream(expr);
final JavaLexer lexer = new JavaLexer(charStream);
final TokenStream tokenStream = new CommonTokenStream(lexer);
return new JavaParser(tokenStream);
}
use of org.antlr.runtime.CommonTokenStream in project binnavi by google.
the class DebuggerMemoryExpressionParser method parse.
/**
* Parses a single memory expression string.
*
* @param memoryExpression The memory expression string to parse.
*
* @return The parsed memory expression tree.
*
* @throws RecognitionException Thrown if parsing failed.
*/
public static MemoryExpressionElement parse(final String memoryExpression) throws RecognitionException {
final CharStream charStream = new ANTLRStringStream(memoryExpression);
final MemoryExpressionLexer lexer = new MemoryExpressionLexer(charStream);
final CommonTokenStream tokens = new CommonTokenStream();
tokens.setTokenSource(lexer);
final MemoryExpressionParser parser = new MemoryExpressionParser(tokens) {
@Override
public void recover(final IntStream input, final RecognitionException exception) {
// Nothing to do
}
@Override
public Object recoverFromMismatchedToken(final IntStream input, final int ttype, final org.antlr.runtime.BitSet follow) throws RecognitionException {
throw new MismatchedTokenException(ttype, input);
}
@Override
public void reportError(final RecognitionException exception) {
// Nothing to do
}
};
parser.setTreeAdaptor(adaptor);
final MemoryExpressionParser.prog_return parserResult = parser.prog();
final CommonTree ast = (CommonTree) parserResult.getTree();
return convert(ast);
}
use of org.antlr.runtime.CommonTokenStream in project yamcs-studio by yamcs.
the class FormulaAst method createParser.
/**
* Creates a parser for the given text.
*
* @param text
* the string to be parsed
* @return the new parser
*/
static FormulaParser createParser(String text) {
CharStream stream = new ANTLRStringStream(text);
var lexer = new FormulaLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
return new FormulaParser(tokenStream);
}
use of org.antlr.runtime.CommonTokenStream in project cassandra by apache.
the class CqlParserTest method parseAndCountErrors.
private void parseAndCountErrors(String cql, int expectedErrors, ParserOperation operation) throws RecognitionException {
SyntaxErrorCounter counter = new SyntaxErrorCounter();
CharStream stream = new ANTLRStringStream(cql);
CqlLexer lexer = new CqlLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
CqlParser parser = new CqlParser(tokenStream);
parser.addErrorListener(counter);
operation.perform(parser);
assertEquals(expectedErrors, counter.count);
}
use of org.antlr.runtime.CommonTokenStream in project cassandra by apache.
the class CqlParserTest method testAddErrorListener.
@Test
public void testAddErrorListener() throws Exception {
SyntaxErrorCounter firstCounter = new SyntaxErrorCounter();
SyntaxErrorCounter secondCounter = new SyntaxErrorCounter();
CharStream stream = new ANTLRStringStream("SELECT * FORM FROM test");
CqlLexer lexer = new CqlLexer(stream);
TokenStream tokenStream = new CommonTokenStream(lexer);
CqlParser parser = new CqlParser(tokenStream);
parser.addErrorListener(firstCounter);
parser.addErrorListener(secondCounter);
// By default CqlParser should recover from the syntax error by removing FORM
// but as recoverFromMismatchedToken and recover have been overloaded, it will not
// and the returned ParsedStatement will be null.
assertNull(parser.query());
// Only one error must be reported (mismatched: FORM).
assertEquals(1, firstCounter.count);
assertEquals(1, secondCounter.count);
}
Aggregations