コード例 #1
0
        public RCValue Get(RCArray <string> name, RCArray <RCBlock> @this)
        {
            RCRefable block = this;
            RCValue   value = null;

            for (int i = 0; i < name.Count; ++i)
            {
                value = block.Get(name[i]);
                block = value as RCRefable;
                if (block == null)
                {
                    // if it is the last value return it
                    if (i == name.Count - 1)
                    {
                        return(value);
                    }
                    // if not, something is wrong
                    else
                    {
                        return(null);
                    }
                }
                if (@this != null && i < name.Count - 1)
                {
                    @this.Write((RCBlock)block);
                }
            }
            return(value);
        }
コード例 #2
0
        /// <summary>
        /// Find and return the value referenced by name. Return null if not found.
        /// </summary>
        public static RCValue Resolve(RCBlock context,
                                      RCClosure closure,
                                      RCArray <string> name,
                                      RCArray <RCBlock> @this,
                                      bool returnNull)
        {
            if (context != null)
            {
                RCValue result = context.Get(name, @this);
                if (result != null)
                {
                    return(result);
                }
            }
            RCClosure parent = closure;
            RCValue   val    = null;

            while (parent != null)
            {
                RCRefable result = parent.Result;
                if (result != null && !parent.NoResolve)
                {
                    val = result.Get(name, @this);
                }
                if (val != null)
                {
                    break;
                }
                if (!parent.NoClimb)
                {
                    parent = parent.Parent;
                }
                else
                {
                    break;
                }
            }
            if (val == null && !returnNull)
            {
                // Delimit thing is annoying.
                throw new RCException(closure,
                                      RCErrors.Name,
                                      "Unable to resolve name " + RCReference.Delimit(name, "."));
            }
            return(val);
        }
コード例 #3
0
        public RCValue Get(string[] name, RCArray <RCBlock> @this)
        {
            RCRefable block = this;
            RCValue   value = null;

            for (int i = 0; i < name.Length; ++i)
            {
                value = block.Get(name[i]);
                block = value as RCRefable;
                if (block == null)
                {
                    return(value);
                }
                else if (@this != null)
                {
                    @this.Write((RCBlock)block);
                }
            }
            return(value);
        }
コード例 #4
0
        public RCValue Get(RCSymbolScalar name, RCArray <RCBlock> @this)
        {
            RCRefable block = this;
            RCValue   value = null;

            object[] array = name.ToArray();
            for (int i = 0; i < array.Length; ++i)
            {
                if (array[i] is long)
                {
                    long index = (long)array[i];
                    value = block.Get(index);
                }
                else if (array[i] is string)
                {
                    value = block.Get((string)array[i]);
                }
                block = value as RCRefable;
                if (block == null)
                {
                    // if it is the last value return it
                    if (i == name.Length - 1)
                    {
                        return(value);
                    }
                    // if not, something is wrong
                    else
                    {
                        return(null);
                    }
                }
                if (@this != null && i < array.Length - 1)
                {
                    @this.Write((RCBlock)block);
                }
            }
            return(value);
        }