Skip to content

Commit da3eead

Browse files
committed
correctly parse nested braces
1 parent 53dfe90 commit da3eead

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

latexrun

+15-4
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,18 @@ def verbose_cmd(args, cwd=None, env=None):
221221
print(cmd, file=sys.stderr)
222222
verbose_cmd.enabled = False
223223

224+
def nested_parenthesis_end(string, opening, closing):
225+
"""Return index where closing character corresponds to opening character"""
226+
stack = []
227+
for i, c in enumerate(string):
228+
if c == opening:
229+
stack.append(i)
230+
elif c == closing and stack:
231+
start = stack.pop()
232+
if not stack:
233+
return i
234+
return -1
235+
224236
class DB:
225237
"""A latexrun control database."""
226238

@@ -1267,12 +1279,11 @@ class LaTeXFilter:
12671279
elif ch == '{':
12681280
# TeX uses this for various things we want to ignore, like
12691281
# file names and print_mark. Consume up to the '}'
1270-
epos = self.__data.find('}', self.__pos)
1271-
if epos != -1:
1272-
self.__pos = epos + 1
1273-
else:
1282+
epos = nested_parenthesis_end(self.__data[self.__pos-1:], '{', '}')
1283+
if epos == -1:
12741284
self.__message('warning', None,
12751285
"unbalanced `{' in log; file names may be wrong")
1286+
self.__pos += epos + 1
12761287
elif ch == '}':
12771288
self.__message('warning', None,
12781289
"extra `}' in log; file names may be wrong")

0 commit comments

Comments
 (0)