From fdd8a43377f083b54908ec9c9db3a94161ce4820 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Thu, 4 Feb 2016 20:19:59 -0500 Subject: Make _advance a property of FileIter --- BibTeX.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'BibTeX.py') diff --git a/BibTeX.py b/BibTeX.py index 134e007..f8a775e 100644 --- a/BibTeX.py +++ b/BibTeX.py @@ -97,6 +97,11 @@ class FileIter: self.lineno += 1 return self._next() + def advance(self, line): + while not line or line.isspace() or COMMENT_RE.match(line): + line = self.next() + return line + class Parser: """Parser class: reads BibTeX from a file and returns a BibTeX object.""" @@ -127,7 +132,7 @@ class Parser: def _parseKey(self, line): it = self.fileiter - line = _advance(it, line) + line = it.advance(line) m = KEY_RE.match(line) if not m: raise ParseError("Expected key at line %s" % self.fileiter.lineno) @@ -139,7 +144,7 @@ class Parser: bracelevel = 0 data = [] while True: - line = _advance(it, line) + line = it.advance(line) line = line.strip() assert line @@ -219,7 +224,7 @@ class Parser: # Got a string, check for concatenation. if line.isspace() or not line: data.append(" ") - line = _advance(it, line) + line = it.advance(line) line = line.strip() assert line if line[0] == '#': @@ -234,7 +239,7 @@ class Parser: def _parseEntry(self, line): # name, strings, entries it = self.fileiter self.entryLine = it.lineno - line = _advance(it, line) + line = it.advance(line) m = BRACE_BEGIN_RE.match(line) if not m: @@ -245,7 +250,7 @@ class Parser: v = [] while True: - line = _advance(it, line) + line = it.advance(line) m = BRACE_END_RE.match(line) if m: @@ -263,7 +268,7 @@ class Parser: elif proto[0] == 'p': key, line = self._parseKey(line) v.append(key) - line = _advance(it, line) + line = it.advance(line) line = line.lstrip() if line[0] == '=': line = line[1:] @@ -333,10 +338,6 @@ class Parser: % it.lineno) -def _advance(it, line): - while not line or line.isspace() or COMMENT_RE.match(line): - line = it.next() - return line # Matches a comment line outside of an entry. OUTER_COMMENT_RE = re.compile(r'^\s*[\#\%]') -- cgit v1.2.3-70-g09d2