Exemple #1
0
        private static Identifier InternalFromSource([SuppressMessage("Microsoft.Globalization", "CA1303")] string text, bool allowInvalid)
        {
            if (text == null)
            {
                throw ExceptionBuilder.ArgumentNull("text");
            }

            if (text.Length == 0 || (text[0] != '"' && text[0] != '['))
            {
                return(CreateNonVerbatim(text));
            }

            const char      EOF = '\0';
            IdentifierFlags flags;
            char            endChar;
            string          unterminatedMessage;

            if (text[0] == '[')
            {
                endChar             = ']';
                unterminatedMessage = Resources.UnterminatedParenthesizedIdentifier;
                flags = IdentifierFlags.Parenthesized;
            }
            else
            {
                endChar             = '"';
                unterminatedMessage = Resources.UnterminatedQuotedIdentifier;
                flags = IdentifierFlags.Verbatim;
            }

            StringBuilder sb  = new StringBuilder();
            int           pos = 1;

            while (true)
            {
                char c = pos < text.Length ? text[pos] : EOF;
                char l = pos < text.Length - 1 ? text[pos + 1] : EOF;

                if (c == EOF)
                {
                    if (allowInvalid)
                    {
                        break;
                    }
                    else
                    {
                        throw ExceptionBuilder.ArgumentInvalidIdentifier("text", String.Format(CultureInfo.CurrentCulture, unterminatedMessage, text));
                    }
                }
                else if (c == endChar)
                {
                    if (l == endChar)
                    {
                        pos++;
                    }
                    else
                    {
                        break;
                    }
                }

                sb.Append(c);
                pos++;
            }

            if (!allowInvalid && pos < text.Length - 1)
            {
                throw ExceptionBuilder.ArgumentInvalidIdentifier("text", String.Format(CultureInfo.CurrentCulture, Resources.InvalidIdentifier, text));
            }

            return(new Identifier(sb.ToString(), flags));
        }
