Search in sources :

Example 1 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class ASTBuilderVisitor method visitLogicalNegation.

@Override
public BaseNode visitLogicalNegation(FEEL_1_1Parser.LogicalNegationContext ctx) {
    BaseNode name = ASTBuilderFactory.newNameRefNode(ctx.not_key(), BuiltInType.BOOLEAN);
    BaseNode node = visit(ctx.unaryExpression());
    ListNode params = ASTBuilderFactory.newListNode(ctx.unaryExpression(), Arrays.asList(node));
    return buildFunctionCall(ctx, name, params);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ListNode(org.kie.dmn.feel.lang.ast.ListNode)

Example 2 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELImpl method compileExpressionList.

public CompiledExpression compileExpressionList(String expression, CompilerContext ctx) {
    FEEL_1_1Parser parser = FEELParser.parse(getEventsManager(ctx.getListeners()), expression, ctx.getInputVariableTypes(), ctx.getInputVariables(), ctx.getFEELFunctions(), profiles);
    ParseTree tree = parser.expressionList();
    ASTBuilderVisitor v = new ASTBuilderVisitor(ctx.getInputVariableTypes());
    BaseNode expr = v.visit(tree);
    CompiledExpression ce = new CompiledExpressionImpl(expr);
    return ce;
}
Also used : ASTBuilderVisitor(org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FEEL_1_1Parser(org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser) ParseTree(org.antlr.v4.runtime.tree.ParseTree) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression)

Example 3 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class FEELShowcase method onTextChange.

@EventHandler("text")
public void onTextChange(final KeyUpEvent e) {
    final FEEL_1_1Parser parser = FEELParser.parse(null, text.getValue(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), Collections.emptyList(), null);
    final ParseTree tree = parser.expression();
    final ASTBuilderVisitor astBuilderVisitor = new ASTBuilderVisitor(emptyMap(), null);
    final BaseNode baseNode = astBuilderVisitor.visit(tree);
    nodes.setValue(getNodesString(baseNode));
    evaluation.setValue(getEvaluation(baseNode));
}
Also used : ASTBuilderVisitor(org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FEEL_1_1Parser(org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser) ParseTree(org.antlr.v4.runtime.tree.ParseTree) EventHandler(org.jboss.errai.ui.shared.api.annotations.EventHandler)

Example 4 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class ASTCompilerVisitor method visit.

@Override
public DirectCompilerResult visit(ListNode n) {
    MethodCallExpr list = Expressions.list();
    DirectCompilerResult result = DirectCompilerResult.of(list, BuiltInType.LIST);
    for (BaseNode e : n.getElements()) {
        DirectCompilerResult r = e.accept(this);
        result.withFD(r.getFieldDeclarations());
        list.addArgument(r.getExpression());
    }
    return result;
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 5 with BaseNode

use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.

the class ASTCompilerVisitor method visit.

@Override
public DirectCompilerResult visit(IterationContextNode n) {
    DirectCompilerResult iterName = n.getName().accept(this);
    DirectCompilerResult iterExpr = n.getExpression().accept(this);
    Expressions.NamedLambda nameLambda = Expressions.namedLambda(iterName.getExpression(), n.getName().getText());
    Expressions.NamedLambda exprLambda = Expressions.namedLambda(iterExpr.getExpression(), n.getExpression().getText());
    MethodCallExpr with = new MethodCallExpr(null, "with").addArgument(nameLambda.name()).addArgument(exprLambda.name());
    DirectCompilerResult r = DirectCompilerResult.of(with, BuiltInType.UNKNOWN);
    r.addFieldDeclaration(nameLambda.field());
    r.addFieldDeclaration(exprLambda.field());
    r.withFD(iterName);
    r.withFD(iterExpr);
    BaseNode rangeEndExpr = n.getRangeEndExpr();
    if (rangeEndExpr != null) {
        DirectCompilerResult rangeEnd = rangeEndExpr.accept(this);
        Expressions.NamedLambda rangeLambda = Expressions.namedLambda(rangeEnd.getExpression(), rangeEndExpr.getText());
        with.addArgument(rangeLambda.name());
        r.addFieldDeclaration(rangeLambda.field());
        r.withFD(rangeEnd);
    }
    return r;
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)108 Test (org.junit.Test)60 ListNode (org.kie.dmn.feel.lang.ast.ListNode)16 InfixOpNode (org.kie.dmn.feel.lang.ast.InfixOpNode)12 IterationContextNode (org.kie.dmn.feel.lang.ast.IterationContextNode)9 NameDefNode (org.kie.dmn.feel.lang.ast.NameDefNode)9 UnaryTestListNode (org.kie.dmn.feel.lang.ast.UnaryTestListNode)9 FEEL_1_1Parser (org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser)9 ParseTree (org.antlr.v4.runtime.tree.ParseTree)8 ContextEntryNode (org.kie.dmn.feel.lang.ast.ContextEntryNode)8 ContextNode (org.kie.dmn.feel.lang.ast.ContextNode)8 FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)8 ArrayList (java.util.ArrayList)6 RangeNode (org.kie.dmn.feel.lang.ast.RangeNode)6 ASTBuilderVisitor (org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor)6 InNode (org.kie.dmn.feel.lang.ast.InNode)5 PathExpressionNode (org.kie.dmn.feel.lang.ast.PathExpressionNode)5 SignedUnaryNode (org.kie.dmn.feel.lang.ast.SignedUnaryNode)5 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)4 Type (org.kie.dmn.feel.lang.Type)4