Search in sources :

Example 76 with BaseNode

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

the class ASTBuilderVisitor method visitContextEntries.

@Override
public BaseNode visitContextEntries(FEEL_1_1Parser.ContextEntriesContext ctx) {
    List<BaseNode> nodes = new ArrayList<>();
    scopeHelper.pushScope();
    for (FEEL_1_1Parser.ContextEntryContext c : ctx.contextEntry()) {
        // forced cast similarly to visitFunctionDefinition() method
        ContextEntryNode visited = (ContextEntryNode) visit(c);
        if (visited != null) {
            nodes.add(visited);
            scopeHelper.addType(visited.getName().getText(), visited.getResultType());
        }
    }
    scopeHelper.popScope();
    return ASTBuilderFactory.newListNode(ctx, nodes);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ArrayList(java.util.ArrayList) ContextEntryNode(org.kie.dmn.feel.lang.ast.ContextEntryNode)

Example 77 with BaseNode

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

the class ASTBuilderVisitor method visitNegatedUnaryTests.

@Override
public BaseNode visitNegatedUnaryTests(FEEL_1_1Parser.NegatedUnaryTestsContext ctx) {
    // negating a unary tests: BOOLEAN-type anyway
    BaseNode name = ASTBuilderFactory.newNameRefNode(ctx.not_key(), BuiltInType.BOOLEAN);
    ListNode value = (ListNode) visit(ctx.simpleUnaryTests());
    return buildFunctionCall(ctx, name, value);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ListNode(org.kie.dmn.feel.lang.ast.ListNode)

Example 78 with BaseNode

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

the class FEELParserTest method testBetween.

@Test
public void testBetween() {
    String inputExpression = "x between 10+y and 3**z";
    BaseNode between = parse(inputExpression);
    assertThat(between, is(instanceOf(BetweenNode.class)));
    assertThat(between.getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(between.getText(), is(inputExpression));
    BetweenNode btw = (BetweenNode) between;
    assertThat(btw.getValue(), is(instanceOf(NameRefNode.class)));
    assertThat(btw.getValue().getText(), is("x"));
    assertThat(btw.getStart(), is(instanceOf(InfixOpNode.class)));
    assertThat(btw.getStart().getText(), is("10+y"));
    assertThat(btw.getEnd(), is(instanceOf(InfixOpNode.class)));
    assertThat(btw.getEnd().getText(), is("3**z"));
}
Also used : BetweenNode(org.kie.dmn.feel.lang.ast.BetweenNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 79 with BaseNode

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

the class FEELParserTest method testForExpression.

@Test
public void testForExpression() {
    String inputExpression = "for item in order.items return item.price * item.quantity";
    BaseNode forbase = parse(inputExpression);
    assertThat(forbase, is(instanceOf(ForExpressionNode.class)));
    assertThat(forbase.getText(), is(inputExpression));
    assertThat(forbase.getResultType(), is(BuiltInType.LIST));
    ForExpressionNode forExpr = (ForExpressionNode) forbase;
    assertThat(forExpr.getIterationContexts().size(), is(1));
    assertThat(forExpr.getExpression(), is(instanceOf(InfixOpNode.class)));
    assertThat(forExpr.getExpression().getText(), is("item.price * item.quantity"));
    IterationContextNode ic = forExpr.getIterationContexts().get(0);
    assertThat(ic.getName().getText(), is("item"));
    assertThat(ic.getExpression(), is(instanceOf(QualifiedNameNode.class)));
    assertThat(ic.getExpression().getText(), is("order.items"));
}
Also used : ForExpressionNode(org.kie.dmn.feel.lang.ast.ForExpressionNode) IterationContextNode(org.kie.dmn.feel.lang.ast.IterationContextNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 80 with BaseNode

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

the class FEELParserTest method testInValueList.

@Test
public void testInValueList() {
    // TODO review this test might be wrong as list is not homogeneous
    String inputExpression = "x / 4 in ( 10+y, true, 80, someVar )";
    BaseNode inNode = parse(inputExpression);
    assertThat(inNode, is(instanceOf(InNode.class)));
    assertThat(inNode.getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(inNode.getText(), is(inputExpression));
    InNode in = (InNode) inNode;
    assertThat(in.getValue(), is(instanceOf(InfixOpNode.class)));
    assertThat(in.getValue().getText(), is("x / 4"));
    assertThat(in.getExprs(), is(instanceOf(ListNode.class)));
    assertThat(in.getExprs().getText(), is("10+y, true, 80, someVar"));
    ListNode list = (ListNode) in.getExprs();
    assertThat(list.getElements().get(0), is(instanceOf(InfixOpNode.class)));
    assertThat(list.getElements().get(1), is(instanceOf(BooleanNode.class)));
    assertThat(list.getElements().get(2), is(instanceOf(NumberNode.class)));
    assertThat(list.getElements().get(3), is(instanceOf(NameRefNode.class)));
}
Also used : InNode(org.kie.dmn.feel.lang.ast.InNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ListNode(org.kie.dmn.feel.lang.ast.ListNode) Test(org.junit.Test)

Aggregations

BaseNode (org.kie.dmn.feel.lang.ast.BaseNode)84 Test (org.junit.Test)54 ListNode (org.kie.dmn.feel.lang.ast.ListNode)12 InfixOpNode (org.kie.dmn.feel.lang.ast.InfixOpNode)11 FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)7 IterationContextNode (org.kie.dmn.feel.lang.ast.IterationContextNode)7 NameDefNode (org.kie.dmn.feel.lang.ast.NameDefNode)7 ContextEntryNode (org.kie.dmn.feel.lang.ast.ContextEntryNode)6 ContextNode (org.kie.dmn.feel.lang.ast.ContextNode)6 PathExpressionNode (org.kie.dmn.feel.lang.ast.PathExpressionNode)4 SignedUnaryNode (org.kie.dmn.feel.lang.ast.SignedUnaryNode)4 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 InNode (org.kie.dmn.feel.lang.ast.InNode)3 InstanceOfNode (org.kie.dmn.feel.lang.ast.InstanceOfNode)3 RangeNode (org.kie.dmn.feel.lang.ast.RangeNode)3 ArrayList (java.util.ArrayList)2 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)2 FunctionDefNode (org.kie.dmn.feel.lang.ast.FunctionDefNode)2 NamedParameterNode (org.kie.dmn.feel.lang.ast.NamedParameterNode)2 QualifiedNameNode (org.kie.dmn.feel.lang.ast.QualifiedNameNode)2