Search in sources :

Example 1 with ReactiveParseItem

use of com.dexels.navajo.parser.compiled.api.ReactiveParseItem in project navajo by Dexels.

the class ASTFunctionNode method interpretToLambda.

@Override
public ContextExpression interpretToLambda(List<String> problems, String expression, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
    List<ContextExpression> unnamed = new LinkedList<>();
    // TODO make lazy?
    Map<String, ContextExpression> named = new HashMap<>();
    for (int i = 0; i < jjtGetNumChildren(); i++) {
        Node sn = jjtGetChild(i);
        ContextExpression cn = sn.interpretToLambda(problems, expression, functionClassifier, mapResolver);
        if (cn instanceof NamedExpression) {
            NamedExpression ne = (NamedExpression) cn;
            named.put(ne.name, ne.expression);
        } else {
            unnamed.add(cn);
        }
    }
    FunctionClassification mode = functionClassifier.apply(functionName);
    switch(mode) {
        case REACTIVE_HEADER:
            break;
        case REACTIVE_SOURCE:
            return new ReactiveParseItem(functionName, Reactive.ReactiveItemType.REACTIVE_SOURCE, named, unnamed, expression, this);
        case REACTIVE_TRANSFORMER:
            return new ReactiveParseItem(functionName, Reactive.ReactiveItemType.REACTIVE_TRANSFORMER, named, unnamed, expression, this);
        case REACTIVE_REDUCER:
            return new ReactiveParseItem(functionName, Reactive.ReactiveItemType.REACTIVE_MAPPER, named, unnamed, expression, this);
        case DEFAULT:
        default:
    }
    return resolveNormalFunction(unnamed, named, problems, expression);
}
Also used : HashMap(java.util.HashMap) ReactiveParseItem(com.dexels.navajo.parser.compiled.api.ReactiveParseItem) NamedExpression(com.dexels.navajo.parser.NamedExpression) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) MappableTreeNode(com.dexels.navajo.script.api.MappableTreeNode) FunctionClassification(com.dexels.navajo.expression.api.FunctionClassification) LinkedList(java.util.LinkedList)

Aggregations

ContextExpression (com.dexels.navajo.expression.api.ContextExpression)1 FunctionClassification (com.dexels.navajo.expression.api.FunctionClassification)1 NamedExpression (com.dexels.navajo.parser.NamedExpression)1 ReactiveParseItem (com.dexels.navajo.parser.compiled.api.ReactiveParseItem)1 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1