Add parsing comment syntax.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sat, 02 Apr 2016 00:32:23 +0300
changeset 432 b3a78fc20b31
parent 431 4ec7d0ea1602
child 433 e8e9a3ddce4f
Add parsing comment syntax.
py/gadict.py
--- a/py/gadict.py	Sat Apr 02 00:26:34 2016 +0300
+++ b/py/gadict.py	Sat Apr 02 00:32:23 2016 +0300
@@ -34,6 +34,8 @@
 class Parser:
     """gadict dictionary format parser."""
 
+    COMMENT_RE = regex.compile(r"^# ")
+
     SEPARATOR_RE = regex.compile(r"^__$")
     HEADWORD_RE = regex.compile(r"^(\p{L}.*)$")
     HEADWORD_VAR_RE = regex.compile(r"^ +(s|pl|v[123]|male|female|comp|super)$")
@@ -57,12 +59,16 @@
         pass
 
     def readline(self):
-        self.line = self.stream.readline()
-        self.eof = len(self.line) == 0
-        if not self.eof:
-            self.lineno += 1
-        if self.TRAILING_SPACES_RE.search(self.line):
-            raise ParseException("Traling spaces detected...\n")
+        while True:
+            self.line = self.stream.readline()
+            self.eof = len(self.line) == 0
+            if not self.eof:
+                self.lineno += 1
+            if self.TRAILING_SPACES_RE.search(self.line):
+                raise ParseException("Traling spaces detected...\n")
+            if self.COMMENT_RE.search(self.line):
+                continue
+            break
 
     def parse(self, stream):
         self.lineno = 0