use of org.antlr.v4.runtime.CommonTokenStream 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.CommonTokenStream 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.CommonTokenStream 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.CommonTokenStream in project ballerina by ballerina-lang.
the class Parser method generateCompilationUnit.
private CompilationUnitNode generateCompilationUnit(PackageSourceEntry sourceEntry) {
try {
int prevErrCount = dlog.errorCount;
BDiagnosticSource diagnosticSrc = getDiagnosticSource(sourceEntry);
String entryName = sourceEntry.getEntryName();
BLangCompilationUnit compUnit = (BLangCompilationUnit) TreeBuilder.createCompilationUnit();
compUnit.setName(sourceEntry.getEntryName());
compUnit.pos = new DiagnosticPos(diagnosticSrc, 1, 1, 1, 1);
ANTLRInputStream ais = new ANTLRInputStream(new ByteArrayInputStream(sourceEntry.getCode()));
ais.name = entryName;
BallerinaLexer lexer = new BallerinaLexer(ais);
lexer.removeErrorListeners();
lexer.addErrorListener(new BallerinaParserErrorListener(context, diagnosticSrc));
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
BallerinaParser parser = new BallerinaParser(tokenStream);
parser.setErrorHandler(getErrorStrategy(diagnosticSrc));
parser.addParseListener(newListener(tokenStream, compUnit, diagnosticSrc));
parser.compilationUnit();
return compUnit;
} catch (IOException e) {
throw new RuntimeException("Error in populating package model: " + e.getMessage(), e);
}
}
use of org.antlr.v4.runtime.CommonTokenStream 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