Search in sources :

Example 1 with FunctionDefinition

use of org.ballerinalang.siddhi.query.api.definition.FunctionDefinition 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);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) FunctionDefinition(org.ballerinalang.siddhi.query.api.definition.FunctionDefinition) SiddhiQLBaseVisitorImpl(org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 2 with FunctionDefinition

use of org.ballerinalang.siddhi.query.api.definition.FunctionDefinition in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitDefinition_function.

@Override
public FunctionDefinition visitDefinition_function(@NotNull SiddhiQLParser.Definition_functionContext ctx) {
    String functionName = (String) visitFunction_name(ctx.function_name());
    String languageName = (String) visitLanguage_name(ctx.language_name());
    Attribute.Type attributeType = (Attribute.Type) visit(ctx.attribute_type());
    String functionBody = (String) visitFunction_body(ctx.function_body());
    FunctionDefinition functionDefinition = new FunctionDefinition();
    functionDefinition.id(functionName).language(languageName).type(attributeType).body(functionBody);
    populateQueryContext(functionDefinition, ctx);
    return functionDefinition;
}
Also used : RangePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType) PartitionType(org.ballerinalang.siddhi.query.api.execution.partition.PartitionType) OrderByAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OrderByAttribute) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute) FunctionDefinition(org.ballerinalang.siddhi.query.api.definition.FunctionDefinition)

Aggregations

FunctionDefinition (org.ballerinalang.siddhi.query.api.definition.FunctionDefinition)2 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)1 PartitionType (org.ballerinalang.siddhi.query.api.execution.partition.PartitionType)1 RangePartitionType (org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType)1 ValuePartitionType (org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType)1 OrderByAttribute (org.ballerinalang.siddhi.query.api.execution.query.selection.OrderByAttribute)1 OutputAttribute (org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute)1 SiddhiQLBaseVisitorImpl (org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl)1