Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        /// <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()}");
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public IMoValue Get(MoPath key, MoParams parameters)
        {
            if (Functions.TryGetValue(key.Value, out var func))
            {
                return(MoValue.FromObject(func(parameters)));
            }

            return(DoubleValue.Zero);
        }
Exemplo n.º 5
0
 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);
     }
 }
Exemplo n.º 6
0
        /// <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)));
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        /// <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);
                }
            }
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        /// <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;
            }
        }
Exemplo n.º 11
0
 /// <inheritdoc />
 public void Set(MoPath key, IMoValue value)
 {
     throw new NotSupportedException("Cannot set a value in a query struct.");
 }
Exemplo n.º 12
0
 public IMoValue GetValue(MoPath name)
 {
     return(GetValue(name, MoParams.Empty));
 }
Exemplo n.º 13
0
 public FuncCallExpression(MoPath name, IExpression[] args) : base(args)
 {
     Name = name;
 }
Exemplo n.º 14
0
 public NameExpression(MoPath path)
 {
     Name = path;
 }
Exemplo n.º 15
0
 /// <inheritdoc />
 public NameExpression(string value)
 {
     Name = new MoPath(value);
 }
Exemplo n.º 16
0
		internal MoPath(MoPath root,string path, string value)
		{
			Root = root;
			Path = path;
			Value = value;
		}
Exemplo n.º 17
0
 /// <inheritdoc />
 public override void Set(MoPath key, IMoValue value)
 {
     throw new NotSupportedException("Read-only context");
 }