# Path: reggata/errors.py
# class LexError(Exception):
#     def __init__(self, msg=None, cause=None):
#         super(LexError, self).__init__(msg)
#         self.cause = cause


from ply import lex
from reggata.errors import LexError
import re
import reggata.consts as consts
Tokens for parser from definition_parser module.
'''


# Token types:
tokens = [
   'STRING', # String as a single word (without whitespaces) or a quoted string
   'COLON',  # This is a delimiter between field name and field value
]


def t_STRING(t):
    r'"(\\["\\]|[^"\\])*"|([^\s():=><~"\\])+' #Тут пробелы лишние нельзя ставить!!!
    # For explanation of the regexp look here: query_tokens.t_STRING
    if t.type == 'STRING' \
    and t.value.startswith('"') \
    and t.value.endswith('"') \
    and not t.value.endswith(r'\"'):
        t.value = t.value.replace(r"\\", "\\")
        t.value = t.value.replace(r'\"', r'"')
        t.value = t.value[1:-1]
    return t

t_COLON = r':'

# Symbols that are ignored
t_ignore  = ' \t\n\r'


def t_error(t):

# Path: reggata/errors.py
# class LexError(Exception):
#     def __init__(self, msg=None, cause=None):
#         super(LexError, self).__init__(msg)
#         self.cause = cause


# Path: reggata/parsers/definition_tokens.py
from ply import lex
from reggata.errors import LexError
import re
import reggata.consts as consts

Tokens for parser from definition_parser module.
'''


# Token types:
tokens = [
   'STRING', # String as a single word (without whitespaces) or a quoted string
   'COLON',  # This is a delimiter between field name and field value
]


def t_STRING(t):
    r'"(\\["\\]|[^"\\])*"|([^\s():=><~"\\])+' #Тут пробелы лишние нельзя ставить!!!
    # For explanation of the regexp look here: query_tokens.t_STRING
    if t.type == 'STRING' \
    and t.value.startswith('"') \
    and t.value.endswith('"') \
    and not t.value.endswith(r'\"'):
        t.value = t.value.replace(r"\\", "\\")
        t.value = t.value.replace(r'\"', r'"')
        t.value = t.value[1:-1]
    return t

t_COLON = r':'

# Symbols that are ignored
t_ignore  = ' \t\n\r'


def t_error(t):

    raise LexError("Lexical error in '{}'".format(t.value[0]))