Example #1
0
        private ISqlNode ParseMaybeAliasedTable(ITokenizer t, Func <ITokenizer, ISqlNode> parse)
        {
            var node = parse(t);

            var      next       = t.Peek();
            SqlToken aliasToken = null;
            Location location   = null;

            if (next.IsKeyword("AS"))
            {
                location   = t.GetNext().Location;
                aliasToken = t.GetIdentifierOrKeyword();
            }
            else if (next.IsType(SqlTokenType.Identifier))
            {
                aliasToken = t.GetNext();
            }

            if (aliasToken == null)
            {
                return(node);
            }

            var alias = new SqlAliasNode
            {
                Location = location ?? aliasToken.Location,
                Source   = node,
                Alias    = new SqlIdentifierNode(aliasToken)
            };

            if (t.Peek().IsSymbol("("))
            {
                alias.ColumnNames = ParseParenthesis(t, x => ParseList(x, ParseIdentifier)).Expression;
            }

            return(alias);
        }