Beispiel #1
0
 /// <summary>
 /// Execute the continue.
 /// </summary>
 public object VisitFunctionDeclare(FunctionDeclareExpr expr)
 {
     return LObjects.Null;
 }
Beispiel #2
0
        public Expr OnParseFunctionDeclare()
        {
            var tokenIt = this._parser.TokenIt;
            var initiatorToken = tokenIt.NextToken;
            var expr = new FunctionDeclareExpr();
            // <codeFunctionDeclare>

            var token = tokenIt.NextToken;
            var expectToken = true;
            expr.Function = new FunctionExpr();
            expr.Function.Meta = new FunctionMetaData();
            _parser.SetupContext(expr.Function, token);

            if (expectToken) tokenIt.Expect(token.Token);
            else tokenIt.Advance();

            // Function name.
            var name = tokenIt.ExpectId(true, true);
            var aliases = new List<string>();
            var nextToken = tokenIt.NextToken;
            List<string> argNames = null;

            // Option 1: Wild card
            if (nextToken.Token == Tokens.Multiply)
            {
                expr.Function.Meta.HasWildCard = true;
                nextToken = tokenIt.Advance();
            }
            // Option 2: Aliases
            else if (nextToken.Token == Tokens.Comma)
            {
                // Collect all function aliases
                while (nextToken.Token == Tokens.Comma)
                {
                    tokenIt.Advance();
                    var alias = tokenIt.ExpectId(true, true);
                    aliases.Add(alias);
                    nextToken = tokenIt.NextToken;
                }
                if (aliases.Count > 0)
                    expr.Function.Meta.Aliases = aliases;
            }

            // Get the parameters.
            if (nextToken.Token == Tokens.LeftParenthesis)
            {
                tokenIt.Expect(Tokens.LeftParenthesis);
                argNames = _parser.ParseNames();
                tokenIt.Expect(Tokens.RightParenthesis);
            }
            expr.Function.Meta.Init(name, argNames);

            // Now parser the function block.
            OnParseFunctionDeclareBlock(expr.Function);

            // </codeFunctionDeclare>
            this._parser.SetupContext(expr, initiatorToken);
            return expr;
        }