Search in sources :

Example 86 with BaseNode

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

the class FEELParserTest method testPathExpression.

@Test
public void testPathExpression() {
    String inputExpression = "[ 10, 15 ].size";
    BaseNode pathBase = parse(inputExpression);
    assertThat(pathBase, is(instanceOf(PathExpressionNode.class)));
    assertThat(pathBase.getText(), is(inputExpression));
    PathExpressionNode pathExpr = (PathExpressionNode) pathBase;
    assertThat(pathExpr.getExpression(), is(instanceOf(ListNode.class)));
    assertThat(pathExpr.getExpression().getText(), is("10, 15"));
    assertThat(pathExpr.getName(), is(instanceOf(NameRefNode.class)));
    assertThat(pathExpr.getName().getText(), is("size"));
}
Also used : PathExpressionNode(org.kie.dmn.feel.lang.ast.PathExpressionNode) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) Test(org.junit.Test)

Example 87 with BaseNode

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

the class FEELParserTest method testPower3.

@Test
public void testPower3() {
    String inputExpression = "y ** 5 * 3";
    BaseNode infix = parse(inputExpression, mapOf(entry("y", BuiltInType.NUMBER)));
    assertThat(infix, is(instanceOf(InfixOpNode.class)));
    assertThat(infix.getResultType(), is(BuiltInType.NUMBER));
    assertThat(infix.getText(), is(inputExpression));
    InfixOpNode mult = (InfixOpNode) infix;
    assertThat(mult.getLeft(), is(instanceOf(InfixOpNode.class)));
    assertThat(mult.getLeft().getText(), is("y ** 5"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
    assertThat(mult.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(mult.getRight().getText(), is("3"));
    InfixOpNode exp = (InfixOpNode) mult.getLeft();
    assertThat(exp.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(exp.getLeft().getText(), is("y"));
    assertThat(exp.getOperator(), is(InfixOpNode.InfixOperator.POW));
    assertThat(exp.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(exp.getRight().getText(), is("5"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 88 with BaseNode

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

the class FEELParserTest method testInstanceOfExpressionAnd.

@Test
public void testInstanceOfExpressionAnd() {
    String inputExpression = "\"foo\" instance of string and 10 instance of number";
    BaseNode andExpr = parse(inputExpression);
    assertThat(andExpr, is(instanceOf(InfixOpNode.class)));
    assertThat(andExpr.getText(), is(inputExpression));
    assertThat(andExpr.getResultType(), is(BuiltInType.BOOLEAN));
    InfixOpNode and = (InfixOpNode) andExpr;
    assertThat(and.getOperator(), is(InfixOpNode.InfixOperator.AND));
    assertThat(and.getLeft(), is(instanceOf(InstanceOfNode.class)));
    assertThat(and.getRight(), is(instanceOf(InstanceOfNode.class)));
    assertThat(and.getLeft().getText(), is("\"foo\" instance of string"));
    assertThat(and.getRight().getText(), is("10 instance of number"));
    assertThat(and.getLeft().getResultType(), is(BuiltInType.BOOLEAN));
    assertThat(and.getRight().getResultType(), is(BuiltInType.BOOLEAN));
    InstanceOfNode ioExpr = (InstanceOfNode) and.getLeft();
    assertThat(ioExpr.getExpression(), is(instanceOf(StringNode.class)));
    assertThat(ioExpr.getExpression().getText(), is("\"foo\""));
    assertThat(ioExpr.getType(), is(instanceOf(TypeNode.class)));
    assertThat(ioExpr.getType().getText(), is("string"));
    ioExpr = (InstanceOfNode) and.getRight();
    assertThat(ioExpr.getExpression(), is(instanceOf(NumberNode.class)));
    assertThat(ioExpr.getExpression().getText(), is("10"));
    assertThat(ioExpr.getType(), is(instanceOf(TypeNode.class)));
    assertThat(ioExpr.getType().getText(), is("number"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) InstanceOfNode(org.kie.dmn.feel.lang.ast.InstanceOfNode) Test(org.junit.Test)

Example 89 with BaseNode

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

the class FEELParserTest method testDivision.

@Test
public void testDivision() {
    String inputExpression = "y / 5 * ( x )";
    BaseNode infix = parse(inputExpression, mapOf(entry("x", BuiltInType.NUMBER), entry("y", BuiltInType.NUMBER)));
    assertThat(infix, is(instanceOf(InfixOpNode.class)));
    assertThat(infix.getResultType(), is(BuiltInType.NUMBER));
    assertThat(infix.getText(), is(inputExpression));
    InfixOpNode mult = (InfixOpNode) infix;
    assertThat(mult.getLeft(), is(instanceOf(InfixOpNode.class)));
    assertThat(mult.getLeft().getText(), is("y / 5"));
    InfixOpNode div = (InfixOpNode) mult.getLeft();
    assertThat(div.getLeft(), is(instanceOf(NameRefNode.class)));
    assertThat(div.getLeft().getText(), is("y"));
    assertThat(div.getOperator(), is(InfixOpNode.InfixOperator.DIV));
    assertThat(div.getRight(), is(instanceOf(NumberNode.class)));
    assertThat(div.getRight().getText(), is("5"));
    assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
    assertThat(mult.getRight(), is(instanceOf(NameRefNode.class)));
    assertThat(mult.getRight().getText(), is("x"));
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) InfixOpNode(org.kie.dmn.feel.lang.ast.InfixOpNode) Test(org.junit.Test)

Example 90 with BaseNode

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

the class FEELParserTest method testInUnaryTestList.

@Test
public void testInUnaryTestList() {
    String inputExpression = "x ** y in ( <=1000, >t, null, (2000..z[, ]z..2000], [(10+5)..(a*b)) )";
    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 ** y"));
    assertThat(in.getExprs(), is(instanceOf(ListNode.class)));
    assertThat(in.getExprs().getText(), is("<=1000, >t, null, (2000..z[, ]z..2000], [(10+5)..(a*b))"));
    ListNode list = (ListNode) in.getExprs();
    assertThat(list.getElements().get(0), is(instanceOf(RangeNode.class)));
    assertThat(list.getElements().get(0).getText(), is("<=1000"));
    assertThat(list.getElements().get(1), is(instanceOf(RangeNode.class)));
    assertThat(list.getElements().get(1).getText(), is(">t"));
    assertThat(list.getElements().get(2), is(instanceOf(NullNode.class)));
    assertThat(list.getElements().get(2).getText(), is("null"));
    assertThat(list.getElements().get(3), is(instanceOf(RangeNode.class)));
    RangeNode interval = (RangeNode) list.getElements().get(3);
    assertThat(interval.getText(), is("(2000..z["));
    assertThat(interval.getLowerBound(), is(RangeNode.IntervalBoundary.OPEN));
    assertThat(interval.getUpperBound(), is(RangeNode.IntervalBoundary.OPEN));
    assertThat(interval.getStart(), is(instanceOf(NumberNode.class)));
    assertThat(interval.getEnd(), is(instanceOf(NameRefNode.class)));
    assertThat(list.getElements().get(4), is(instanceOf(RangeNode.class)));
    interval = (RangeNode) list.getElements().get(4);
    assertThat(interval.getText(), is("]z..2000]"));
    assertThat(interval.getLowerBound(), is(RangeNode.IntervalBoundary.OPEN));
    assertThat(interval.getUpperBound(), is(RangeNode.IntervalBoundary.CLOSED));
    assertThat(interval.getStart(), is(instanceOf(NameRefNode.class)));
    assertThat(interval.getEnd(), is(instanceOf(NumberNode.class)));
    assertThat(list.getElements().get(5), is(instanceOf(RangeNode.class)));
    interval = (RangeNode) list.getElements().get(5);
    assertThat(interval.getText(), is("[(10+5)..(a*b))"));
    assertThat(interval.getLowerBound(), is(RangeNode.IntervalBoundary.CLOSED));
    assertThat(interval.getUpperBound(), is(RangeNode.IntervalBoundary.OPEN));
    assertThat(interval.getStart(), is(instanceOf(InfixOpNode.class)));
    assertThat(interval.getEnd(), is(instanceOf(InfixOpNode.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) RangeNode(org.kie.dmn.feel.lang.ast.RangeNode) Test(org.junit.Test)

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