Esempio n. 1
0
        // arglist:
        //             expression                     rest_of_arguments
        //             expression "=" expression      rest_of_arguments
        //             expression "for" gen_expr_rest
        //
        private Arg[] FinishArgListOrGenExpr(out List<string> commaWhiteSpace, out bool ateTerminator)
        {
            Arg a = null;
            commaWhiteSpace = MakeWhiteSpaceList();

            Token t = PeekToken();
            if (t.Kind != TokenKind.RightParenthesis && t.Kind != TokenKind.Multiply && t.Kind != TokenKind.Power) {
                Expression e = ParseExpression();
                if (e is ErrorExpression) {
                    ateTerminator = false;
                    return new[] { new Arg(e) };
                }

                if (MaybeEat(TokenKind.Assign)) {               //  Keyword argument
                    a = FinishKeywordArgument(e);
                } else if (PeekToken(Tokens.KeywordForToken)) {    //  Generator expression
                    var genExpr = ParseGeneratorExpression(e);
                    AddIsAltForm(genExpr);
                    a = new Arg(genExpr);
                    ateTerminator = Eat(TokenKind.RightParenthesis);
                    a.SetLoc(e.StartIndex, GetEnd());
                    return new Arg[1] { a };       //  Generator expression is the argument
                } else {
                    a = new Arg(e);
                    a.SetLoc(e.StartIndex, e.EndIndex);
                }

                //  Was this all?
                //
                if (MaybeEat(TokenKind.Comma)) {
                    if (commaWhiteSpace != null) {
                        commaWhiteSpace.Add(_tokenWhiteSpace);
                    }
                } else {
                    ateTerminator = Eat(TokenKind.RightParenthesis);
                    a.SetLoc(e.StartIndex, GetEnd());
                    return new Arg[1] { a };
                }
            }

            return FinishArgumentList(a, commaWhiteSpace, out ateTerminator);   // TODO: Use ateTerminator
        }
Esempio n. 2
0
        private Arg FinishKeywordArgument(Expression t)
        {
            Debug.Assert(_token.Token.Kind == TokenKind.Assign);
            string equalWhiteSpace = _tokenWhiteSpace;
            NameExpression n = t as NameExpression;

            string name;
            if (n == null) {
                ReportSyntaxError(t.StartIndex, t.EndIndex, "expected name");
                name = null;
            } else {
                name = n.Name;
            }

            Expression val = ParseExpression();
            Arg arg = new Arg(t, val);
            arg.SetLoc(t.StartIndex, val.EndIndex);
            if (_verbatim) {
                AddPreceedingWhiteSpace(arg, equalWhiteSpace);
            }

            // we're losing the name expression...
            return arg;
        }