#!/usr/bin/env python
# -*- coding: utf-8 -*-

# CAVEAT UTILITOR
#
# This file was automatically generated by Grako.
#
#    https://pypi.python.org/pypi/grako/
#
# Any changes you make to it will be overwritten the next time
# the file is generated.


from __future__ import print_function, division, absolute_import, unicode_literals

from grako.parsing import graken, Parser
from grako.util import re, RE_FLAGS, generic_main  # noqa


__version__ = (2016, 8, 1, 1, 11, 9, 0)

__all__ = [
    'SqlParser',
    'SqlSemantics',
    'main'
]

KEYWORDS = set([])


class SqlParser(Parser):
    def __init__(self,
                 whitespace='\\s+',
                 nameguard=None,
                 comments_re='/\\*[\\s\\S]*?\\*/',
                 eol_comments_re='--.*?$',
                 ignorecase=True,
             
    left_recursion=True,
                 keywords=KEYWORDS,
                 namechars='',
                 **kwargs):
 
       super(SqlParser, self).__init__(
            whitespace=whitespace,
            nameguard=nameguard,
            comments_re=comments_re,
            eol_comments_re=eol_comments_re,
            ignorecase=ignorecase,
            left_recursion=left_recursion,
            keywords=keywords,
            namechars=namechars,
            **kwargs
        )

    @graken()
    def _digit_(self):
        self._pattern(r'\d+')

    @graken()
    def _double_quote_(self):
        self._token('"')

    @graken()
    def _quote_(self):
        self._token("'")

    @graken()
    def _left_paren_(self):
        self._token('(')

    @graken()
    def _right_paren_(self):
        self._token(')')

    @graken()
    def _asterisk_(self):
        self._token('*')

    @graken()
    def _plus_sign_(self):
        self._token('+')

    @graken()
    def _comma_(self):
        self._token(',')

    @graken()
    def _minus_sign_(self):
        self._token('-')

    @graken()
    def _period_(self):
        self._token('.')

    @graken()
    def _solidus_(self):
        self._token('/')

    @graken()
    def _colon_(self):
        self._token(':')

    @graken()
    def _semicolon_(self):
        self._token(';')

    @graken()
    def _less_than_operator_(self):
        self._token('<')

    @graken()
    def _equals_operator_(self):
        self._token('=')

    @graken()
    def _greater_than_operator_(self):
        self._token('>')

    @graken()
    def _question_mark_(self):
        self._token('?')

    @graken()
    def _underscore_(self):
        self._token('_')

    @graken()
    def _regular_identifier_(self):
        self._pattern(r'[a-z]\w*')
        self._check_name()

    @graken()
    def _delimited_identifier_(self):
        self._double_quote_()
        self._delimited_identifier_body_()
        self._double_quote_()

    @graken()
    def _delimited_identifier_body_(self):
        self._pattern(r'(""|[^"\n])+')

    @graken()
    def _not_equals_operator_(self):
        self._token('<>')

    @graken()
    def _greater_than_or_equals_operator_(self):
        self._token('>=')

    @graken()
    def _less_than_or_equals_operator_(self):
        self._token('<=')

    @graken()
    def _concatenation_operator_(self):
        self._token('||')

    @graken()
    def _literal_(self):
        with self._choice():
            with self._option():
                self._signed_numeric_literal_()
            with self._option():
                self._general_literal_()
            self._error('no available options')

    @graken()
    def _unsigned_literal_(self):
        with self._choice():
            with self._option():
                self._unsigned_numeric_literal_()
            with self._option():
                self._general_literal_()
            self._error('no available options')

    @graken()
    def _general_literal_(self):
        with self._choice():
            with self._option():
                self._character_string_literal_()
            with self._option():
                self._national_character_string_literal_()
            with self._option():
                self._bit_string_literal_()
            with self._option():
                self._hex_string_literal_()
            with self._option():
                self._datetime_literal_()
            with self._option():
                self._interval_literal_()
            self._error('no available options')

    @graken()
    def _character_string_literal_(self):
        with self._optional():
            self._underscore_()
            self._character_set_name_()

        def block0():
            self._quote_()
            self._character_representation_()
            self._quote_()
        self._positive_closure(block0)

    @graken()
    def _character_representation_(self):
        self._pattern(r"(''|[^'\n])*")

    @graken()
    def _national_character_string_literal_(self):
        self._token('N')

        def block0():
            self._quote_()
            self._character_representation_()
            self._quote_()
        self._positive_closure(block0)

    @graken()
    def _bit_string_literal_(self):
        self._token('B')

        def block0():
            self._quote_()
            with self._optional():

                def block1():
                    self._bit_()
                self._positive_closure(block1)
            self._quote_()
        self._positive_closure(block0)

    @graken()
    def _hex_string_literal_(self):
        self._token('X')

        def block0():
            self._quote_()
            with self._optional():

                def block1():
                    self._hexit_()
                self._positive_closure(block1)
            self._quote_()
        self._positive_closure(block0)

    @graken()
    def _bit_(self):
        self._pattern(r'[01]')

    @graken()
    def _hexit_(self):
        self._pattern(r'[a-f\d]')

    @graken()
    def _signed_numeric_literal_(self):
        with self._optional():
            self._sign_()
        self._unsigned_numeric_literal_()

    @graken()
    def _unsigned_numeric_literal_(self):
        with self._choice():
            with self._option():
                self._exact_numeric_literal_()
            with self._option():
                self._approximate_numeric_literal_()
            self._error('no available options')

    @graken()
    def _exact_numeric_literal_(self):
        with self._choice():
            with self._option():
                self._unsigned_integer_()
                with self._optional():
                    self._period_()
                    with self._optional():
                        self._unsigned_integer_()
            with self._option():
                self._period_()
                self._unsigned_integer_()
            self._error('no available options')

    @graken()
    def _sign_(self):
        with self._choice():
            with self._option():
                self._plus_sign_()
            with self._option():
                self._minus_sign_()
            self._error('no available options')

    @graken()
    def _approximate_numeric_literal_(self):
        self._exact_numeric_literal_()
        self._token('E')
        self._signed_integer_()

    @graken()
    def _signed_integer_(self):
        with self._optional():
            self._sign_()
        self._unsigned_integer_()

    @graken()
    def _unsigned_integer_(self):
        self._digit_()

    @graken()
    def _datetime_literal_(self):
        with self._choice():
            with self._option():
                self._date_literal_()
            with self._option():
                self._time_literal_()
            with self._option():
                self._timestamp_literal_()
            self._error('no available options')

    @graken()
    def _date_literal_(self):
        self._token('DATE')
        self._date_string_()

    @graken()
    def _time_literal_(self):
        self._token('TIME')
        self._time_string_()

    @graken()
    def _timestamp_literal_(self):
        self._token('TIMESTAMP')
        self._timestamp_string_()

    @graken()
    def _date_string_(self):
        self._quote_()
        self._d