public IEnumerable <ITypedElement> Dispatcher(Closure context, IEnumerable <Invokee> args) { var actualArgs = new List <IEnumerable <ITypedElement> >(); var focus = args.First()(context, InvokeeFactory.EmptyArgs); if (!focus.Any()) { return(ElementNode.EmptyList); } actualArgs.Add(focus); var newCtx = context.Nest(focus); actualArgs.AddRange(args.Skip(1).Select(a => a(newCtx, InvokeeFactory.EmptyArgs))); if (actualArgs.Any(aa => !aa.Any())) { return(ElementNode.EmptyList); } var entry = _scope.DynamicGet(_name, actualArgs); if (entry != null) { try { // The Get() here should never fail, since we already know there's a (dynamic) matching candidate // Need to clean up this duplicate logic later var argFuncs = actualArgs.Select(arg => InvokeeFactory.Return(arg)); return(entry(context, argFuncs)); } catch (TargetInvocationException tie) { // Unwrap the very non-informative T.I.E, and throw the nested exception instead throw tie.InnerException; } } else { //TODO: Make error reporting better throw Error.Argument(noMatchError(actualArgs)); } }
public override Invokee VisitNewNodeListInit(FP.NewNodeListInitExpression expression, SymbolTable scope) { return(InvokeeFactory.Return(FhirValueList.Empty)); }
public override Invokee VisitConstant(FP.ConstantExpression expression, SymbolTable scope) { return(InvokeeFactory.Return(new ConstantValue(expression.Value))); }
public static void AddVar(this SymbolTable table, string name, IElementNavigator value) { table.Add(new CallSignature(name, typeof(string)), InvokeeFactory.Return(value)); }
public override Invokee VisitNewNodeListInit(FP.NewNodeListInitExpression expression, SymbolTable scope) { return(InvokeeFactory.Return(ElementNode.EmptyList)); }
public override Invokee VisitConstant(FP.ConstantExpression expression, SymbolTable scope) { return(InvokeeFactory.Return(ElementNode.ForPrimitive(expression.Value))); }