Example #1
0
        private ExpressionSyntax ParsePrimary()
        {
            var k = this.CurrentToken.Kind;

            switch (k)
            {
            case SyntaxKind.OpenParenToken:
                var open  = this.EatToken();
                var expr  = this.ParseExpression();
                var close = this.EatToken(SyntaxKind.CloseParenToken);
                return(SyntaxFactory.ParenthesizedExpression(open, expr, close));

            case SyntaxKind.IdentifierToken:
                var identifier = TruncateIdentifier(this.EatToken());
                return(SyntaxFactory.IdentifierName(identifier));

            case SyntaxKind.TrueKeyword:
            case SyntaxKind.FalseKeyword:
                return(SyntaxFactory.LiteralExpression(
                           SyntaxFacts.GetLiteralExpression(k),
                           this.EatToken()
                           ));

            default:
                return(SyntaxFactory.IdentifierName(
                           this.EatToken(SyntaxKind.IdentifierToken, ErrorCode.ERR_InvalidPreprocExpr)
                           ));
            }
        }