Exemple #2
0
        protected TResult Dispatch(SyntaxNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            switch (node.Kind)
            {
            case SyntaxKind.CompilationUnit:
                return(VisitCompilationUnit((CompilationUnitSyntax)node));

            case SyntaxKind.SkippedTokensTrivia:
                return(VisitSkippedTokensTrivia((SkippedTokensTriviaSyntax)node));

            case SyntaxKind.ComplementExpression:
            case SyntaxKind.IdentityExpression:
            case SyntaxKind.NegationExpression:
            case SyntaxKind.LogicalNotExpression:
                return(VisitUnaryExpression((UnaryExpressionSyntax)node));

            case SyntaxKind.BitwiseAndExpression:
            case SyntaxKind.BitwiseOrExpression:
            case SyntaxKind.ExclusiveOrExpression:
            case SyntaxKind.AddExpression:
            case SyntaxKind.SubExpression:
            case SyntaxKind.MultiplyExpression:
            case SyntaxKind.DivideExpression:
            case SyntaxKind.ModuloExpression:
            case SyntaxKind.PowerExpression:
            case SyntaxKind.EqualExpression:
            case SyntaxKind.NotEqualExpression:
            case SyntaxKind.LessExpression:
            case SyntaxKind.LessOrEqualExpression:
            case SyntaxKind.GreaterExpression:
            case SyntaxKind.GreaterOrEqualExpression:
            case SyntaxKind.NotLessExpression:
            case SyntaxKind.NotGreaterExpression:
            case SyntaxKind.LeftShiftExpression:
            case SyntaxKind.RightShiftExpression:
            case SyntaxKind.LogicalAndExpression:
            case SyntaxKind.LogicalOrExpression:
                return(VisitBinaryExpression((BinaryExpressionSyntax)node));

            case SyntaxKind.LikeExpression:
                return(VisitLikeExpression((LikeExpressionSyntax)node));

            case SyntaxKind.SoundsLikeExpression:
                return(VisitSoundsLikeExpression((SoundsLikeExpressionSyntax)node));

            case SyntaxKind.SimilarToExpression:
                return(VisitSimilarToExpression((SimilarToExpressionSyntax)node));

            case SyntaxKind.ParenthesizedExpression:
                return(VisitParenthesizedExpression((ParenthesizedExpressionSyntax)node));

            case SyntaxKind.BetweenExpression:
                return(VisitBetweenExpression((BetweenExpressionSyntax)node));

            case SyntaxKind.IsNullExpression:
                return(VisitIsNullExpression((IsNullExpressionSyntax)node));

            case SyntaxKind.CastExpression:
                return(VisitCastExpression((CastExpressionSyntax)node));

            case SyntaxKind.CaseExpression:
                return(VisitCaseExpression((CaseExpressionSyntax)node));

            case SyntaxKind.CaseLabel:
                return(VisitCaseLabel((CaseLabelSyntax)node));

            case SyntaxKind.CoalesceExpression:
                return(VisitCoalesceExpression((CoalesceExpressionSyntax)node));

            case SyntaxKind.NullIfExpression:
                return(VisitNullIfExpression((NullIfExpressionSyntax)node));

            case SyntaxKind.InExpression:
                return(VisitInExpression((InExpressionSyntax)node));

            case SyntaxKind.LiteralExpression:
                return(VisitLiteralExpression((LiteralExpressionSyntax)node));

            case SyntaxKind.VariableExpression:
                return(VisitParameterExpression((VariableExpressionSyntax)node));

            case SyntaxKind.NameExpression:
                return(VisitNameExpression((NameExpressionSyntax)node));

            case SyntaxKind.PropertyAccessExpression:
                return(VisitPropertyAccessExpression((PropertyAccessExpressionSyntax)node));

            case SyntaxKind.CountAllExpression:
                return(VisitCountAllExpression((CountAllExpressionSyntax)node));

            case SyntaxKind.FunctionInvocationExpression:
                return(VisitFunctionInvocationExpression((FunctionInvocationExpressionSyntax)node));

            case SyntaxKind.MethodInvocationExpression:
                return(VisitMethodInvocationExpression((MethodInvocationExpressionSyntax)node));

            case SyntaxKind.ArgumentList:
                return(VisitArgumentList((ArgumentListSyntax)node));

            case SyntaxKind.SingleRowSubselect:
                return(VisitSingleRowSubselect((SingleRowSubselectSyntax)node));

            case SyntaxKind.ExistsSubselect:
                return(VisitExistsSubselect((ExistsSubselectSyntax)node));

            case SyntaxKind.AllAnySubselect:
                return(VisitAllAnySubselect((AllAnySubselectSyntax)node));

            case SyntaxKind.ParenthesizedTableReference:
                return(VisitParenthesizedTableReference((ParenthesizedTableReferenceSyntax)node));

            case SyntaxKind.NamedTableReference:
                return(VisitNamedTableReference((NamedTableReferenceSyntax)node));

            case SyntaxKind.CrossJoinedTableReference:
                return(VisitCrossJoinedTableReference((CrossJoinedTableReferenceSyntax)node));

            case SyntaxKind.InnerJoinedTableReference:
                return(VisitInnerJoinedTableReference((InnerJoinedTableReferenceSyntax)node));

            case SyntaxKind.OuterJoinedTableReference:
                return(VisitOuterJoinedTableReference((OuterJoinedTableReferenceSyntax)node));

            case SyntaxKind.DerivedTableReference:
                return(VisitDerivedTableReference((DerivedTableReferenceSyntax)node));

            case SyntaxKind.ExceptQuery:
                return(VisitExceptQuery((ExceptQuerySyntax)node));

            case SyntaxKind.UnionQuery:
                return(VisitUnionQuery((UnionQuerySyntax)node));

            case SyntaxKind.IntersectQuery:
                return(VisitIntersectQuery((IntersectQuerySyntax)node));

            case SyntaxKind.OrderedQuery:
                return(VisitOrderedQuery((OrderedQuerySyntax)node));

            case SyntaxKind.OrderByColumn:
                return(VisitOrderByColumn((OrderByColumnSyntax)node));

            case SyntaxKind.ParenthesizedQuery:
                return(VisitParenthesizedQuery((ParenthesizedQuerySyntax)node));

            case SyntaxKind.CommonTableExpressionQuery:
                return(VisitCommonTableExpressionQuery((CommonTableExpressionQuerySyntax)node));

            case SyntaxKind.CommonTableExpression:
                return(VisitCommonTableExpression((CommonTableExpressionSyntax)node));

            case SyntaxKind.CommonTableExpressionColumnName:
                return(VisitCommonTableExpressionColumnName((CommonTableExpressionColumnNameSyntax)node));

            case SyntaxKind.CommonTableExpressionColumnNameList:
                return(VisitCommonTableExpressionColumnNameList((CommonTableExpressionColumnNameListSyntax)node));

            case SyntaxKind.SelectQuery:
                return(VisitSelectQuery((SelectQuerySyntax)node));

            case SyntaxKind.TopClause:
                return(VisitTopClause((TopClauseSyntax)node));

            case SyntaxKind.WildcardSelectColumn:
                return(VisitWildcardSelectColumn((WildcardSelectColumnSyntax)node));

            case SyntaxKind.ExpressionSelectColumn:
                return(VisitExpressionSelectColumn((ExpressionSelectColumnSyntax)node));

            case SyntaxKind.SelectClause:
                return(VisitSelectClause((SelectClauseSyntax)node));

            case SyntaxKind.FromClause:
                return(VisitFromClause((FromClauseSyntax)node));

            case SyntaxKind.WhereClause:
                return(VisitWhereClause((WhereClauseSyntax)node));

            case SyntaxKind.GroupByClause:
                return(VisitGroupByClause((GroupByClauseSyntax)node));

            case SyntaxKind.GroupByColumn:
                return(VisitGroupByColumn((GroupByColumnSyntax)node));

            case SyntaxKind.HavingClause:
                return(VisitHavingClause((HavingClauseSyntax)node));

            case SyntaxKind.Alias:
                return(VisitAlias((AliasSyntax)node));

            default:
                throw ExceptionBuilder.UnexpectedValue(node.Kind);
            }
        }