public MacroArgumentListSyntax ParseArgumentList()
        {
            var openParen = Match(SyntaxKind.OpenParenToken);

            var arguments = new List <SyntaxNodeBase>();

            CommaIsSeparatorStack.Push(true);

            try
            {
                var currentArg = new List <SyntaxToken>();
                var parenStack = 0;
                while ((Current.Kind != SyntaxKind.CloseParenToken || parenStack > 0) && Current.Kind != SyntaxKind.EndOfFileToken)
                {
                    switch (Current.Kind)
                    {
                    case SyntaxKind.OpenParenToken:
                        CommaIsSeparatorStack.Push(false);
                        parenStack++;
                        currentArg.Add(NextToken());
                        break;

                    case SyntaxKind.CloseParenToken:
                        CommaIsSeparatorStack.Pop();
                        parenStack--;
                        currentArg.Add(NextToken());
                        break;

                    case SyntaxKind.CommaToken:
                        if (CommaIsSeparatorStack.Peek() == false)
                        {
                            goto default;
                        }
                        arguments.Add(new MacroArgumentSyntax(currentArg));
                        currentArg = new List <SyntaxToken>();
                        arguments.Add(Match(SyntaxKind.CommaToken));
                        break;

                    default:
                        currentArg.Add(NextToken());
                        break;
                    }
                }

                if (currentArg.Any())
                {
                    arguments.Add(new MacroArgumentSyntax(currentArg));
                }
            }
            finally
            {
                CommaIsSeparatorStack.Pop();
            }

            var argumentList = new SeparatedSyntaxList <MacroArgumentSyntax>(arguments);

            var closeParen = Match(SyntaxKind.CloseParenToken);

            return(new MacroArgumentListSyntax(openParen, argumentList, closeParen));
        }
        private void ParseArgumentList(SyntaxKind openKind, SyntaxKind closeKind, bool atLeastOneArg, out SyntaxToken openToken, out SeparatedSyntaxList <ExpressionSyntax> arguments, out SyntaxToken closeToken)
        {
            openToken = Match(openKind);

            var args = new List <SyntaxNodeBase>();

            if (atLeastOneArg || Current.Kind != closeKind)
            {
                CommaIsSeparatorStack.Push(true);

                try
                {
                    args.Add(ParseExpression());

                    while (Current.Kind == SyntaxKind.CommaToken)
                    {
                        args.Add(Match(SyntaxKind.CommaToken));
                        args.Add(ParseExpression());
                    }
                }
                finally
                {
                    CommaIsSeparatorStack.Pop();
                }
            }

            arguments = new SeparatedSyntaxList <ExpressionSyntax>(args);

            closeToken = Match(closeKind);
        }
예제 #3
0
        private PredefinedObjectTypeSyntax ParsePatchType(SyntaxToken token)
        {
            var lessThan        = Match(SyntaxKind.LessThanToken);
            var userDefinedType = ParseIdentifier();
            var comma           = Match(SyntaxKind.CommaToken);

            ExpressionSyntax controlPoints;

            try
            {
                CommaIsSeparatorStack.Push(true);
                _greaterThanTokenIsNotOperator = true;
                controlPoints = ParseExpression();
            }
            finally
            {
                _greaterThanTokenIsNotOperator = false;
                CommaIsSeparatorStack.Pop();
            }

            var greaterThan      = Match(SyntaxKind.GreaterThanToken);
            var typeArgumentList = new TemplateArgumentListSyntax(lessThan,
                                                                  new SeparatedSyntaxList <ExpressionSyntax>(new List <SyntaxNodeBase> {
                userDefinedType, comma, controlPoints
            }),
                                                                  greaterThan);

            return(new PredefinedObjectTypeSyntax(token, typeArgumentList));
        }
        private ExpressionSyntax ParseVariableInitializer()
        {
            CommaIsSeparatorStack.Push(true);

            try
            {
                switch (Current.Kind)
                {
                case SyntaxKind.OpenBraceToken:
                    return(ParseArrayInitializer());

                default:
                    return(ParseExpression());
                }
            }
            finally
            {
                CommaIsSeparatorStack.Pop();
            }
        }
        private ExpressionSyntax ParseCastOrParenthesizedExpression()
        {
            Debug.Assert(Current.Kind == SyntaxKind.OpenParenToken);

            var resetPoint = GetResetPoint();

            // We have a decision to make -- is this a cast, or is it a parenthesized
            // expression?  Because look-ahead is cheap with our token stream, we check
            // to see if this "looks like" a cast (without constructing any parse trees)
            // to help us make the decision.
            if (ScanCast())
            {
                // Looks like a cast, so parse it as one.
                Reset(ref resetPoint);
                var openParen = Match(SyntaxKind.OpenParenToken);
                List <ArrayRankSpecifierSyntax> arrayRankSpecifiers;
                var type       = ParseTypeForCast(out arrayRankSpecifiers);
                var closeParen = Match(SyntaxKind.CloseParenToken);
                var expr       = ParseSubExpression(SyntaxFacts.GetOperatorPrecedence(SyntaxKind.CastExpression));
                return(new CastExpressionSyntax(openParen, type, arrayRankSpecifiers, closeParen, expr));
            }

            // Doesn't look like a cast, so parse this as a parenthesized expression.
            {
                Reset(ref resetPoint);
                var openParen = Match(SyntaxKind.OpenParenToken);

                try
                {
                    CommaIsSeparatorStack.Push(false);
                    var expression = ParseSubExpression(0);
                    var closeParen = Match(SyntaxKind.CloseParenToken);
                    return(new ParenthesizedExpressionSyntax(openParen, expression, closeParen));
                }
                finally
                {
                    CommaIsSeparatorStack.Pop();
                }
            }
        }
예제 #6
0
        private PredefinedObjectTypeSyntax ParseMultisampledTextureType(SyntaxToken token)
        {
            var lessThan = Match(SyntaxKind.LessThanToken);
            var type     = ParseScalarOrVectorType();

            var arguments = new List <SyntaxNodeBase> {
                type
            };

            if (Current.Kind == SyntaxKind.CommaToken)
            {
                var comma = Match(SyntaxKind.CommaToken);

                ExpressionSyntax samples;
                try
                {
                    CommaIsSeparatorStack.Push(true);
                    _greaterThanTokenIsNotOperator = true;
                    samples = ParseExpression();
                }
                finally
                {
                    _greaterThanTokenIsNotOperator = false;
                    CommaIsSeparatorStack.Pop();
                }

                arguments.Add(comma);
                arguments.Add(samples);
            }

            var greaterThan      = Match(SyntaxKind.GreaterThanToken);
            var typeArgumentList = new TemplateArgumentListSyntax(lessThan,
                                                                  new SeparatedSyntaxList <ExpressionSyntax>(arguments),
                                                                  greaterThan);

            return(new PredefinedObjectTypeSyntax(token, typeArgumentList));
        }