# Path: cjktools/resources/dict_format.py
# class RegexFormat(DictionaryFormat):
#     """
#     Describes a dictionary format, by providing regular expressions
#     for the header, the entry lines, and senses within an entry line. The
#     entry line pattern should have named values called 'word', 'reading',
#     and 'senses'.
#     """
# 
#     def __init__(self, name, header_pattern, line_pattern, sense_pattern):
#         self.name = name
#         self.header_pattern = re.compile(header_pattern, re.UNICODE)
#         self.line_pattern = re.compile(line_pattern, re.UNICODE)
#         self.sense_pattern = re.compile(sense_pattern, re.UNICODE)
# 
#     def match_header(self, header_line):
#         return bool(self.header_pattern.match(header_line))
# 
#     def parse_line(self, entry_line):
#         match = self.line_pattern.match(entry_line)
#         if not match:
#             raise FormatError("Bad line: %s" % entry_line)
# 
#         match_dict = match.groupdict()
# 
#         word = match_dict['word'].replace(' ', '')
#         reading = (match_dict.get('reading') or word).replace(' ', '')
#         readings = [reading]
#         sense_line = match_dict.get('senses')
# 
#         senses = []
#         for match in self.sense_pattern.finditer(sense_line):
#             senses.append(match.groupdict()['sense'])
# 
#         if not senses:
#             raise FormatError("No senses for word: %s" % word)
# 
#         return DictionaryEntry(word, readings, senses)
# 
# class UnknownFormatError(Exception):
#     """
#     Indicates that the dictionary which we attempted to parse had an
#     unknown format.
#     """
#     pass


from .dict_format import RegexFormat, UnknownFormatError
    at once.
    """
    lines = iter(istream)
    header = next(lines)
    return detect_format(header).iter_entries(lines)


#
#  DICTIONARY FORMATS
#

known_formats = [
    RegexFormat(
        'edict',
        '^.？？？.*$',
        '^(?P<word>[^ ]+) (\[(?P<reading>[^\]]+)\] )?(?P<senses>.*)$',
        '/(?P<sense>[^/]+)',
    ),
    RegexFormat(
        'jc_kdic',
        '^FORMAT jc_kdic$',
        '^(?P<word>[^ ]+) \[(?P<reading>[^\]]+)\]\t(?P<senses>.*)$',
        '(?P<sense>[^，]+)[，]?',
    ),
    RegexFormat(
        'cj_kdic',
        '^FORMAT cj_kdic$',
        '^(?P<word>[^\t]+)\t(?P<reading>[^\\\\]+)\\\\n(?P<senses>.*)$',
        '([１２３４５７８９０]+．)?(?P<sense>[^\\\\]+)(\\\\n)?',
    ),

# Path: cjktools/resources/dict_format.py
# class RegexFormat(DictionaryFormat):
#     """
#     Describes a dictionary format, by providing regular expressions
#     for the header, the entry lines, and senses within an entry line. The
#     entry line pattern should have named values called 'word', 'reading',
#     and 'senses'.
#     """
# 
#     def __init__(self, name, header_pattern, line_pattern, sense_pattern):
#         self.name = name
#         self.header_pattern = re.compile(header_pattern, re.UNICODE)
#         self.line_pattern = re.compile(line_pattern, re.UNICODE)
#         self.sense_pattern = re.compile(sense_pattern, re.UNICODE)
# 
#     def match_header(self, header_line):
#         return bool(self.header_pattern.match(header_line))
# 
#     def parse_line(self, entry_line):
#         match = self.line_pattern.match(entry_line)
#         if not match:
#             raise FormatError("Bad line: %s" % entry_line)
# 
#         match_dict = match.groupdict()
# 
#         word = match_dict['word'].replace(' ', '')
#         reading = (match_dict.get('reading') or word).replace(' ', '')
#         readings = [reading]
#         sense_line = match_dict.get('senses')
# 
#         senses = []
#         for match in self.sense_pattern.finditer(sense_line):
#             senses.append(match.groupdict()['sense'])
# 
#         if not senses:
#             raise FormatError("No senses for word: %s" % word)
# 
#         return DictionaryEntry(word, readings, senses)
# 
# class UnknownFormatError(Exception):
#     """
#     Indicates that the dictionary which we attempted to parse had an
#     unknown format.
#     """
#     pass


# Path: cjktools/resources/auto_format.py
from .dict_format import RegexFormat, UnknownFormatError

    at once.
    """
    lines = iter(istream)
    header = next(lines)
    return detect_format(header).iter_entries(lines)


#
#  DICTIONARY FORMATS
#

known_formats = [
    RegexFormat(
        'edict',
        '^.？？？.*$',
        '^(?P<word>[^ ]+) (\[(?P<reading>[^\]]+)\] )?(?P<senses>.*)$',
        '/(?P<sense>[^/]+)',
    ),
    RegexFormat(
        'jc_kdic',
        '^FORMAT jc_kdic$',
        '^(?P<word>[^ ]+) \[(?P<reading>[^\]]+)\]\t(?P<senses>.*)$',
        '(?P<sense>[^，]+)[，]?',
    ),
    RegexFormat(
        'cj_kdic',
        '^FORMAT cj_kdic$',
        '^(?P<word>[^\t]+)\t(?P<reading>[^\\\\]+)\\\\n(?P<senses>.*)$',
        '([１２３４５７８９０]+．)?(?P<sense>[^\\\\]+)(\\\\n)?',
    ),

    RegexFormat(