// parameter ::= // identifier | "(" sublist ")" private Parameter ParseParameter(int position, HashSet<string> names, ParameterKind kind, bool isTyped = false) { Token t = PeekToken(); Parameter parameter; switch (t.Kind) { case TokenKind.LeftParenthesis: // sublist string parenWhiteSpace = _lookaheadWhiteSpace; NextToken(); var parenStart = GetStart(); Expression ret = ParseSublist(names, true); if (_langVersion.Is7x()) { 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); } } break; case TokenKind.Name: // identifier NextToken(); var name = TokenToName((NameToken)t); 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.Is6x()) { ReportSyntaxError(start, parameter.Annotation.EndIndex, "invalid syntax, parameter annotations require 3.x"); } } CompleteParameterName(parameter, name.RealName, names, paramStart); break; default: ReportSyntaxError(_lookahead); NextToken(); parameter = new ErrorParameter(_verbatim ? Error(_tokenWhiteSpace + _token.Token.VerbatimImage) : null); break; } return parameter; }
// SublistParameter public override bool Walk(SublistParameter node) { return ShouldWalkWorker(node); }
public override bool Walk(SublistParameter node) { return true; }
public override void PostWalk(SublistParameter node) { PostWalkWorker(node); }