public override object Execute(RTExecutionContext context) { IRTEntry[] source = (new RTVariable(RTSysSymbols.MERGE_INPUT)).Execute(context) as IRTEntry[]; string srcText = (new RTVariable(RTSysSymbols.SOURCE_TEXT)).Execute(context) as string; IList<string> unmatched = ExtractUnmatched(srcText, source); string[] processed = source.Select(x => x.Result).ToArray(); Debug.Assert(unmatched.Count >= processed.Length); StringBuilder sb = new StringBuilder(); int j = 0; for (int i = 0; i < unmatched.Count; i++) { if (unmatched[i] != null) { sb.Append(unmatched[i]); } else { if (j < processed.Length) { sb.Append(processed[j++]); } } } return sb.ToString(); }
public override object Execute(RTExecutionContext context) { var ctx = context as RTTemplateContext; if (ctx == null) return _value; if (replaceExpression == null) { replaceExpression = new ReplaceExpression(); } return replaceExpression.Execute(_value, ctx.RTMatch, ctx.RTMatchCount); }
public override object Execute(RTExecutionContext context) { StringBuilder sb = new StringBuilder(); foreach (var expr in _items) { var retval = expr.Execute(context); if (!context.HasError) { sb.Append(retval); //literal and function list return string } } if (!context.HasError) return sb.ToString(); else return null; }
public override object Execute(RTExecutionContext context) { StringBuilder sb = new StringBuilder(); context.PushScope(new RTScope(null)); foreach (var func in _items) { var result = func.Execute(context); if (!context.HasError && result != null && !(result is RTVoid)) { sb.Append(result); } } context.PopScope(); if (!context.HasError) return sb.ToString(); else return null; }
public override object Execute(RTExecutionContext context) { RTScope scope = context.CurrentScope; int previousErrorCount = context.Errors.Count; var evaledArgs = new List<object>(); bool allArgsResolved = EvaluateArgs(context, evaledArgs); //check if (evaledArgs.Count < this.MinArgNumber) { context.Errors.Add(new RTExecutionError(scope, RTErrorCode.Metadata_Not_Enough_Args, string.Format(ErrorMessages.Metadata_Not_Enough_Args, this.MinArgNumber, evaledArgs.Count))); } if (evaledArgs.Count > this.MaxArgNumber) { context.Errors.Add(new RTExecutionError(scope, RTErrorCode.Metadata_Too_Many_Args, string.Format(ErrorMessages.Metadata_Too_Many_Args, this.MaxArgNumber, evaledArgs.Count))); } if (context.Errors.Count > previousErrorCount) { return RTVoid.Singleton; } if (allArgsResolved) { return ExecuteList(evaledArgs); } else { if (!this.HandlesScope) { int i = -1; while (!(evaledArgs[++i] is RTScope)) ; //find the first unresolved scope context.Errors.Add(new RTExecutionError(scope, RTErrorCode.Metadata_Invalid_Arg, string.Format(ErrorMessages.Metadata_Invalid_Arg_Func, i, scope.FunctionName))); return RTVoid.Singleton; } else { for (int i = 0; i < evaledArgs.Count; i++) { scope.AddArg(evaledArgs[i]); } return scope; } } }
/// <summary> /// Resolve the value of this variable, which can be this variable itself, another variable, data value or void. /// </summary> /// <param name="context"></param> /// <returns></returns> public object Execute(RTExecutionContext context) { if (context.CurrentScope == null) return this; var variable = this; object val; while (true) { val = context.CurrentScope.GetValue(variable.Name); if (val is RTVoid) return variable; variable = val as RTVariable; if (variable == null) break; else if (variable.Name == this.Name) { return this; } } return val; }
protected virtual bool EvaluateArgs(RTExecutionContext context, IList<object> evaledArgs) { RTScope func = context.CurrentScope; bool allArgsResolved = true; for (int i = 0; i < func.ArgCount; i++) { var evaled = EvaluateArg(i, context); RTScope evaledScope = evaled as RTScope; if (evaled is RTVoid) continue; if (evaled is RTScope || evaled is RTVariable) { allArgsResolved = false; } if (!this.HandlesList && !(evaled is string) && evaled is IEnumerable) { context.Errors.Add(new RTExecutionError(func, RTErrorCode.Metadata_Invalid_Arg, string.Format(ErrorMessages.Metadata_Invalid_Arg_List, i, func.FunctionName))); } evaledArgs.Add(evaled); } return allArgsResolved; }
public abstract object Execute(RTExecutionContext context);
/// <summary> /// Evaluate the ith arg in the function. /// </summary> /// <param name="func"></param> /// <param name="i"></param> /// <param name="context"></param> /// <returns></returns> protected virtual object EvaluateArg(int i, RTExecutionContext context) { var scope = context.CurrentScope; object arg = scope.GetArg(i); object evaled; var expr = arg as IRTExpression; if (expr != null) { evaled = expr.Execute(context); } else { evaled = arg; } RTScope evaledScope = evaled as RTScope; if (arg is RTVariable && evaledScope != null) { evaled = evaledScope.Execute(context); //try to reduct scope referenced by var } return evaled; }
public object Execute(RTExecutionContext context) { if (Creator == null) throw new InvalidOperationException(ErrorMessages.Scope_Execute_Error); RTScope exeScope = _executed ? Duplicate() : this; context.PushScope(exeScope); var retval = Creator.Metadata.Execute(context); context.PopScope(); exeScope._executed = true; return retval; }
public override object Execute(RTExecutionContext context) { var scope = new RTScope(this); var retval = scope.Execute(context); if (!Metadata.HasReturnValue) { retval = RTVoid.Singleton; } return retval; }