public abstract T VisitVariableRef(VariableRefExpression expression, SymbolTable scope);
public DynaDispatcher(string name, SymbolTable scope) { _scope = scope; _name = name; }
public abstract T VisitFunctionCall(FunctionCallExpression expression, SymbolTable scope);
//public abstract T VisitLambda(LambdaExpression expression); public abstract T VisitNewNodeListInit(NewNodeListInitExpression expression, SymbolTable scope);
public override T Accept <T>(ExpressionVisitor <T> visitor, SymbolTable scope) { return(visitor.VisitVariableRef(this, scope)); }
public static void AddLogic(this SymbolTable table, string name, Func <Func <bool?>, Func <bool?>, bool?> func) { table.Add(new CallSignature(name, typeof(bool?), typeof(object), typeof(Func <bool?>), typeof(Func <bool?>)), InvokeeFactory.WrapLogic(func)); }
public override Invokee VisitFunctionCall(FP.FunctionCallExpression expression, SymbolTable scope) { var focus = expression.Focus.ToEvaluator(scope); var arguments = new List <Invokee>() { focus }; arguments.AddRange(expression.Arguments.Select(arg => arg.ToEvaluator(scope))); // We have no real type information, so just pass object as the type var types = new List <Type>() { typeof(object) }; // for the focus; types.AddRange(expression.Arguments.Select(a => typeof(object))); // for the arguments // Now locate the function based on the types and name Invokee boundFunction = resolve(scope, expression.FunctionName, types); return(InvokeeFactory.Invoke(expression.FunctionName, arguments, boundFunction)); }
public abstract T Accept <T>(ExpressionVisitor <T> visitor, SymbolTable scope);
public static Invokee ToEvaluator(this FP.Expression expr, SymbolTable scope) { var compiler = new EvaluatorVisitor(); return(expr.Accept <Invokee>(compiler, scope)); }
public override Invokee VisitConstant(FP.ConstantExpression expression, SymbolTable scope) { return(InvokeeFactory.Return(ElementNode.ForPrimitive(expression.Value))); }
public SymbolTable(SymbolTable parent) { Parent = parent; }
public static void AddVar(this SymbolTable table, string name, IElementNavigator value) { table.Add(new CallSignature(name, typeof(string)), InvokeeFactory.Return(value.ToTypedElement())); }
public static void AddVar(this SymbolTable table, string name, object value) { table.AddVar(name, ElementNode.ForPrimitive(value)); }
public static SymbolTable AddStandardFP(this SymbolTable t) { // Functions that operate on the focus, without null propagation t.Add("empty", (IEnumerable <object> f) => !f.Any()); t.Add("exists", (IEnumerable <object> f) => f.Any()); t.Add("count", (IEnumerable <object> f) => f.Count()); t.Add("trace", (IEnumerable <IElementNavigator> f, string name) => f.Trace(name)); // t.Add("binary.|", (object f, IEnumerable<IValueProvider> l, IEnumerable<IValueProvider> r) => l.ConcatUnion(r)); t.Add("binary.|", (object f, IEnumerable <IElementNavigator> l, IEnumerable <IElementNavigator> r) => l.DistinctUnion(r)); t.Add("binary.contains", (object f, IEnumerable <IElementNavigator> a, IElementNavigator b) => a.Contains(b)); t.Add("binary.in", (object f, IElementNavigator a, IEnumerable <IElementNavigator> b) => b.Contains(a)); t.Add("distinct", (IEnumerable <IElementNavigator> f) => f.Distinct()); t.Add("isDistinct", (IEnumerable <IElementNavigator> f) => f.IsDistinct()); t.Add("subsetOf", (IEnumerable <IElementNavigator> f, IEnumerable <IElementNavigator> a) => f.SubsetOf(a)); t.Add("supersetOf", (IEnumerable <IElementNavigator> f, IEnumerable <IElementNavigator> a) => a.SubsetOf(f)); t.Add("today", (object f) => PartialDateTime.Today()); t.Add("now", (object f) => PartialDateTime.Now()); t.Add("binary.&", (object f, string a, string b) => (a ?? "") + (b ?? "")); t.Add("iif", (IEnumerable <IElementNavigator> f, bool?condition, IEnumerable <IElementNavigator> result) => f.IIf(condition, result)); t.Add("iif", (IEnumerable <IElementNavigator> f, bool?condition, IEnumerable <IElementNavigator> result, IEnumerable <IElementNavigator> otherwise) => f.IIf(condition, result, otherwise)); // Functions that use normal null propagation and work with the focus (buy may ignore it) t.Add("not", (IEnumerable <IElementNavigator> f) => f.Not(), doNullProp: true); t.Add("builtin.children", (IEnumerable <IElementNavigator> f, string a) => f.Navigate(a), doNullProp: true); t.Add("children", (IEnumerable <IElementNavigator> f) => f.Children(), doNullProp: true); t.Add("descendants", (IEnumerable <IElementNavigator> f) => f.Descendants(), doNullProp: true); t.Add("binary.=", (object f, IEnumerable <IElementNavigator> a, IEnumerable <IElementNavigator> b) => a.IsEqualTo(b), doNullProp: true); t.Add("binary.!=", (object f, IEnumerable <IElementNavigator> a, IEnumerable <IElementNavigator> b) => !a.IsEqualTo(b), doNullProp: true); t.Add("binary.~", (object f, IEnumerable <IElementNavigator> a, IEnumerable <IElementNavigator> b) => a.IsEquivalentTo(b), doNullProp: true); t.Add("binary.!~", (object f, IEnumerable <IElementNavigator> a, IEnumerable <IElementNavigator> b) => !a.IsEquivalentTo(b), doNullProp: true); t.Add("unary.-", (object f, long a) => - a, doNullProp: true); t.Add("unary.-", (object f, decimal a) => - a, doNullProp: true); t.Add("unary.+", (object f, long a) => a, doNullProp: true); t.Add("unary.+", (object f, decimal a) => a, doNullProp: true); t.Add("binary.*", (object f, long a, long b) => a * b, doNullProp: true); t.Add("binary.*", (object f, decimal a, decimal b) => a * b, doNullProp: true); t.Add("binary./", (object f, decimal a, decimal b) => a / b, doNullProp: true); //.Add((object f, decimal a, decimal b) => a / b, doNullProp: true); t.Add("binary.+", (object f, long a, long b) => a + b, doNullProp: true); t.Add("binary.+", (object f, decimal a, decimal b) => a + b, doNullProp: true); t.Add("binary.+", (object f, string a, string b) => a + b, doNullProp: true); t.Add("binary.-", (object f, long a, long b) => a - b, doNullProp: true); t.Add("binary.-", (object f, decimal a, decimal b) => a - b, doNullProp: true); t.Add("binary.div", (object f, long a, long b) => a / b, doNullProp: true); t.Add("binary.div", (object f, decimal a, decimal b) => (long)Math.Truncate(a / b), doNullProp: true); t.Add("binary.mod", (object f, long a, long b) => a % b, doNullProp: true); t.Add("binary.mod", (object f, decimal a, decimal b) => a % b, doNullProp: true); t.Add("binary.>", (object f, long a, long b) => a > b, doNullProp: true); t.Add("binary.>", (object f, decimal a, decimal b) => a > b, doNullProp: true); t.Add("binary.>", (object f, string a, string b) => String.CompareOrdinal(a, b) > 0, doNullProp: true); t.Add("binary.>", (object f, PartialDateTime a, PartialDateTime b) => a > b, doNullProp: true); t.Add("binary.>", (object f, PartialTime a, PartialTime b) => a > b, doNullProp: true); t.Add("binary.<", (object f, long a, long b) => a < b, doNullProp: true); t.Add("binary.<", (object f, decimal a, decimal b) => a < b, doNullProp: true); t.Add("binary.<", (object f, string a, string b) => String.CompareOrdinal(a, b) < 0, doNullProp: true); t.Add("binary.<", (object f, PartialDateTime a, PartialDateTime b) => a < b, doNullProp: true); t.Add("binary.<", (object f, PartialTime a, PartialTime b) => a < b, doNullProp: true); t.Add("binary.<=", (object f, long a, long b) => a <= b, doNullProp: true); t.Add("binary.<=", (object f, decimal a, decimal b) => a <= b, doNullProp: true); t.Add("binary.<=", (object f, string a, string b) => String.CompareOrdinal(a, b) <= 0, doNullProp: true); t.Add("binary.<=", (object f, PartialDateTime a, PartialDateTime b) => a <= b, doNullProp: true); t.Add("binary.<=", (object f, PartialTime a, PartialTime b) => a <= b, doNullProp: true); t.Add("binary.>=", (object f, long a, long b) => a >= b, doNullProp: true); t.Add("binary.>=", (object f, decimal a, decimal b) => a >= b, doNullProp: true); t.Add("binary.>=", (object f, string a, string b) => String.CompareOrdinal(a, b) >= 0, doNullProp: true); t.Add("binary.>=", (object f, PartialDateTime a, PartialDateTime b) => a >= b, doNullProp: true); t.Add("binary.>=", (object f, PartialTime a, PartialTime b) => a >= b, doNullProp: true); t.Add("single", (IEnumerable <IElementNavigator> f) => f.Single(), doNullProp: true); t.Add("skip", (IEnumerable <IElementNavigator> f, long a) => f.Skip((int)a), doNullProp: true); t.Add("first", (IEnumerable <IElementNavigator> f) => f.First(), doNullProp: true); t.Add("last", (IEnumerable <IElementNavigator> f) => f.Last(), doNullProp: true); t.Add("tail", (IEnumerable <IElementNavigator> f) => f.Tail(), doNullProp: true); t.Add("take", (IEnumerable <IElementNavigator> f, long a) => f.Take((int)a), doNullProp: true); t.Add("builtin.item", (IEnumerable <IElementNavigator> f, long a) => f.Item((int)a), doNullProp: true); t.Add("toInteger", (IElementNavigator f) => f.ToInteger(), doNullProp: true); t.Add("toDecimal", (IElementNavigator f) => f.ToDecimal(), doNullProp: true); t.Add("toString", (IElementNavigator f) => f.ToStringRepresentation(), doNullProp: true); t.Add("substring", (string f, long a) => f.FpSubstring((int)a), doNullProp: true); t.Add("substring", (string f, long a, long b) => f.FpSubstring((int)a, (int)b), doNullProp: true); t.Add("startsWith", (string f, string fragment) => f.StartsWith(fragment), doNullProp: true); t.Add("endsWith", (string f, string fragment) => f.EndsWith(fragment), doNullProp: true); t.Add("matches", (string f, string regex) => Regex.IsMatch(f, regex), doNullProp: true); t.Add("indexOf", (string f, string fragment) => f.FpIndexOf(fragment), doNullProp: true); t.Add("contains", (string f, string fragment) => f.Contains(fragment), doNullProp: true); t.Add("replaceMatches", (string f, string regex, string subst) => Regex.Replace(f, regex, subst), doNullProp: true); t.Add("replace", (string f, string regex, string subst) => f.FpReplace(regex, subst), doNullProp: true); t.Add("length", (string f) => f.Length, doNullProp: true); t.Add("is", (IElementNavigator f, string name) => f.Is(name), doNullProp: true); t.Add("as", (IEnumerable <IElementNavigator> f, string name) => f.FilterType(name), doNullProp: true); t.Add("binary.is", (object f, IElementNavigator left, string name) => left.Is(name), doNullProp: true); t.Add("binary.as", (object f, IElementNavigator left, string name) => left.CastAs(name), doNullProp: true); t.Add("extension", (IEnumerable <IElementNavigator> f, string url) => f.Extension(url), doNullProp: true); // Logic operators do not use null propagation and may do short-cut eval t.AddLogic("binary.and", (a, b) => a.And(b)); t.AddLogic("binary.or", (a, b) => a.Or(b)); t.AddLogic("binary.xor", (a, b) => a.XOr(b)); t.AddLogic("binary.implies", (a, b) => a.Implies(b)); // Special late-bound functions t.Add(new CallSignature("where", typeof(IEnumerable <IElementNavigator>), typeof(object), typeof(Invokee)), runWhere); t.Add(new CallSignature("select", typeof(IEnumerable <IElementNavigator>), typeof(object), typeof(Invokee)), runSelect); t.Add(new CallSignature("all", typeof(bool), typeof(object), typeof(Invokee)), runAll); t.Add(new CallSignature("any", typeof(bool), typeof(object), typeof(Invokee)), runAny); t.Add(new CallSignature("repeat", typeof(IEnumerable <IElementNavigator>), typeof(object), typeof(Invokee)), runRepeat); t.AddVar("sct", "http://snomed.info/sct"); t.AddVar("loinc", "http://loinc.org"); t.AddVar("ucum", "http://unitsofmeasure.org"); t.Add("builtin.coreexturl", (object f, string id) => getCoreExtensionUrl(id)); t.Add("builtin.corevsurl", (object f, string id) => getCoreValueSetUrl(id)); return(t); }
public override Invokee VisitNewNodeListInit(FP.NewNodeListInitExpression expression, SymbolTable scope) { return(InvokeeFactory.Return(ElementNode.EmptyList)); }
public override T Accept <T>(ExpressionVisitor <T> visitor, SymbolTable scope) { return(visitor.VisitFunctionCall(this, scope)); }
public override Invokee VisitVariableRef(FP.VariableRefExpression expression, SymbolTable scope) { // HACK, for now, $this is special, and we handle in run-time, not compile time... if (expression.Name == "builtin.this") { return(InvokeeFactory.GetThis); } // HACK, for now, $this is special, and we handle in run-time, not compile time... if (expression.Name == "builtin.that") { return(InvokeeFactory.GetThat); } // HACK, for now, $index is special, and we handle in run-time, not compile time... if (expression.Name == "builtin.index") { return(InvokeeFactory.GetIndex); } // HACK, for now, %context is special, and we handle in run-time, not compile time... if (expression.Name == "context") { return(InvokeeFactory.GetContext); } // HACK, for now, %resource is special, and we handle in run-time, not compile time... if (expression.Name == "resource") { return(InvokeeFactory.GetResource); } // HACK, for now, %rootResource is special, and we handle in run-time, not compile time... if (expression.Name == "rootResource") { return(InvokeeFactory.GetRootResource); } // Variables are still functions without arguments. For now variables are treated separately here, //Functions are handled elsewhere. return(resolve(scope, expression.Name, Enumerable.Empty <Type>())); }
public override T Accept <T>(ExpressionVisitor <T> visitor, SymbolTable scope) { return(visitor.VisitNewNodeListInit(this, scope)); }
//public void Visit(Expression expression) //{ // if (expression is ConstantExpression) // VisitConstant((ConstantExpression)expression); // else if (expression is FunctionCallExpression) // VisitFunctionCall((FunctionCallExpression)expression); // else if (expression is LambdaExpression) // VisitLambda((LambdaExpression)expression); // else if (expression is NewNodeListInitExpression) // VisitNewNodeListInit((NewNodeListInitExpression)expression); // else if (expression is VariableRefExpression) // VisitVariableRef((VariableRefExpression)expression); //} public abstract T VisitConstant(ConstantExpression expression, SymbolTable scope);
internal static Invokee Get(this SymbolTable table, CallSignature signature) { return(table.Get(signature.Name, signature.ArgumentTypes)); }
public static void Add <R>(this SymbolTable table, string name, Func <R> func) { table.Add(new CallSignature(name, typeof(R)), InvokeeFactory.Wrap(func)); }