public virtual ValueReference Evaluate(EvaluationContext ctx, string exp, object expectedType) { foreach (ValueReference var in ctx.Adapter.GetLocalVariables(ctx)) { if (var.Name == exp) { return(var); } } foreach (ValueReference var in ctx.Adapter.GetParameters(ctx)) { if (var.Name == exp) { return(var); } } ValueReference thisVar = ctx.Adapter.GetThisReference(ctx); if (thisVar != null) { if (thisVar.Name == exp) { return(thisVar); } foreach (ValueReference cv in thisVar.GetChildReferences(ctx.Options)) { if (cv.Name == exp) { return(cv); } } } throw new EvaluatorException("Invalid Expression: '{0}'", exp); }
public virtual CompletionData GetExpressionCompletionData(EvaluationContext ctx, string exp) { int i; if (exp.Length == 0) { return(null); } if (exp [exp.Length - 1] == '.') { exp = exp.Substring(0, exp.Length - 1); i = 0; while (i < exp.Length) { ValueReference vr = null; try { vr = ctx.Evaluator.Evaluate(ctx, exp.Substring(i), null); if (vr != null) { CompletionData data = new CompletionData(); foreach (ValueReference cv in vr.GetChildReferences(ctx.Options)) { data.Items.Add(new CompletionItem(cv.Name, cv.Flags)); } data.ExpressionLenght = 0; return(data); } } catch (Exception ex) { Console.WriteLine(ex); } i++; } return(null); } i = exp.Length - 1; bool lastWastLetter = false; while (i >= 0) { char c = exp [i--]; if (!char.IsLetterOrDigit(c) && c != '_') { break; } lastWastLetter = !char.IsDigit(c); } if (lastWastLetter) { string partialWord = exp.Substring(i + 1); CompletionData data = new CompletionData(); data.ExpressionLenght = partialWord.Length; // Local variables foreach (ValueReference vc in GetLocalVariables(ctx)) { if (vc.Name.StartsWith(partialWord)) { data.Items.Add(new CompletionItem(vc.Name, vc.Flags)); } } // Parameters foreach (ValueReference vc in GetParameters(ctx)) { if (vc.Name.StartsWith(partialWord)) { data.Items.Add(new CompletionItem(vc.Name, vc.Flags)); } } // Members ValueReference thisobj = GetThisReference(ctx); if (thisobj != null) { data.Items.Add(new CompletionItem("this", ObjectValueFlags.Field | ObjectValueFlags.ReadOnly)); } object type = GetEnclosingType(ctx); foreach (ValueReference vc in GetMembers(ctx, null, type, thisobj != null ? thisobj.Value : null)) { if (vc.Name.StartsWith(partialWord)) { data.Items.Add(new CompletionItem(vc.Name, vc.Flags)); } } if (data.Items.Count > 0) { return(data); } } return(null); }
protected virtual CompletionData GetMemberCompletionData(EvaluationContext ctx, ValueReference vr) { var data = new CompletionData (); foreach (ValueReference cv in vr.GetChildReferences (ctx.Options)) data.Items.Add (new CompletionItem (cv.Name, cv.Flags)); data.ExpressionLength = 0; return data; }