Наследование: ITSQLClauseParser
Пример #1
0
        public TSQLOutputClause Parse(ITSQLTokenizer tokenizer)
        {
            TSQLOutputClause output = new TSQLOutputClause();

            if (!tokenizer.Current.IsFutureKeyword(TSQLFutureKeywords.OUTPUT))
            {
                throw new InvalidOperationException("OUTPUT expected.");
            }

            output.Tokens.Add(tokenizer.Current);

            while (
                tokenizer.MoveNext() &&
                !tokenizer.Current.IsCharacter(TSQLCharacters.Semicolon) &&
                (
                    tokenizer.Current.IsKeyword(TSQLKeywords.AS) ||
                    tokenizer.Current.Type == TSQLTokenType.Identifier ||
                    tokenizer.Current.Type == TSQLTokenType.SystemColumnIdentifier ||
                    tokenizer.Current.IsCharacter(TSQLCharacters.Period) ||
                    tokenizer.Current.IsCharacter(TSQLCharacters.Comma) ||
                    tokenizer.Current.Text == "*" ||
                    tokenizer.Current.Type == TSQLTokenType.Whitespace ||
                    tokenizer.Current.Type == TSQLTokenType.SingleLineComment ||
                    tokenizer.Current.Type == TSQLTokenType.MultilineComment
                ))
            {
                output.Tokens.Add(tokenizer.Current);
            }

            if (tokenizer.Current.IsKeyword(TSQLKeywords.INTO))
            {
                TSQLIntoClause intoClause = new TSQLIntoClauseParser().Parse(tokenizer);

                output.Into = intoClause;

                output.Tokens.AddRange(intoClause.Tokens);
            }

            return(output);
        }
        public TSQLSelectStatement Parse(TSQLTokenizer tokenizer)
        {
            TSQLSelectStatement select = new TSQLSelectStatement();

            // should whitespace be excluded from statement parsing logic?

            // should I differentiate keywords that start commands?

            // correlated subqueries
            // scalar function calls

            // SELECT clause

            TSQLSelectClause selectClause = new TSQLSelectClauseParser().Parse(tokenizer);

            select.Select = selectClause;

            select.Tokens.AddRange(selectClause.Tokens);

            if (tokenizer.Current.IsKeyword(TSQLKeywords.INTO))
            {
                TSQLIntoClause intoClause = new TSQLIntoClauseParser().Parse(tokenizer);

                select.Into = intoClause;

                select.Tokens.AddRange(intoClause.Tokens);
            }

            if (tokenizer.Current.IsKeyword(TSQLKeywords.FROM))
            {
                TSQLFromClause fromClause = new TSQLFromClauseParser().Parse(tokenizer);

                select.From = fromClause;

                select.Tokens.AddRange(fromClause.Tokens);
            }

            if (tokenizer.Current.IsKeyword(TSQLKeywords.WHERE))
            {
                TSQLWhereClause whereClause = new TSQLWhereClauseParser().Parse(tokenizer);

                select.Where = whereClause;

                select.Tokens.AddRange(whereClause.Tokens);
            }

            if (tokenizer.Current.IsKeyword(TSQLKeywords.GROUP))
            {
                TSQLGroupByClause groupByClause = new TSQLGroupByClauseParser().Parse(tokenizer);

                select.GroupBy = groupByClause;

                select.Tokens.AddRange(groupByClause.Tokens);
            }

            if (tokenizer.Current.IsKeyword(TSQLKeywords.HAVING))
            {
                TSQLHavingClause havingClause = new TSQLHavingClauseParser().Parse(tokenizer);

                select.Having = havingClause;

                select.Tokens.AddRange(havingClause.Tokens);
            }

            if (tokenizer.Current.IsKeyword(TSQLKeywords.ORDER))
            {
                TSQLOrderByClause orderByClause = new TSQLOrderByClauseParser().Parse(tokenizer);

                select.OrderBy = orderByClause;

                select.Tokens.AddRange(orderByClause.Tokens);
            }

            if (tokenizer.Current.IsCharacter(TSQLCharacters.Semicolon))
            {
                select.Tokens.Add(tokenizer.Current);
            }

            return select;
        }