Пример #1
0
        private SeparatedSyntaxList <ExpressionSyntax> ParseArgumentExpressionList(int minimumNumberOfArguments)
        {
            if (Current.Kind == SyntaxKind.RightParenthesisToken && minimumNumberOfArguments == 0)
            {
                return(SeparatedSyntaxList <ExpressionSyntax> .Empty);
            }

            var expressionsWithCommas = new List <SyntaxNodeOrToken>();
            var minimumNumberOfItems  = minimumNumberOfArguments * 2 - 1;

            while (true)
            {
                var oldIndex = _tokenIndex;

                var argument = ParseExpression();
                expressionsWithCommas.Add(argument);

                if (_tokenIndex == oldIndex)
                {
                    SkipTokens(t => SyntaxFacts.CanFollowArgument(t.Kind));
                }

                var missingComma       = Current.Kind != SyntaxKind.CommaToken;
                var enoughParameters   = minimumNumberOfItems <= expressionsWithCommas.Count;
                var canStartExpression = SyntaxFacts.CanStartExpression(Current.Kind);

                if (missingComma && enoughParameters && !canStartExpression)
                {
                    break;
                }

                var comma = Match(SyntaxKind.CommaToken);
                expressionsWithCommas.Add(comma);
            }

            return(new SeparatedSyntaxList <ExpressionSyntax>(expressionsWithCommas));
        }