Search in sources :

Example 1 with ListNode

use of org.kie.dmn.feel.lang.ast.ListNode 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 ListNode

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

the class ASTBuilderVisitor method visitForExpression.

@Override
public BaseNode visitForExpression(FEEL_1_1Parser.ForExpressionContext ctx) {
    ListNode list = (ListNode) visit(ctx.iterationContexts());
    BaseNode expr = visit(ctx.expression());
    return ASTBuilderFactory.newForExpression(ctx, list, expr);
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ListNode(org.kie.dmn.feel.lang.ast.ListNode)

Example 3 with ListNode

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

the class FEELParserTest method testEmptyList.

@Test
public void testEmptyList() {
    String inputExpression = "[]";
    BaseNode list = parse(inputExpression);
    assertThat(list, is(instanceOf(ListNode.class)));
    assertThat(list.getResultType(), is(BuiltInType.LIST));
    assertThat(list.getText(), is(inputExpression));
    ListNode ln = (ListNode) list;
    assertThat(ln.getElements(), is(empty()));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ListNode(org.kie.dmn.feel.lang.ast.ListNode) Test(org.junit.Test)

Example 4 with ListNode

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

the class FEELParserTest method testFunctionDecisionTableInvocation.

@Test
public void testFunctionDecisionTableInvocation() {
    String inputExpression = "decision table( " + "    outputs: \"Applicant Risk Rating\"," + "    input expression list: [\"Applicant Age\", \"Medical History\"]," + "    rule list: [" + "        [ >60      , \"good\" , \"Medium\" ]," + "        [ >60      , \"bad\"  , \"High\"   ]," + "        [ [25..60] , -        , \"Medium\" ]," + "        [ <25      , \"good\" , \"Low\"    ]," + "        [ <25      , \"bad\"  , \"Medium\" ] ]," + "    hit policy: \"Unique\" )";
    // need to call parse passing in the input variables
    BaseNode functionBase = parse(inputExpression);
    assertThat(functionBase, is(instanceOf(FunctionInvocationNode.class)));
    assertThat(functionBase.getText(), is(inputExpression));
    FunctionInvocationNode function = (FunctionInvocationNode) functionBase;
    assertThat(function.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(function.getName().getText(), is("decision table"));
    assertThat(function.getParams(), is(instanceOf(ListNode.class)));
    assertThat(function.getParams().getElements().size(), is(4));
    assertThat(function.getParams().getElements().get(0), is(instanceOf(NamedParameterNode.class)));
    assertThat(function.getParams().getElements().get(1), is(instanceOf(NamedParameterNode.class)));
    assertThat(function.getParams().getElements().get(2), is(instanceOf(NamedParameterNode.class)));
    assertThat(function.getParams().getElements().get(3), is(instanceOf(NamedParameterNode.class)));
    NamedParameterNode named = (NamedParameterNode) function.getParams().getElements().get(0);
    assertThat(named.getText(), is("outputs: \"Applicant Risk Rating\""));
    assertThat(named.getName().getText(), is("outputs"));
    assertThat(named.getExpression(), is(instanceOf(StringNode.class)));
    assertThat(named.getExpression().getText(), is("\"Applicant Risk Rating\""));
    named = (NamedParameterNode) function.getParams().getElements().get(1);
    assertThat(named.getName().getText(), is("input expression list"));
    assertThat(named.getExpression(), is(instanceOf(ListNode.class)));
    ListNode list = (ListNode) named.getExpression();
    assertThat(list.getElements().size(), is(2));
    assertThat(list.getElements().get(0), is(instanceOf(StringNode.class)));
    assertThat(list.getElements().get(0).getText(), is("\"Applicant Age\""));
    assertThat(list.getElements().get(1), is(instanceOf(StringNode.class)));
    assertThat(list.getElements().get(1).getText(), is("\"Medical History\""));
    named = (NamedParameterNode) function.getParams().getElements().get(2);
    assertThat(named.getName().getText(), is("rule list"));
    assertThat(named.getExpression(), is(instanceOf(ListNode.class)));
    list = (ListNode) named.getExpression();
    assertThat(list.getElements().size(), is(5));
    assertThat(list.getElements().get(0), is(instanceOf(ListNode.class)));
    ListNode rule = (ListNode) list.getElements().get(0);
    assertThat(rule.getElements().size(), is(3));
    assertThat(rule.getElements().get(0), is(instanceOf(UnaryTestNode.class)));
    assertThat(rule.getElements().get(0).getText(), is(">60"));
    assertThat(rule.getElements().get(1), is(instanceOf(StringNode.class)));
    assertThat(rule.getElements().get(1).getText(), is("\"good\""));
    assertThat(rule.getElements().get(2), is(instanceOf(StringNode.class)));
    assertThat(rule.getElements().get(2).getText(), is("\"Medium\""));
    named = (NamedParameterNode) function.getParams().getElements().get(3);
    assertThat(named.getName().getText(), is("hit policy"));
    assertThat(named.getExpression(), is(instanceOf(StringNode.class)));
    assertThat(named.getExpression().getText(), is("\"Unique\""));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) NamedParameterNode(org.kie.dmn.feel.lang.ast.NamedParameterNode) ListNode(org.kie.dmn.feel.lang.ast.ListNode) FunctionInvocationNode(org.kie.dmn.feel.lang.ast.FunctionInvocationNode) Test(org.junit.Test)

Example 5 with ListNode

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

the class FEELParserTest method testExpressionList.

@Test
public void testExpressionList() {
    // TODO review this test is potentially wrong as the list is not homogeneous
    String inputExpression = "[ 10, foo * bar, true ]";
    BaseNode list = parse(inputExpression);
    assertThat(list, is(instanceOf(ListNode.class)));
    assertThat(list.getResultType(), is(BuiltInType.LIST));
    assertThat(list.getText(), is("10, foo * bar, true"));
    ListNode ln = (ListNode) list;
    assertThat(ln.getElements().size(), is(3));
    assertThat(ln.getElements().get(0), is(instanceOf(NumberNode.class)));
    assertThat(ln.getElements().get(1), is(instanceOf(InfixOpNode.class)));
    assertThat(ln.getElements().get(2), is(instanceOf(BooleanNode.class)));
}
Also used : 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)12 ListNode (org.kie.dmn.feel.lang.ast.ListNode)12 Test (org.junit.Test)5 InNode (org.kie.dmn.feel.lang.ast.InNode)2 RangeNode (org.kie.dmn.feel.lang.ast.RangeNode)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CompilerContext (org.kie.dmn.feel.lang.CompilerContext)1 Type (org.kie.dmn.feel.lang.Type)1 DashNode (org.kie.dmn.feel.lang.ast.DashNode)1 FunctionInvocationNode (org.kie.dmn.feel.lang.ast.FunctionInvocationNode)1 NamedParameterNode (org.kie.dmn.feel.lang.ast.NamedParameterNode)1 UnaryTestNode (org.kie.dmn.feel.lang.ast.UnaryTestNode)1 UnaryTest (org.kie.dmn.feel.runtime.UnaryTest)1