示例#1
0
        /// <summary>
        /// puts ((1..20).to_a)    (ok)
        /// puts (1..20).to_a      (error)
        /// </summary>
        /// <returns></returns>
        private ArgsNode ParseExpressionListAsArgs()
        {
            ArgsNode parameters = new ArgsNode();

            bool inparentheses = TryParseToken(TokenType.Separator, "(");

            for (AstNode expression = ParseExpression();
                 expression != null;
                 expression = ParseExpression())
            {
                parameters.Push(expression);
                if (!TryParseToken(TokenType.Separator, ","))
                {
                    break;
                }
            }

            if (inparentheses)
            {
                ParseToken(TokenType.Separator, ")");

                if (TryParseName(DO))
                {
                    parameters.Push(ParseBlockExpression());
                }
                else if (TryParseToken(TokenType.Separator, "{"))
                {
                    parameters.Push(ParseBlockExpression(true));
                }
            }

            return(parameters);
        }
示例#2
0
        private ArgsNode ParseParameterList(bool canhaveparens = true)
        {
            Token    token      = null;
            ArgsNode parameters = new ArgsNode();

            bool inparentheses = false;

            if (canhaveparens)
            {
                inparentheses = TryParseToken(TokenType.Separator, "(");
            }

            for (string name = TryParseName(out token); name != null; name = ParseName(out token))
            {
                if (name.StartsWith("&"))
                {
                    parameters.block = NODE_LINENO(new SymNode(name), token);
                }
                else
                {
                    parameters.Push(NODE_LINENO(new SymNode(name), token));
                }

                if (!TryParseToken(TokenType.Separator, ","))
                {
                    break;
                }
            }

            if (inparentheses)
            {
                ParseToken(TokenType.Separator, ")");
            }

            return(parameters);
        }