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);
}
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);
}
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"));
}
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"));
}
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)));
}
Aggregations