use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testComparisonInFixOp.
@Test
public void testComparisonInFixOp() {
String inputExpression = "foo >= bar * 10";
BaseNode infix = parse(inputExpression);
assertThat(infix, is(instanceOf(InfixOpNode.class)));
assertThat(infix.getResultType(), is(BuiltInType.BOOLEAN));
assertThat(infix.getText(), is(inputExpression));
InfixOpNode in = (InfixOpNode) infix;
assertThat(in.getLeft(), is(instanceOf(NameRefNode.class)));
assertThat(in.getLeft().getText(), is("foo"));
assertThat(in.getRight(), is(instanceOf(InfixOpNode.class)));
assertThat(in.getRight().getText(), is("bar * 10"));
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testPower1.
@Test
public void testPower1() {
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(NameRefNode.class)));
assertThat(mult.getLeft().getText(), is("y"));
assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
assertThat(mult.getRight(), is(instanceOf(InfixOpNode.class)));
assertThat(mult.getRight().getText(), is("5 ** 3"));
InfixOpNode exp = (InfixOpNode) mult.getRight();
assertThat(exp.getLeft(), is(instanceOf(NumberNode.class)));
assertThat(exp.getLeft().getText(), is("5"));
assertThat(exp.getOperator(), is(InfixOpNode.InfixOperator.POW));
assertThat(exp.getRight(), is(instanceOf(NumberNode.class)));
assertThat(exp.getRight().getText(), is("3"));
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class ASTBuilderVisitor method visitAddExpression.
@Override
public BaseNode visitAddExpression(FEEL_1_1Parser.AddExpressionContext ctx) {
BaseNode left = visit(ctx.additiveExpression());
BaseNode right = visit(ctx.multiplicativeExpression());
String op = ctx.op.getText();
return ASTBuilderFactory.newInfixOpNode(ctx, left, op, right);
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class ASTBuilderVisitor method visitIterationContext.
@Override
public BaseNode visitIterationContext(FEEL_1_1Parser.IterationContextContext ctx) {
NameDefNode name = (NameDefNode) visit(ctx.nameDefinition());
BaseNode expr = visit(ctx.expression().get(0));
if (ctx.expression().size() == 1) {
return ASTBuilderFactory.newIterationContextNode(ctx, name, expr);
} else {
BaseNode rangeEndExpr = visit(ctx.expression().get(1));
return ASTBuilderFactory.newIterationContextNode(ctx, name, expr, rangeEndExpr);
}
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class ASTBuilderVisitor method visitRelExpressionValueList.
@Override
public BaseNode visitRelExpressionValueList(FEEL_1_1Parser.RelExpressionValueListContext ctx) {
BaseNode value = visit(ctx.val);
BaseNode list = visit(ctx.expressionList());
return ASTBuilderFactory.newInNode(ctx, value, list);
}
Aggregations