aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2016-02-04 20:19:59 -0500
committerThibaut Horel <thibaut.horel@gmail.com>2016-02-04 20:19:59 -0500
commitfdd8a43377f083b54908ec9c9db3a94161ce4820 (patch)
tree70946749b9e927bf8b19bd9fdbfae21193274457
parentf555859455c9e9e262f6021dca538c73441093f2 (diff)
downloadanonbib-fdd8a43377f083b54908ec9c9db3a94161ce4820.tar.gz
Make _advance a property of FileIter
-rw-r--r--BibTeX.py21
1 files changed, 11 insertions, 10 deletions
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*[\#\%]')