Skip to content

Commit

Permalink
correctly parse nested braces
Browse files Browse the repository at this point in the history
  • Loading branch information
temporaer committed Jul 20, 2015
1 parent 4641ea4 commit 819ce83
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions latexrun
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ def verbose_cmd(args, cwd=None, env=None):
print(cmd, file=sys.stderr)
verbose_cmd.enabled = False

def nested_parenthesis_end(string, opening, closing):
"""Return index where closing character corresponds to first character"""
stack = []
for i, c in enumerate(string):
if c == opening:
stack.append(i)
elif c == closing and stack:
start = stack.pop()
if not stack:
return i
return -1

class DB:
"""A latexrun control database."""

Expand Down Expand Up @@ -1267,12 +1279,11 @@ class LaTeXFilter:
elif ch == '{':
# TeX uses this for various things we want to ignore, like
# file names and print_mark. Consume up to the '}'
epos = self.__data.find('}', self.__pos)
if epos != -1:
self.__pos = epos + 1
else:
epos = nested_parenthesis_end(self.__data[self.__pos-1:], '{', '}')
if epos == -1:
self.__message('warning', None,
"unbalanced `{' in log; file names may be wrong")
self.__pos += epos + 1
elif ch == '}':
self.__message('warning', None,
"extra `}' in log; file names may be wrong")
Expand Down

0 comments on commit 819ce83

Please sign in to comment.