public bool Evaluate(string block, ScriptContext context) { var replacer = context.Get<IVariableReplacer>(); var scriptLog = context.Get<IScriptLog>(); var replaced = replacer.Replace(block, context); // replace single equals with double equals replaced = Regex.Replace(replaced, "([^=:<>])=(?!=)", "$1=="); if(context.DebugLevel > 0) { scriptLog.Log(context.Name, "if {0}".ToFormat(replaced), context.LineNumber); } try { var interpreter = new Interpreter(); var result = (bool)interpreter.Eval(replaced); if(context.DebugLevel > 0) { scriptLog.Log(context.Name, "if result {0}".ToFormat(result.ToString().ToLower()), context.LineNumber); } return result; } catch(Exception exc) { scriptLog.Log(context.Name, "if result {0}".ToFormat(exc), context.LineNumber); return false; } }
public ReplacerBlueprint(Interpreter interpreter, Regex regex, IEnumerable<Token<TokenType>> evaluator) : base(interpreter) { _evaluator = evaluator; _regex = regex; _inputCollected = false; _input = null; _matches = null; }
public override string RenderTag(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex) { Match lineMatch = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]); String condition = lineMatch.Groups["condition"].Value; var interpreter = new Interpreter(); foreach (var element in parameters) { interpreter.SetVariable(element.Key, element.Value, element.Value.GetType()); } var result = interpreter.Eval<bool>(condition); if (result) return renderer.RenderBlock(reader.ReadBlock()); reader.ReadBlock(); return ""; }
public void SelectTo(object obj, string expr, JsonPathResultAccumulator output) { if (obj == null) throw new ArgumentNullException("obj"); if (output == null) throw new ArgumentNullException("output"); Interpreter i = new Interpreter(output, ValueSystem, ScriptEvaluator); expr = Normalize(expr); if (expr.Length >= 1 && expr[0] == '$') // ^\$:? expr = expr.Substring(expr.Length >= 2 && expr[1] == ';' ? 2 : 1); i.Trace(expr, obj, "$"); }
public string callMixin(string line, TemplateReader reader, Dictionary<string, object> parameters, int patternIndex) { Match m = Regex.Match(line.Trim(), RegularExpressionPatterns[patternIndex]); List<object> mixinParams = new List<object>(); String mixinName = m.Groups["name"].Value; Mixin mixin = mixins[mixinName]; var interpreter = new Interpreter(); Dictionary<string, object> outerParameters = new Dictionary<string, object>(); foreach (var element in parameters) { interpreter.SetVariable(element.Key, element.Value, element.Value.GetType()); } foreach (Capture cap in m.Groups["param"].Captures) { var result = interpreter.Eval(cap.Value); mixinParams.Add(result); } if (mixinParams.Count != mixin.parameters.Count) throw new TemplateException("Missmatch number of mixin arguments"); for (int i = 0; i < mixinParams.Count; i++) { if (parameters.ContainsKey(mixin.parameters[i])) { outerParameters.Add(mixin.parameters[i], parameters[mixin.parameters[i]]); parameters[mixin.parameters[i]] = mixinParams[i]; } else { parameters.Add(mixin.parameters[i], mixinParams[i]); } } String blockRendered = renderer.RenderBlock(mixin.block); foreach(var n in mixin.parameters) { parameters.Remove(n); } foreach(var p in outerParameters) { parameters.Add(p.Key, p.Value); } return blockRendered; }
public RegexDateTimePattern(string re, Interpreter inter) { this.regEx = new Regex(re); this.inter = inter; }