equal
deleted
inserted
replaced
31 return ":{:d}: {:s}\nLINE: {:s}".format(self.lineno, self.msg, self.line) |
31 return ":{:d}: {:s}\nLINE: {:s}".format(self.lineno, self.msg, self.line) |
32 |
32 |
33 |
33 |
34 class Parser: |
34 class Parser: |
35 """gadict dictionary format parser.""" |
35 """gadict dictionary format parser.""" |
|
36 |
|
37 COMMENT_RE = regex.compile(r"^# ") |
36 |
38 |
37 SEPARATOR_RE = regex.compile(r"^__$") |
39 SEPARATOR_RE = regex.compile(r"^__$") |
38 HEADWORD_RE = regex.compile(r"^(\p{L}.*)$") |
40 HEADWORD_RE = regex.compile(r"^(\p{L}.*)$") |
39 HEADWORD_VAR_RE = regex.compile(r"^ +(s|pl|v[123]|male|female|comp|super)$") |
41 HEADWORD_VAR_RE = regex.compile(r"^ +(s|pl|v[123]|male|female|comp|super)$") |
40 HEADWORD_PRON_RE = regex.compile(r"^ +\[([\p{L}' ]+)\]$") |
42 HEADWORD_PRON_RE = regex.compile(r"^ +\[([\p{L}' ]+)\]$") |
55 |
57 |
56 def __init__(self): |
58 def __init__(self): |
57 pass |
59 pass |
58 |
60 |
59 def readline(self): |
61 def readline(self): |
60 self.line = self.stream.readline() |
62 while True: |
61 self.eof = len(self.line) == 0 |
63 self.line = self.stream.readline() |
62 if not self.eof: |
64 self.eof = len(self.line) == 0 |
63 self.lineno += 1 |
65 if not self.eof: |
64 if self.TRAILING_SPACES_RE.search(self.line): |
66 self.lineno += 1 |
65 raise ParseException("Traling spaces detected...\n") |
67 if self.TRAILING_SPACES_RE.search(self.line): |
|
68 raise ParseException("Traling spaces detected...\n") |
|
69 if self.COMMENT_RE.search(self.line): |
|
70 continue |
|
71 break |
66 |
72 |
67 def parse(self, stream): |
73 def parse(self, stream): |
68 self.lineno = 0 |
74 self.lineno = 0 |
69 self.stream = stream |
75 self.stream = stream |
70 self.dom = [] |
76 self.dom = [] |