コード例 #1
0
        /// <summary>
        ///  Finds the first scoped variable matching the name, using Rule as the current rule to work backwards from
        /// </summary>
        public Rule FindVariable(string name, Node rule)
        {
            var previousNode = rule;

            foreach (var frame in Frames)
            {
                var v = frame.Variable(name, null);
                if (v)
                {
                    return(v);
                }
                previousNode = frame;
            }

            Rule result = null;

            if (Parent != null)
            {
                result = Parent.FindVariable(name, rule);
            }

            if (result != null)
            {
                return(result);
            }

            if (ClosureEnvironment != null)
            {
                return(ClosureEnvironment.FindVariable(name, rule));
            }

            return(null);
        }