Example #1
0
 private void OnUnknownVariable(UnknownIdentifierEventArgs e)
 {
     if (this.UnknownVariable != null)
     {
         this.UnknownVariable(this, e);
     }
 }
Example #2
0
        private String EvalVar(String exp)
        {
            // Is the variable registered?
            if (this.Variables.ContainsKey(exp.ToLower()))
            {
                // Return variable value
                return(this.Variables[exp.ToLower()]);
            }

            var e = new UnknownIdentifierEventArgs
            {
                ErrorBehaviour = ErrorBehaviour.Throw,
                Identifier     = exp.ToLower(),
                Replacement    = ""
            };

            // Raise UnknownVariable event
            this.OnUnknownVariable(e);

            switch (e.ErrorBehaviour)
            {
            case ErrorBehaviour.Ignore:
                return("");

            case ErrorBehaviour.Replace:
                return(e.Replacement);

            case ErrorBehaviour.Throw:
            default:
                throw new UnknownIdentifierException(
                          String.Format("The statement '{0}' is not a registered variable!", exp));
            }
        }
Example #3
0
 private void OnUnknownFunction(UnknownIdentifierEventArgs e)
 {
     if (this.UnknownFunction != null)
     {
         this.UnknownFunction(this, e);
     }
 }
Example #4
0
        private String EvalFunc(String exp)
        {
            // Evaluate statement, enable quoting (can contain other statements)
            exp = this.Eval(exp, true);

            Match match = this.m_FuncRegex.Match(exp);

            // Is this a valid function call?
            if (match.Success)
            {
                // Get the name of the Function
                string name = match.Groups["Name"].Value;

                // Is the function registered?
                if (this.Functions.ContainsKey(name))
                {
                    // Compute function arguments
                    var args = new List <String>();

                    foreach (Capture cap in match.Groups["Parameter"].Captures)
                    {
                        args.Add(cap.Value);
                    }

                    // Call the function and return the value
                    return(this.Functions[name](args.ToArray()));
                }
                else
                {
                    var e = new UnknownIdentifierEventArgs
                    {
                        ErrorBehaviour = ErrorBehaviour.Throw,
                        Identifier     = name,
                        Replacement    = ""
                    };

                    // Raise UnknownFunction event
                    this.OnUnknownFunction(e);

                    switch (e.ErrorBehaviour)
                    {
                    case ErrorBehaviour.Ignore:
                        return("");

                    case ErrorBehaviour.Replace:
                        return(e.Replacement);

                    case ErrorBehaviour.Throw:
                    default:
                        throw new UnknownIdentifierException(
                                  String.Format("The function '{0}' is not a registered function!", name));
                    }
                }
            }

            throw new InvalidStatementException(String.Format("The statement '{0}' is not a valid function call!", exp));
        }