/// <inheritdoc /> public IMoValue Get(MoPath key, MoParams parameters) { if (key.HasChildren) { string main = key.Value; if (!string.IsNullOrWhiteSpace(main)) { ExecuteGet(key, main, parameters, out var value); if (value is IMoStruct moStruct) { return(moStruct.Get(key.Next, parameters)); } return(value); } } if (!ExecuteGet(key, key.Value, parameters, out var returnValue)) { Debug.WriteLine($"({_instance.ToString()}) Unknown query: {key}"); } return(returnValue); }
internal MoPath FixNameShortcut(MoPath name) { var first = name.Value; switch (first) { case "q": first = "query"; break; case "v": first = "variable"; break; case "t": first = "temp"; break; case "c": first = "context"; break; } name.SetValue(first); return(name); // String.Join(".", splits); }
/// <inheritdoc /> public IMoValue Get(MoPath key, MoParams parameters) { if (int.TryParse(key.Value, out int index)) { return(this[index]); } throw new MoLangRuntimeException($"Invalid path for array access: {key.Path.ToString()}"); }
/// <inheritdoc /> public IMoValue Get(MoPath key, MoParams parameters) { if (Functions.TryGetValue(key.Value, out var func)) { return(MoValue.FromObject(func(parameters))); } return(DoubleValue.Zero); }
public IMoValue GetValue(MoPath name, MoParams param) { try { return(Structs[name.Value].Get(name.Next, param)); } catch (Exception ex) { throw new MoLangRuntimeException($"Cannot retrieve struct: {name}", ex); } }
/// <inheritdoc /> public override IMoValue Evaluate(MoScope scope, MoLangEnvironment environment) { //List<IExpression> p = Args.ToList(); MoPath name = Name; /* Name is NameExpression expression ? expression.Name : * new MoPath(Name.Evaluate(scope, environment).ToString());*/ IMoValue[] arguments = new IMoValue[Parameters.Length]; for (int i = 0; i < arguments.Length; i++) { arguments[i] = Parameters[i].Evaluate(scope, environment); } return(environment.GetValue(name, new MoParams(arguments))); }
public void SetValue(MoPath name, IMoValue value) { if (!Structs.TryGetValue(name.Value, out var v)) { throw new MoLangRuntimeException($"Invalid path: {name.Path}", null); } try { v.Set(name.Next, value); } catch (Exception ex) { throw new MoLangRuntimeException($"Cannot set value on struct: {name}", ex); } }
/// <inheritdoc /> public void Set(MoPath key, IMoValue value) { if (!key.HasChildren) { if (_propertyCache.Properties.TryGetValue(key.Value, out var accessor)) { if (!accessor.CanWrite) { throw new MoLangRuntimeException("Cannot write to ReadOnly property!", null); } accessor.Set(_instance, value); return; } throw new MoLangRuntimeException($"Variable was not a struct: {key}", null); } string main = key.Value; if (!string.IsNullOrWhiteSpace(main)) { if (!_propertyCache.Properties.TryGetValue(main, out var accessor)) { throw new MoLangRuntimeException($"Could not access property: {key}", null); } var container = accessor.Get(_instance); if (container is IMoStruct moStruct) { moStruct.Set(key.Next, value); } else { throw new MoLangRuntimeException($"Variable was not a struct: {key}", null); } } }
private bool ExecuteGet(MoPath property, string main, MoParams parameters, out IMoValue returnValue) { if (_propertyCache.Properties.TryGetValue(main, out var accessor)) { if (!accessor.CanRead) { throw new MoLangRuntimeException($"Cannot read from property '{property.ToString()}'", null); } returnValue = accessor.Get(_instance); return(true); } if (_propertyCache.Functions.TryGetValue(main, out var f)) { returnValue = f.Invoke(_instance, parameters); return(true); } returnValue = DoubleValue.Zero; return(false); }
/// <inheritdoc /> public override void Assign(MoScope scope, MoLangEnvironment environment, IMoValue value) { var index = (int)Index.Evaluate(scope, environment).AsDouble(); MoPath path; if (Array is NameExpression nameExpression) { var p = nameExpression.Name; path = p; } else { var eval = Array.Evaluate(scope, environment); path = new MoPath($"{eval.AsString()}"); } var array = environment.GetValue(path); if (array is ArrayStruct asArray) { asArray[index] = value; } }
/// <inheritdoc /> public void Set(MoPath key, IMoValue value) { throw new NotSupportedException("Cannot set a value in a query struct."); }
public IMoValue GetValue(MoPath name) { return(GetValue(name, MoParams.Empty)); }
public FuncCallExpression(MoPath name, IExpression[] args) : base(args) { Name = name; }
public NameExpression(MoPath path) { Name = path; }
/// <inheritdoc /> public NameExpression(string value) { Name = new MoPath(value); }
internal MoPath(MoPath root,string path, string value) { Root = root; Path = path; Value = value; }
/// <inheritdoc /> public override void Set(MoPath key, IMoValue value) { throw new NotSupportedException("Read-only context"); }