use of org.antlr.v4.runtime.ANTLRInputStream 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.antlr.v4.runtime.ANTLRInputStream in project pinot by linkedin.
the class Pql2Compiler method compileToBrokerRequest.
@Override
public BrokerRequest compileToBrokerRequest(String expression) throws Pql2CompilationException {
try {
//
CharStream charStream = new ANTLRInputStream(expression);
PQL2Lexer lexer = new PQL2Lexer(charStream);
lexer.setTokenFactory(new CommonTokenFactory(true));
TokenStream tokenStream = new UnbufferedTokenStream<CommonToken>(lexer);
PQL2Parser parser = new PQL2Parser(tokenStream);
parser.setErrorHandler(new BailErrorStrategy());
// Parse
ParseTree parseTree = parser.root();
ParseTreeWalker walker = new ParseTreeWalker();
Pql2AstListener listener = new Pql2AstListener(expression);
walker.walk(listener, parseTree);
AstNode rootNode = listener.getRootNode();
BrokerRequest brokerRequest = new BrokerRequest();
rootNode.updateBrokerRequest(brokerRequest);
return brokerRequest;
} catch (Pql2CompilationException e) {
throw e;
} catch (Exception e) {
throw new Pql2CompilationException(e.getMessage());
}
}
use of org.antlr.v4.runtime.ANTLRInputStream in project neo4j by neo4j.
the class ResultsParser method matcherParse.
ValueMatcher matcherParse(String value, CypherMatchersCreator listener) {
lexer.setInputStream(new ANTLRInputStream(value));
walker.walk(listener, parser.value());
return listener.parsed();
}
use of org.antlr.v4.runtime.ANTLRInputStream in project neo4j by neo4j.
the class ResultsParser method parseParameter.
Object parseParameter(String value, CypherParametersCreator listener) {
lexer.setInputStream(new ANTLRInputStream(value));
walker.walk(listener, parser.value());
return listener.parsed();
}
use of org.antlr.v4.runtime.ANTLRInputStream 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();
}
Aggregations