# Path: format_sql/tokenizer.py
# class Token:
#     AS = 'AS'
#     ASC = 'ASC'
#     COMMA = ','
#     COMPARE = 'compare'
#     DESC = 'DESC'
#     FROM = 'FROM'
#     FUNC = 'func'
#     GROUP_BY = 'GROUP'
#     IDENTIFIER = 'identifier'
#     IN = 'IN'
#     INSERT = 'INSERT'
#     IS = 'IS'
#     ON = 'ON'
#     NULL = 'NULL'
#     HAVING = 'HAVING'
#     JOIN = 'join'
#     LIMIT = 'LIMIT'
#     LINK = 'link'
#     NOT = 'NOT'
#     NUMBER = 'number'
#     ORDER_BY = 'ORDER'
#     PARENTHESIS_CLOSE = ')'
#     PARENTHESIS_OPEN = '('
#     SEMICOLON = ';'
#     SELECT = 'SELECT'
#     STR = 'str'
#     WITH_ROLLUP = 'WITH'
#     WHERE = 'WHERE'
#     VALUES = 'VALUES'
#     BETWEEN = 'BETWEEN'
#     CASE = 'CASE'
#     WHEN = 'WHEN'
#     THEN = 'THEN'
#     ELSE = 'ELSE'
# 
#     def __init__(self, token_type, token_value):
#         self._type = token_type
#         self._value = token_value
# 
#     def __repr__(self):
#         return '<%s: %s>' % (self._type, self._value)
# 
#     @staticmethod
#     def get_token(value):
#         normalized = value.split()[0].upper()
# 
#         if normalized in TOKEN_RES.keys():
#             return normalized
# 
#         normalized = value.split()[-1].upper()
#         if normalized == 'JOIN':
#             return Token.JOIN
# 
#         return None


import attr
from format_sql.tokenizer import Token
            values.append(on)

        elif toks[i]._type == Token.COMMA:
            i += 1

        else:
            break

    from_ = From(toks[0]._value, values)
    return from_, i


def _parse_alias(toks):
    i = 0
    result = {'as': None, 'alias': None}
    if len(toks) > i and toks[i]._type == Token.AS:
        result['as'] = toks[i]._value
        i += 1

    if _match(toks[i:], [(Token.IDENTIFIER, Token.STR, Token.NUMBER)]):
        result['alias'] = toks[i]._value
        i += 1
    return result, i


def _parse_group_by(toks):
    values = []

    i = 1
    while i < len(toks):

# Path: format_sql/tokenizer.py
# class Token:
#     AS = 'AS'
#     ASC = 'ASC'
#     COMMA = ','
#     COMPARE = 'compare'
#     DESC = 'DESC'
#     FROM = 'FROM'
#     FUNC = 'func'
#     GROUP_BY = 'GROUP'
#     IDENTIFIER = 'identifier'
#     IN = 'IN'
#     INSERT = 'INSERT'
#     IS = 'IS'
#     ON = 'ON'
#     NULL = 'NULL'
#     HAVING = 'HAVING'
#     JOIN = 'join'
#     LIMIT = 'LIMIT'
#     LINK = 'link'
#     NOT = 'NOT'
#     NUMBER = 'number'
#     ORDER_BY = 'ORDER'
#     PARENTHESIS_CLOSE = ')'
#     PARENTHESIS_OPEN = '('
#     SEMICOLON = ';'
#     SELECT = 'SELECT'
#     STR = 'str'
#     WITH_ROLLUP = 'WITH'
#     WHERE = 'WHERE'
#     VALUES = 'VALUES'
#     BETWEEN = 'BETWEEN'
#     CASE = 'CASE'
#     WHEN = 'WHEN'
#     THEN = 'THEN'
#     ELSE = 'ELSE'
# 
#     def __init__(self, token_type, token_value):
#         self._type = token_type
#         self._value = token_value
# 
#     def __repr__(self):
#         return '<%s: %s>' % (self._type, self._value)
# 
#     @staticmethod
#     def get_token(value):
#         normalized = value.split()[0].upper()
# 
#         if normalized in TOKEN_RES.keys():
#             return normalized
# 
#         normalized = value.split()[-1].upper()
#         if normalized == 'JOIN':
#             return Token.JOIN
# 
#         return None


# Path: format_sql/parser.py
import attr
from format_sql.tokenizer import Token

            values.append(on)

        elif toks[i]._type == Token.COMMA:
            i += 1

        else:
            break

    from_ = From(toks[0]._value, values)
    return from_, i


def _parse_alias(toks):
    i = 0
    result = {'as': None, 'alias': None}
    if len(toks) > i and toks[i]._type == Token.AS:
        result['as'] = toks[i]._value
        i += 1

    if _match(toks[i:], [(Token.IDENTIFIER, Token.STR, Token.NUMBER)]):
        result['alias'] = toks[i]._value
        i += 1
    return result, i


def _parse_group_by(toks):
    values = []

    i = 1
    while i < len(toks):

        if toks[i]._type not in (Token.IDENTIFIER, Token.NUMBER):