private List<Boolean> parseCompileEvaluate(String feelLiteralExpression, Object l) { Object left = EvalHelper.coerceNumber(l); FEELEventListenersManager mgr = new FEELEventListenersManager(); CompiledFEELSupport.SyntaxErrorListener listener = new CompiledFEELSupport.SyntaxErrorListener(); mgr.addListener(listener); EvaluationContext emptyContext = CodegenTestUtil.newEmptyEvaluationContext(mgr); CompiledFEELUnaryTests compiledUnaryTests = parse(feelLiteralExpression, mgr, listener); LOG.debug("{}", compiledUnaryTests); List<Boolean> result = compiledUnaryTests.getUnaryTests() .stream() .map(ut -> ut.apply(emptyContext, left)) .collect(Collectors.toList()); if (listener.isError()) { LOG.debug("{}", listener.event()); return Collections.emptyList(); } LOG.debug("{}", result); return result; }
private CompiledFEELUnaryTests parse(String input, Map<String, Type> inputTypes, FEELEventListenersManager mgr, CompiledFEELSupport.SyntaxErrorListener listener) { FEEL_1_1Parser parser = FEELParser.parse(mgr, input, inputTypes, Collections.emptyMap(), Collections.emptyList(), Collections.emptyList()); ParseTree tree = parser.unaryTestsRoot(); DirectCompilerResult directResult; if (listener.isError()) { directResult = CompiledFEELSupport.compiledErrorUnaryTest(listener.event().getMessage()); } else { ASTBuilderVisitor v = new ASTBuilderVisitor(inputTypes); BaseNode node = v.visit(tree); BaseNode transformed = node.accept(new ASTUnaryTestTransform()).node(); directResult = transformed.accept(new ASTCompilerVisitor()); } Expression expr = directResult.getExpression(); CompiledFEELUnaryTests cu = new CompilerBytecodeLoader().makeFromJPUnaryTestsExpression(input, expr, directResult.getFieldDeclarations()); return cu; }
private DirectCompilerResult getCompilerResult() { if (compiledExpression == null) { if (errorListener.isError()) { compiledExpression = DirectCompilerResult.of( CompiledFEELSupport.compiledErrorExpression( errorListener.event().getMessage()), BuiltInType.UNKNOWN); } else { try { compiledExpression = ast.accept(new ASTCompilerVisitor()); } catch (FEELCompilationError e) { compiledExpression = DirectCompilerResult.of( CompiledFEELSupport.compiledErrorExpression(e.getMessage()), BuiltInType.UNKNOWN); } } } return compiledExpression; }
private DirectCompilerResult getCompilerResult() { if (compiledExpression == null) { if (errorListener.isError()) { compiledExpression = CompiledFEELSupport.compiledErrorUnaryTest( errorListener.event().getMessage()); } else { try { compiledExpression = ast.accept(new ASTCompilerVisitor()); } catch (FEELCompilationError e) { compiledExpression = CompiledFEELSupport.compiledErrorUnaryTest(e.getMessage()); } } } return compiledExpression; }
public UnaryTestInterpretedExecutableExpression getInterpreted() { if (errorListener.isError()) { return UnaryTestInterpretedExecutableExpression.EMPTY; } else { return new UnaryTestInterpretedExecutableExpression(new CompiledExpressionImpl(ast)); } }