private static AffectableEntityInfoContainer GetContainer(Type type) { AffectableEntityInfoContainer container; if (!Cache.TryGetValue(type, out container)) { var cache = new AffectableEntityInfoCache(type); container = new AffectableEntityInfoContainer(cache); Cache[type] = container; } return(container); }
private static Parser <ExpressionResult> FunctionTerm(AffectableEntityInfoContainer container) { return(from name in FunctionName from lparen in Parse.Char('(') from args in ArgumentsTerm(name, container) from rparen in Parse.Char(')') select new ExpressionResult { FunctionName = name, TargetPropertyInfo = args.Item1, Condition = args.Item2, Value = args.Item3 }); }
private static Parser <Tuple <PropertyInfo, Expression, Expression> > ArgumentsTerm(string functionName, AffectableEntityInfoContainer container) { AffectableEntityInfo info; if (!container.EntityInfoCache.TryGetAffectableEntityInfo(functionName, out info)) { throw new ArgumentException(string.Format("Function name {0} is not found in entityInfoCache.", functionName)); } var parameter = container.ParameterCache.Get(functionName); var prop = new ValuePropertyContainer(info, functionName, parameter); Func <int, Parser <Expression> > argsExpr = i => (from separator in Comma from item in CallKeyTerm(info, parameter.Item1, i).Parser select item); return((from keys in (from firstKey in CallKeyTerm(info, parameter.Item1, 0).Parser.Once() from tailKey in KeyTermMany(argsExpr, 1) select firstKey.Concat(tailKey)) from comma in Comma from v in ValueTerm(prop).Parser.Once() select Tuple.Create(info.PropertyInfo, Join(keys.ToArray()), v.First())).Or(ValueOnlyArgumentTerm(prop))); }
private static ParserWithContainer <ExpressionResultSet, AffectableEntityInfoContainer> Lambda(AffectableEntityInfoContainer container) { return(new ParserWithContainer <ExpressionResultSet, AffectableEntityInfoContainer>(Expr(container).End(), container)); }
private static Parser <ExpressionResultSet> Expr(AffectableEntityInfoContainer container) { return(from f in FunctionTerm(container).DelimitedBy(Comma) select ToResult(f, container.ParameterCache)); }
public static ExpressionResultSet ParseExpression(string script, AffectableEntityInfoContainer container) { return(Lambda(container).Parser.Parse(script)); }