Esempio n. 1
0
 public override bool Walk(SublistParameter node)
 {
     node.AddVariable(_binder._globalScope, _binder._bindRefs, _binder.DefineParameter(node.Name));
     // we walk the node by hand to avoid walking the default values.
     WalkTuple(node.Tuple);
     return(false);
 }
Esempio n. 2
0
        public override bool Walk(SublistParameter node)
        {
#if NAME_BINDING
            node.PythonVariable =
#endif
            _binder.DefineParameter(node.Name);
            node.Parent = _binder._currentScope;
            // we walk the node by hand to avoid walking the default values.
            WalkTuple(node.Tuple);
            return(false);
        }
Esempio n. 3
0
        //  parameter ::=
        //      identifier | "(" sublist ")"
        private Parameter ParseParameter(int position, HashSet<string> names, ParameterKind kind, bool isTyped = false) {
            Name name;
            Parameter parameter;

            if (PeekToken().Kind == TokenKind.LeftParenthesis) {
                // sublist
                string parenWhiteSpace = _lookaheadWhiteSpace;

                NextToken();
                var parenStart = GetStart();
                Expression ret = ParseSublist(names, true);

                if (_langVersion.Is3x()) {
                    ReportSyntaxError(parenStart, GetEnd(), "sublist parameters are not supported in 3.x");
                }

                bool ateRightParen = Eat(TokenKind.RightParenthesis);
                string closeParenWhiteSpace = _tokenWhiteSpace;

                TupleExpression tret = ret as TupleExpression;
                NameExpression nameRet;

                if (tret != null) {
                    parameter = new SublistParameter(position, tret);
                    if (_verbatim) {
                        AddPreceedingWhiteSpace(tret, parenWhiteSpace);
                        AddSecondPreceedingWhiteSpace(tret, closeParenWhiteSpace);
                        if (!ateRightParen) {
                            AddErrorMissingCloseGrouping(parameter);
                        }
                    }
                } else if ((nameRet = ret as NameExpression) != null) {
                    parameter = new Parameter(nameRet.Name, kind);
                    if (_verbatim) {
                        AddThirdPreceedingWhiteSpace(parameter, (string)_attributes[nameRet][NodeAttributes.PreceedingWhiteSpace]);
                        AddIsAltForm(parameter);
                        if (!ateRightParen) {
                            AddErrorMissingCloseGrouping(parameter);
                        }
                    }
                } else {
                    Debug.Assert(ret is ErrorExpression);
                    ReportSyntaxError(_lookahead);

                    parameter = new ErrorParameter((ErrorExpression)ret);
                    AddIsAltForm(parameter);
                }

                if (parameter != null) {
                    parameter.SetLoc(ret.IndexSpan);
                }
                if (_verbatim) {
                    AddPreceedingWhiteSpace(parameter, parenWhiteSpace);
                    AddSecondPreceedingWhiteSpace(parameter, closeParenWhiteSpace);
                    if (!ateRightParen) {
                        AddErrorMissingCloseGrouping(parameter);
                    }
                }
            } else if ((name = TokenToName(PeekToken())).HasName) {
                NextToken();
                var paramStart = GetStart();
                parameter = new Parameter(name.RealName, kind);
                if (_verbatim) {
                    AddPreceedingWhiteSpace(parameter, _tokenWhiteSpace);
                    AddVerbatimName(name, parameter);
                }
                if (isTyped && MaybeEat(TokenKind.Colon)) {
                    if (_verbatim) {
                        AddThirdPreceedingWhiteSpace(parameter, _tokenWhiteSpace);
                    }

                    var start = GetStart();
                    parameter.Annotation = ParseExpression();

                    if (_langVersion.Is2x()) {
                        ReportSyntaxError(start, parameter.Annotation.EndIndex, "invalid syntax, parameter annotations require 3.x");
                    }
                }
                CompleteParameterName(parameter, name.RealName, names, paramStart);
            } else {
                ReportSyntaxError(_lookahead);
                NextToken();
                parameter = new ErrorParameter(_verbatim ? Error(_tokenWhiteSpace + _token.Token.VerbatimImage) : null);
            }

            return parameter;
        }
Esempio n. 4
0
 public override bool Walk(SublistParameter node) {
     node.AddVariable(_binder._globalScope, _binder._bindRefs, _binder.DefineParameter(node.Name));
     // we walk the node by hand to avoid walking the default values.
     WalkTuple(node.Tuple);
     return false;
 }
Esempio n. 5
0
 public override bool Walk(SublistParameter node) {
     return true;
 }
Esempio n. 6
0
 public override bool Walk(SublistParameter node)
 {
     return(true);
 }
Esempio n. 7
0
 public override void PostWalk(SublistParameter node) { PostWalkWorker(node); }
Esempio n. 8
0
 // SublistParameter
 public override bool Walk(SublistParameter node) { return ShouldWalkWorker(node); }