diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2016-02-04 20:32:19 -0500 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2016-02-04 20:32:19 -0500 |
| commit | 4a3c68678479474d1323b1f49b06541bc0b3c4bd (patch) | |
| tree | fc2f0f51a55f4d48f63600145d8e0cb944ff1758 | |
| parent | fdd8a43377f083b54908ec9c9db3a94161ce4820 (diff) | |
| download | anonbib-4a3c68678479474d1323b1f49b06541bc0b3c4bd.tar.gz | |
Shadow advance method from FileIter
| -rw-r--r-- | BibTeX.py | 41 |
1 files changed, 18 insertions, 23 deletions
@@ -130,9 +130,12 @@ class Parser: self.litStringLine = 0 self.entryLine = 0 + def advance(self, line): + return self.fileiter.advance(line) + + def _parseKey(self, line): - it = self.fileiter - line = it.advance(line) + line = self.advance(line) m = KEY_RE.match(line) if not m: raise ParseError("Expected key at line %s" % self.fileiter.lineno) @@ -140,19 +143,17 @@ class Parser: return key, line def _parseValue(self, line): - it = self.fileiter bracelevel = 0 data = [] while True: - line = it.advance(line) - line = line.strip() + line = self.advance(line).strip() assert line # Literal string? if line[0] == '"': line = line[1:] - self.litStringLine = it.lineno - while 1: + self.litStringLine = self.fileiter.lineno + while True: if bracelevel: m = BRACE_CLOSE_RE.match(line) if m: @@ -175,7 +176,7 @@ class Parser: continue data.append(line) data.append(" ") - line = it.next() + line = self.fileiter.next() self.litStringLine = 0 elif line[0] == '{': bracelevel += 1 @@ -202,7 +203,7 @@ class Parser: # print bracelevel, "C", repr(line) data.append(line) data.append(" ") - line = it.next() + line = self.fileiter.next() elif line[0] == '#': print >>sys.stderr, "Weird concat on line %s" % it.lineno elif line[0] in "},": @@ -224,8 +225,7 @@ class Parser: # Got a string, check for concatenation. if line.isspace() or not line: data.append(" ") - line = it.advance(line) - line = line.strip() + line = self.advance(line).strip() assert line if line[0] == '#': line = line[1:] @@ -237,9 +237,8 @@ class Parser: return data, line def _parseEntry(self, line): # name, strings, entries - it = self.fileiter - self.entryLine = it.lineno - line = it.advance(line) + self.entryLine = self.fileiter.lineno + line = self.advance(line) m = BRACE_BEGIN_RE.match(line) if not m: @@ -250,7 +249,7 @@ class Parser: v = [] while True: - line = it.advance(line) + line = self.advance(line) m = BRACE_END_RE.match(line) if m: @@ -268,8 +267,7 @@ class Parser: elif proto[0] == 'p': key, line = self._parseKey(line) v.append(key) - line = it.advance(line) - line = line.lstrip() + line = self.advance(line).strip() if line[0] == '=': line = line[1:] value, line = self._parseValue(line) @@ -320,12 +318,11 @@ class Parser: return self.result def _parse(self): - it = self.fileiter - line = it.next() + line = self.fileiter.next() while 1: # Skip blank lines. while not line or line.isspace() or OUTER_COMMENT_RE.match(line): - line = it.next() + line = self.fileiter.next() # Get the first line of an entry. m = ENTRY_BEGIN_RE.match(line) if m: @@ -335,9 +332,7 @@ class Parser: self.entryLine = 0 else: raise ParseError("Bad input at line %s (expected a new entry.)" - % it.lineno) - - + % self.fileiter.lineno) # Matches a comment line outside of an entry. OUTER_COMMENT_RE = re.compile(r'^\s*[\#\%]') |
