# Path: actrie/tokenizer.py
# class Tokenizer:
#     def __init__(self, text):
#         self.text = text
#         self.cur = 0
# 
#     @staticmethod
#     def escape_char(ch):
#         if ch == u"\\":
#             return u"\\"
#         elif ch == u"t":
#             return u"\t"
#         elif ch == u"r":
#             return u"\r"
#         elif ch == u"n":
#             return u"\n"
#         elif ch == u"(":
#             return u"("
#         elif ch == u")":
#             return u")"
# 
#         raise TokenizerError("'\\" + ch + "' is not a escape character")
# 
#     def consume(self, stop=set()):
#         s = u""
#         is_escape = False
#         so = self.cur
# 
#         while self.cur < len(self.text):
#             ch = self.text[self.cur]
#             self.cur += 1
# 
#             if is_escape:
#                 ch = self.escape_char(ch)
#                 is_escape = False
#             else:
#                 if ch == u"\\":
#                     is_escape = True
#                     continue
# 
#                 if ch in stop and (ch != u"." or self.cur >= len(self.text) or self.text[self.cur] == "{"):
#                     return s, ch
# 
#             s += ch
# 
#         return s, -1
# 
#     def consume_integer(self):
#         s = u""
#         while self.cur < len(self.text):
#             ch = self.text[self.cur]
#             if ch not in number_char:
#                 break
#             s += ch
#             self.cur += 1
#         return int(s) if s else None
# 
#     def expect(self, s, move=True):
#         wlen = len(s)
#         if len(self.text) - self.cur >= wlen and self.text[self.cur : (self.cur + wlen)] == s:
#             if move:
#                 self.cur += wlen
#             return True
#         return False
# 
#     def eof(self):
#         return self.cur == len(self.text)
# 
# Path: actrie/util.py
# def convert2pass(string):
# def convert2unicode(string):
# def replace_escap(word):
# def convert2pass(string):
# def convert2unicode(string):
# def replace_escap(word):


from abc import ABCMeta, abstractmethod
    from enum import Enum
from .tokenizer import Tokenizer
from .util import convert2unicode, is_py2k
        else:
            return u"(" + u"|".join([p.ustr() for p in self.alters]) + u")"

    def __str__(self):
        return self.ustr() if not is_py2k else self.ustr().encode("utf-8")


class AntiAmbiguousPattern(Pattern):
    def __init__(self, origin, ambis):
        Pattern.__init__(self)
        self.type = PatternType.AntiAmbiguous
        self.origin = origin
        self.ambis = set(ambis)

    def ustr(self):
        return self.origin.ustr() + u"(?&!" + u"|".join([p.ustr() for p in self.ambis]) + u")"

    def __str__(self):
        return self.ustr() if not is_py2k else self.ustr().encode("utf-8")


class DistancePattern(Pattern):
    def __init__(self, head, tail, dist):
        Pattern.__init__(self)
        self.type = PatternType.Distance
        self.head = head
        self.tail = tail
        self.dist = dist

    def ustr(self):

# Path: actrie/tokenizer.py
# class Tokenizer:
#     def __init__(self, text):
#         self.text = text
#         self.cur = 0
# 
#     @staticmethod
#     def escape_char(ch):
#         if ch == u"\\":
#             return u"\\"
#         elif ch == u"t":
#             return u"\t"
#         elif ch == u"r":
#             return u"\r"
#         elif ch == u"n":
#             return u"\n"
#         elif ch == u"(":
#             return u"("
#         elif ch == u")":
#             return u")"
# 
#         raise TokenizerError("'\\" + ch + "' is not a escape character")
# 
#     def consume(self, stop=set()):
#         s = u""
#         is_escape = False
#         so = self.cur
# 
#         while self.cur < len(self.text):
#             ch = self.text[self.cur]
#             self.cur += 1
# 
#             if is_escape:
#                 ch = self.escape_char(ch)
#                 is_escape = False
#             else:
#                 if ch == u"\\":
#                     is_escape = True
#                     continue
# 
#                 if ch in stop and (ch != u"." or self.cur >= len(self.text) or self.text[self.cur] == "{"):
#                     return s, ch
# 
#             s += ch
# 
#         return s, -1
# 
#     def consume_integer(self):
#         s = u""
#         while self.cur < len(self.text):
#             ch = self.text[self.cur]
#             if ch not in number_char:
#                 break
#             s += ch
#             self.cur += 1
#         return int(s) if s else None
# 
#     def expect(self, s, move=True):
#         wlen = len(s)
#         if len(self.text) - self.cur >= wlen and self.text[self.cur : (self.cur + wlen)] == s:
#             if move:
#                 self.cur += wlen
#             return True
#         return False
# 
#     def eof(self):
#         return self.cur == len(self.text)
# 
# Path: actrie/util.py
# def convert2pass(string):
# def convert2unicode(string):
# def replace_escap(word):
# def convert2pass(string):
# def convert2unicode(string):
# def replace_escap(word):


# Path: actrie/pattern.py
from abc import ABCMeta, abstractmethod
    from enum import Enum
from .tokenizer import Tokenizer
from .util import convert2unicode, is_py2k

        else:
            return u"(" + u"|".join([p.ustr() for p in self.alters]) + u")"

    def __str__(self):
        return self.ustr() if not is_py2k else self.ustr().encode("utf-8")


class AntiAmbiguousPattern(Pattern):
    def __init__(self, origin, ambis):
        Pattern.__init__(self)
        self.type = PatternType.AntiAmbiguous
        self.origin = origin
        self.ambis = set(ambis)

    def ustr(self):
        return self.origin.ustr() + u"(?&!" + u"|".join([p.ustr() for p in self.ambis]) + u")"

    def __str__(self):
        return self.ustr() if not is_py2k else self.ustr().encode("utf-8")


class DistancePattern(Pattern):
    def __init__(self, head, tail, dist):
        Pattern.__init__(self)
        self.type = PatternType.Distance
        self.head = head
        self.tail = tail
        self.dist = dist

    def ustr(self):

        return self.head.ustr() + u".{0," + convert2unicode(str(self.dist)) + u"}" + self.tail.ustr()