Beispiel #1
0
        /// <summary>
        /// Replaces the variables in the expression with values from <paramref name="scope"/>.
        /// </summary>
        /// <param name="scope">The scope object containing variable values.</param>
        /// <param name="result">[out] The new expression containing the replaced variables.</param>
        /// <returns><c>true</c> if substitution was successful, <c>false</c> if something went wrong, in which case <paramref name="result"/> will likely be a <see cref="ParseErrorExpression"/>.</returns>
        public override bool ReplaceVariables(InterpreterScope scope, out ExpressionBase result)
        {
            // user-defined functions should be evaluated (expanded) immediately.
            if (!Evaluate(scope, out result))
            {
                return(false);
            }

            if (result == null)
            {
                var functionCall = scope.GetContext <FunctionCallExpression>();
                if (functionCall != null)
                {
                    result = new ParseErrorExpression(Name.Name + " did not return a value", functionCall.FunctionName);
                }
                else
                {
                    result = new ParseErrorExpression(Name.Name + " did not return a value");
                }

                return(false);
            }

            return(true);
        }
Beispiel #2
0
        private ExpressionBase LocateParameter(InterpreterScope scope, string name)
        {
            var functionCall = scope.GetContext <FunctionCallExpression>();

            if (functionCall != null)
            {
                var nameEnumerator  = Parameters.GetEnumerator();
                var valueEnumerator = functionCall.Parameters.GetEnumerator();
                while (nameEnumerator.MoveNext() && valueEnumerator.MoveNext())
                {
                    if (nameEnumerator.Current.Name == name)
                    {
                        return(valueEnumerator.Current);
                    }
                }
            }

            return(null);
        }