use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method parse.
private BaseNode parse(String input, Map<String, Type> inputTypes) {
FEEL_1_1Parser parser = FEELParser.parse(null, input, inputTypes, Collections.emptyMap(), Collections.emptyList(), Collections.emptyList());
ParseTree tree = parser.expression();
ASTBuilderVisitor v = new ASTBuilderVisitor(inputTypes);
BaseNode expr = v.visit(tree);
return expr;
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testAdd1.
@Test
public void testAdd1() {
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 add = (InfixOpNode) infix;
assertThat(add.getLeft(), is(instanceOf(NameRefNode.class)));
assertThat(add.getLeft().getText(), is("y"));
assertThat(add.getOperator(), is(InfixOpNode.InfixOperator.ADD));
assertThat(add.getRight(), is(instanceOf(InfixOpNode.class)));
assertThat(add.getRight().getText(), is("5 * 3"));
InfixOpNode mult = (InfixOpNode) add.getRight();
assertThat(mult.getLeft(), is(instanceOf(NumberNode.class)));
assertThat(mult.getLeft().getText(), is("5"));
assertThat(mult.getOperator(), is(InfixOpNode.InfixOperator.MULT));
assertThat(mult.getRight(), is(instanceOf(NumberNode.class)));
assertThat(mult.getRight().getText(), is("3"));
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELImpl method compileExpressionList.
public CompiledExpression compileExpressionList(String expression, CompilerContext ctx) {
FEEL_1_1Parser parser = FEELParser.parse(getEventsManager(ctx.getListeners()), expression, ctx.getInputVariableTypes(), ctx.getInputVariables(), ctx.getFEELFunctions(), profiles);
ParseTree tree = parser.expressionList();
ASTBuilderVisitor v = new ASTBuilderVisitor(ctx.getInputVariableTypes());
BaseNode expr = v.visit(tree);
CompiledExpression ce = new CompiledExpressionImpl(expr);
return ce;
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testBooleanTrueLiteral.
@Test
public void testBooleanTrueLiteral() {
String inputExpression = "true";
BaseNode bool = parse(inputExpression);
assertThat(bool, is(instanceOf(BooleanNode.class)));
assertThat(bool.getResultType(), is(BuiltInType.BOOLEAN));
assertLocation(inputExpression, bool);
}
use of org.kie.dmn.feel.lang.ast.BaseNode in project drools by kiegroup.
the class FEELParserTest method testNameReference.
@Test
public void testNameReference() {
String inputExpression = "someSimpleName";
BaseNode nameRef = parse(inputExpression, mapOf(entry("someSimpleName", BuiltInType.STRING)));
assertThat(nameRef, is(instanceOf(NameRefNode.class)));
assertThat(nameRef.getResultType(), is(BuiltInType.STRING));
assertLocation(inputExpression, nameRef);
}
Aggregations