use of org.antlr.v4.runtime.tree.ParseTree in project ballerina by ballerina-lang.
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);
}
use of org.antlr.v4.runtime.tree.ParseTree in project ballerina by ballerina-lang.
the class SiddhiCompiler method parsePartition.
public static Partition parsePartition(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.partition_final();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (Partition) eval.visit(tree);
}
use of org.antlr.v4.runtime.tree.ParseTree in project ballerina by ballerina-lang.
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.antlr.v4.runtime.tree.ParseTree in project ballerina by ballerina-lang.
the class BLangWSPreservingParserListener method exitEveryRule.
@Override
public void exitEveryRule(ParserRuleContext parserRuleContext) {
if (getWSWasCalledOn == parserRuleContext) {
return;
}
int rangeEndTokenIndex;
if (parserRuleContext.stop == null) {
ParseTree child = parserRuleContext.getChild(1);
if (child instanceof TerminalNode) {
// This is needed to handle A + B + C case of BinaryAddSubExpression
rangeEndTokenIndex = ((TerminalNode) child).getSymbol().getTokenIndex();
} else {
rangesOfRuleContext.pop();
return;
}
} else {
rangeEndTokenIndex = parserRuleContext.stop.getTokenIndex() + 1;
}
closeLastRange(rangeEndTokenIndex);
Stack<TokenRange> tokenRanges = new Stack<>();
// TODO: check why rangesOfRuleContext become empty before closing the last range.
if (!rangesOfRuleContext.isEmpty()) {
tokenRanges = rangesOfRuleContext.pop();
}
Stack<Whitespace> ws = new Stack<>();
for (TokenRange range : tokenRanges) {
addWSFromRange(ws, range);
}
wsSinceLastNode.addAll(ws);
if (!rangesOfRuleContext.isEmpty()) {
rangesOfRuleContext.peek().add(new TokenRange(rangeEndTokenIndex));
}
}
use of org.antlr.v4.runtime.tree.ParseTree in project ballerina by ballerina-lang.
the class TomlProcessor method parseTomlContent.
/**
* Generate the proxy object by passing in the toml file.
*
* @param stream charstream object containing the content
* @return proxy object
*/
public static ParseTree parseTomlContent(CharStream stream) {
TomlLexer lexer = new TomlLexer(stream);
// Get a list of matched tokens
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Pass the tokens to the parser
TomlParser parser = new TomlParser(tokens);
return parser.toml();
}
Aggregations