Inheritance: ICommand
Exemplo n.º 1
0
        private ICommand ParseSimpleCommand()
        {
            if (this.TryParse(TokenType.Name, "var"))
            {
                this.lexer.NextToken();
                return this.ParseVarCommand();
            }

            IExpression expression = this.ParseExpression();

            if (expression == null)
                return null;

            if (this.TryParse(TokenType.Operator, "="))
            {
                this.lexer.NextToken();

                ICommand command = null;

                if (expression is ArrayExpression)
                {
                    ArrayExpression aexpr = (ArrayExpression)expression;
                    command = new SetArrayCommand(aexpr.Expression, aexpr.Arguments, this.ParseExpression());
                }
                else
                {
                    if (expression is VariableExpression)
                        IsValidName(((VariableExpression)expression).Name);

                    command = new SetCommand(expression, this.ParseExpression());
                }

                return command;
            }

            // TODO Review trick to suppor function name(pars) {} without ending ;
            if (expression is FunctionExpression && ((FunctionExpression)expression).Name != null)
                this.lexer.PushToken(tokenSemiColon);

            return new ExpressionCommand(expression);
        }