// The variable_value_resolver is used only to find the unused variables, the variable values aren't used. // variable_value_resolver can be null, in that case unused variables aren't explored. // cache can be null. public ExpressionCompilerJob(Parser parser, IEvalContext eval_ctx, bool collect_unresolved_variables, CompiledExpressionCache cache) { m_Parser = parser; m_EvalContext = eval_ctx; m_CollectUnresolvedVariables = collect_unresolved_variables; m_Cache = cache; }
public override Value Evaluate(IEvalContext ctx) { string s0 = SubExpressions[0].Evaluate(ctx).ToString(); string s1 = SubExpressions[1].Evaluate(ctx).ToString(); return(new BoolValue(s0.EndsWith(s1, StringComparison.OrdinalIgnoreCase))); }
public override Value Evaluate(IEvalContext ctx) { string s0 = SubExpressions[0].Evaluate(ctx).ToString(); string s1 = SubExpressions[1].Evaluate(ctx).ToString(); int idx = s0.IndexOf(s1, StringComparison.OrdinalIgnoreCase); return(new BoolValue(idx >= 0)); }
protected internal virtual Value RecursiveCollectUnresolvedVariables(IEvalContext ctx) { for (int i = 0; i < SubExpressions.Length; ++i) { SubExpressions[i].RecursiveCollectUnresolvedVariables(ctx); } return(m_CollectUnresolvedVariableDefaultRetVal); }
protected internal override Value RecursiveCollectUnresolvedVariables(IEvalContext ctx) { SubExpressions[0].RecursiveCollectUnresolvedVariables(ctx); SubExpressions[1].RecursiveCollectUnresolvedVariables(ctx); Match m = m_Regex.Match(""); m_LocalContext = new RegexMatchLocalContext(m_Regex.GetGroupNumbers(), m_Regex.GetGroupNames(), m.Groups); return(new BoolValue(!m_InvertResultValue)); }
public List <Variable> CollectUnresolvedVariables(IEvalContext ctx) { Debug.Assert(!(ctx is SafeEvalContext)); Private.UnresolvedVariableCollectorEvalContext uvc_ctx = new Private.UnresolvedVariableCollectorEvalContext(ctx); SafeEvalContext safe_ctx = new SafeEvalContext(uvc_ctx); RecursiveCollectUnresolvedVariables(safe_ctx); return(uvc_ctx.UnresolvedVariables); }
public async override Task <Token> EvalAsync(IEvalContext ctx) { StringBuilder sb = new StringBuilder(); foreach (var expr in this.Expressions) { sb.Append((string)await expr.EvalAsync(ctx)); } return(new StringToken(sb.ToString())); }
public override Value Evaluate(IEvalContext ctx) { Value v = ctx.GetVariableValue(this); if (v != null) { return(v); } throw new ExpressionEvaluatorException(string.Format("Error retrieving the value of variable '{0}' during expression evaluation!", m_Name)); }
public override Value Evaluate(IEvalContext ctx) { Value val0 = SubExpressions[0].Evaluate(ctx); Value val1 = SubExpressions[1].Evaluate(ctx); if (val0.GetType() == Type.String && val1.GetType() == Type.String) { return(new BoolValue(!val0.ToString().Equals(val1.ToString(), StringComparison.OrdinalIgnoreCase))); } return(new BoolValue(val0.ToBool() != val1.ToBool())); }
protected internal override Value RecursiveCollectUnresolvedVariables(IEvalContext ctx) { SubExpressions[0].RecursiveCollectUnresolvedVariables(ctx); SubExpressions[1].RecursiveCollectUnresolvedVariables(ctx); string output = "X"; if (m_VariableName != null) { m_LocalContext = new VariableValueResolver(); m_LocalContext.SetVariable(m_VariableName, output); } return new StringValue(output); }
public async override Task <Token> EvalAsync(IEvalContext ctx) { if (this.Left == this.Right) { return(Token.True); } var leftToken = await this.Left.EvalAsync(ctx); var rightToken = await this.Right.EvalAsync(ctx); return(new BooleanToken(leftToken < rightToken)); }
protected internal override Value RecursiveCollectUnresolvedVariables(IEvalContext ctx) { SubExpressions[0].RecursiveCollectUnresolvedVariables(ctx); SubExpressions[1].RecursiveCollectUnresolvedVariables(ctx); string output = "X"; if (m_VariableName != null) { m_LocalContext = new VariableValueResolver(); m_LocalContext.SetVariable(m_VariableName, output); } return(new StringValue(output)); }
public override Value Evaluate(IEvalContext ctx) { Match match = m_Regex.Match(SubExpressions[0].Evaluate(ctx).ToString()); if (!match.Success) { m_LocalContext = null; return(new BoolValue(m_InvertResultValue)); } m_LocalContext = new RegexMatchLocalContext(m_Regex.GetGroupNumbers(), m_Regex.GetGroupNames(), match.Groups); return(new BoolValue(!m_InvertResultValue)); }
public override Value Evaluate(IEvalContext ctx) { string dir = SubExpressions[0].Evaluate(ctx).ToString(); string path = SubExpressions[1].Evaluate(ctx).ToString(); bool rooted_dir = System.IO.Path.IsPathRooted(dir); bool rooted_path = System.IO.Path.IsPathRooted(path); if (rooted_dir ^ rooted_path) { return(GetErrorReturnValue(path)); } string[] dir_components = dir.Split(PATH_SEPARATORS, StringSplitOptions.RemoveEmptyEntries); string[] path_components = path.Split(PATH_SEPARATORS, StringSplitOptions.RemoveEmptyEntries); int max_cmp_count = Math.Min(dir_components.Length, path_components.Length); int same; for (same = 0; same < max_cmp_count; ++same) { if (dir_components[same].ToLower() != path_components[same].ToLower()) { break; } } if (same == 0 && rooted_dir && !dir.StartsWith("\\") && !dir.StartsWith("/")) { return(GetErrorReturnValue(path)); } StringBuilder sb = new StringBuilder(); for (int i = 0, e = dir_components.Length - same; i < e; ++i) { sb.Append(i > 0 ? "/.." : ".."); } for (int i = same; i < path_components.Length; ++i) { if (sb.Length > 0) { sb.Append('/'); } sb.Append(path_components[i]); } return(new StringValue(sb.ToString())); }
public override Value Evaluate(IEvalContext ctx) { string path = SubExpressions[0].Evaluate(ctx).ToString(); string owner = ""; if (path.Length > 0) { PackageGlobals.InvokeOnUIThread(delegate() { owner = WorkspaceInfoGetter.Instance().GetOwner(path); }); } return(new StringValue(owner)); }
public override Value Evaluate(IEvalContext ctx) { string command = SubExpressions[0].Evaluate(ctx).ToString(); string workdir = SubExpressions[1].Evaluate(ctx).ToString(); string exec_output = m_Evaluator.Evaluate(m_ExecPeriodSecs, command, workdir); if (m_VariableName != null) { m_LocalContext = new VariableValueResolver(); m_LocalContext.SetVariable(m_VariableName, exec_output); } return(new StringValue(exec_output)); }
public override Value Evaluate(IEvalContext ctx) { string command = SubExpressions[0].Evaluate(ctx).ToString(); string workdir = SubExpressions[1].Evaluate(ctx).ToString(); string exec_output = m_Evaluator.Evaluate(m_ExecPeriodSecs, command, workdir); if (m_VariableName != null) { m_LocalContext = new VariableValueResolver(); m_LocalContext.SetVariable(m_VariableName, exec_output); } return new StringValue(exec_output); }
public override async Task <Token> EvalAsync(IEvalContext ctx) { var leftValue = await this.Left.EvalAsync(ctx); if (!leftValue) { return(BooleanToken.False); } var rightValue = await this.Right.EvalAsync(ctx); if (!rightValue) { return(BooleanToken.False); } return(BooleanToken.True); }
private ExpressionLanguageEngine(IEvalContext ctx, IEvalExceptionHandlingPolicy policy, object fallbackValue, ICache <string, ExpressionLanguageAST> cache) { _i = new Interpreter(); if (ctx != null) { _ctx = ctx; } else { _ctx = new EvalContext(); } _ctx.Assign(NULL, null);//Note:null works as keyword _policy = policy; _fallbackValue = fallbackValue; _cache = cache; }
public async override Task <Token> EvalAsync(IEvalContext ctx) { Token value = await ctx.ResolveTargetAsync(this.Target); if (value == null) { return(Token.Empty); } foreach (var member in Members) { value = value[member]; if (value == null) { return(Token.Empty); } } return(value); }
protected internal override Value RecursiveCollectUnresolvedVariables(IEvalContext ctx) { Expression expr_ctx, expr_no_ctx; if (SubExpressions[0].RecursiveCollectUnresolvedVariables(ctx).ToBool()) { expr_ctx = SubExpressions[1]; expr_no_ctx = SubExpressions[2]; } else { expr_ctx = SubExpressions[2]; expr_no_ctx = SubExpressions[1]; } if (expr_ctx != null) { IVariableValueResolver local_ctx = SubExpressions[0].GetLocalContext(); if (local_ctx == null) { expr_ctx.RecursiveCollectUnresolvedVariables(ctx); } else { ctx.PushLocalContext(local_ctx); try { expr_ctx.RecursiveCollectUnresolvedVariables(ctx); } finally { ctx.PopLocalContext(); } } } if (expr_no_ctx != null) { expr_no_ctx.RecursiveCollectUnresolvedVariables(ctx); } return(new BoolValue(false)); }
public async override Task <Token> EvalAsync(IEvalContext ctx) { var strs = this.Expressions; if (strs.Count == 0) { return(Token.Empty); } if (strs.Count == 1) { return(await strs[0].EvalAsync(ctx)); } StringBuilder sb = new StringBuilder(); foreach (var expr in strs) { sb.Append((string)(await expr.EvalAsync(ctx))); } return(new StringToken(sb.ToString())); }
public override Value Evaluate(IEvalContext ctx) { Expression expr = SubExpressions[0].Evaluate(ctx).ToBool() ? SubExpressions[1] : SubExpressions[2]; IVariableValueResolver local_ctx = SubExpressions[0].GetLocalContext(); if (local_ctx == null) { return(expr.Evaluate(ctx)); } else { ctx.PushLocalContext(local_ctx); try { Value res = expr.Evaluate(ctx); return(res); } finally { ctx.PopLocalContext(); } } }
public abstract Task <Token> EvalAsync(IEvalContext ctx);
public abstract Value Evaluate(IEvalContext ctx);
public UnresolvedVariableCollectorEvalContext(IEvalContext ctx) : base(ctx) { }
public EvalVisitor(IEvalContext ctx) { _ctx = ctx; }
public UnitOfWork(IEvalContext context) { _context = context; }
public override Value Evaluate(IEvalContext ctx) { string dir = SubExpressions[0].Evaluate(ctx).ToString(); string path = SubExpressions[1].Evaluate(ctx).ToString(); bool rooted_dir = System.IO.Path.IsPathRooted(dir); bool rooted_path = System.IO.Path.IsPathRooted(path); if (rooted_dir ^ rooted_path) return GetErrorReturnValue(path); string[] dir_components = dir.Split(PATH_SEPARATORS, StringSplitOptions.RemoveEmptyEntries); string[] path_components = path.Split(PATH_SEPARATORS, StringSplitOptions.RemoveEmptyEntries); int max_cmp_count = Math.Min(dir_components.Length, path_components.Length); int same; for (same = 0; same < max_cmp_count; ++same) { if (dir_components[same].ToLower() != path_components[same].ToLower()) break; } if (same == 0 && rooted_dir && !dir.StartsWith("\\") && !dir.StartsWith("/")) return GetErrorReturnValue(path); StringBuilder sb = new StringBuilder(); for (int i=0,e=dir_components.Length-same; i<e; ++i) sb.Append(i > 0 ? "/.." : ".."); for (int i = same; i < path_components.Length; ++i) { if (sb.Length > 0) sb.Append('/'); sb.Append(path_components[i]); } return new StringValue(sb.ToString()); }
public override Value Evaluate(IEvalContext ctx) { return(new StringValue(SubExpressions[0].Evaluate(ctx).ToString() + SubExpressions[1].Evaluate(ctx).ToString())); }
public async override Task <Token> EvalAsync(IEvalContext ctx) { return(new StringToken(this.Value)); }
public override Value Evaluate(IEvalContext ctx) { string path = SubExpressions[0].Evaluate(ctx).ToString(); string owner = ""; if (path.Length > 0) { PackageGlobals.InvokeOnUIThread(delegate() { owner = WorkspaceInfoGetter.Instance().GetOwner(path); }); } return new StringValue(owner); }
public override Value Evaluate(IEvalContext ctx) { return(new BoolValue(SubExpressions[0].Evaluate(ctx).ToBool() ^ SubExpressions[1].Evaluate(ctx).ToBool())); }
public override Value Evaluate(IEvalContext ctx) { return(this); }