use of org.projectnessie.cel.shaded.org.antlr.v4.runtime.CommonTokenStream in project elasticsearch by elastic.
the class Walker method buildAntlrTree.
private SourceContext buildAntlrTree(String source) {
ANTLRInputStream stream = new ANTLRInputStream(source);
PainlessLexer lexer = new EnhancedPainlessLexer(stream, sourceName);
PainlessParser parser = new PainlessParser(new CommonTokenStream(lexer));
ParserErrorStrategy strategy = new ParserErrorStrategy(sourceName);
lexer.removeErrorListeners();
parser.removeErrorListeners();
if (settings.isPicky()) {
setupPicky(parser);
}
parser.setErrorHandler(strategy);
return parser.source();
}
use of org.projectnessie.cel.shaded.org.antlr.v4.runtime.CommonTokenStream in project aic-praise by aic-sri-international.
the class HOGMCodeArea method computeHighlighting.
private static StyleSpans<Collection<String>> computeHighlighting(String text) {
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
int lastTokenEnd = 0;
ANTLRInputStream input = new ANTLRInputStream(text);
HOGMLexer lexer = new HOGMLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
tokens.fill();
for (int i = 0; i < tokens.size(); i++) {
Token t = tokens.get(i);
if (t.getType() == Token.EOF) {
break;
}
String styleClass;
if (t.getType() == HOGMLexer.COMMENT || t.getType() == HOGMLexer.LINE_COMMENT) {
styleClass = "hogmCodeComment";
} else if (HOGMTerminalSymbols.isTerminalSymbol(t.getText())) {
styleClass = "hogmCodeKeyword";
} else {
styleClass = "hogmCodeOther";
}
int spacing = t.getStartIndex() - lastTokenEnd;
if (spacing > 0) {
spansBuilder.add(Collections.emptyList(), spacing);
}
int stylesize = (t.getStopIndex() - t.getStartIndex()) + 1;
spansBuilder.add(Collections.singleton(styleClass), stylesize);
lastTokenEnd = t.getStopIndex() + 1;
}
return spansBuilder.create();
}
use of org.projectnessie.cel.shaded.org.antlr.v4.runtime.CommonTokenStream in project presto by prestodb.
the class SqlParser method invokeParser.
private Node invokeParser(String name, String sql, Function<SqlBaseParser, ParserRuleContext> parseFunction) {
try {
SqlBaseLexer lexer = new SqlBaseLexer(new CaseInsensitiveStream(new ANTLRInputStream(sql)));
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
SqlBaseParser parser = new SqlBaseParser(tokenStream);
parser.addParseListener(new PostProcessor());
lexer.removeErrorListeners();
lexer.addErrorListener(ERROR_LISTENER);
parser.removeErrorListeners();
parser.addErrorListener(ERROR_LISTENER);
ParserRuleContext tree;
try {
// first, try parsing with potentially faster SLL mode
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
tree = parseFunction.apply(parser);
} catch (ParseCancellationException ex) {
// if we fail, parse with LL mode
// rewind input stream
tokenStream.reset();
parser.reset();
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
tree = parseFunction.apply(parser);
}
return new AstBuilder().visit(tree);
} catch (StackOverflowError e) {
throw new ParsingException(name + " is too large (stack overflow while parsing)");
}
}
use of org.projectnessie.cel.shaded.org.antlr.v4.runtime.CommonTokenStream in project siddhi by wso2.
the class SiddhiCompiler method parseFunctionDefinition.
public static FunctionDefinition parseFunctionDefinition(String source) throws SiddhiParserException {
ANTLRInputStream input = new ANTLRInputStream(source);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.definition_function_final();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (FunctionDefinition) eval.visit(tree);
}
use of org.projectnessie.cel.shaded.org.antlr.v4.runtime.CommonTokenStream in project siddhi by wso2.
the class SiddhiCompiler method parseTimeConstantDefinition.
public static TimeConstant parseTimeConstantDefinition(String source) throws SiddhiParserException {
ANTLRInputStream input = new ANTLRInputStream(source);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.time_value();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (TimeConstant) eval.visit(tree);
}
Aggregations