Skip to content

Commit 3547bab

Browse files
committed
optionally look for mismatched [{()}]
1 parent dd0629f commit 3547bab

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

latexrun

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def main():
7979
action=ArgParserWarnAction, dest='nowarns', default=set(['underfull']),
8080
help='Enable/disable warning from CLASS, which can be any package name, '
8181
'LaTeX warning class (e.g., font), bad box type '
82-
'(underfull, overfull, loose, tight), or "all"')
82+
'(underfull, overfull, loose, tight), strict parsing (strict-parse), or "all"')
8383
arg_parser.add_argument(
8484
'-O', metavar='DIR', dest='obj_dir', default='latex.out',
8585
help='Directory for intermediate files and control database '
@@ -230,14 +230,17 @@ def mkdir_p(path):
230230
pass
231231
else: raise
232232

233-
def nested_parenthesis_end(string, opening, closing):
233+
def nested_parenthesis_end(string, opening, closing, lax_checking=False):
234234
"""Return index where closing character corresponds to opening character"""
235235
stack = []
236236
for i, c in enumerate(string):
237-
if c == opening:
238-
stack.append(i)
239-
elif c == closing and stack:
240-
start = stack.pop()
237+
if c in opening:
238+
stack.append(c)
239+
elif c in closing and stack:
240+
start_ch = stack.pop()
241+
if not lax_checking and opening.index(start_ch) != closing.index(c):
242+
# Mismatch, e.g. expected ')', found '}'
243+
return -1
241244
if not stack:
242245
return i
243246
return -1
@@ -1288,7 +1291,11 @@ class LaTeXFilter:
12881291
elif ch == '{':
12891292
# TeX uses this for various things we want to ignore, like
12901293
# file names and print_mark. Consume up to the '}'
1291-
epos = nested_parenthesis_end(self.__data[self.__pos-1:], '{', '}')
1294+
lax_checking = False
1295+
if "strict-parse" in self.__suppress:
1296+
lax_checking = not self.__suppress["strict-parse"]
1297+
epos = nested_parenthesis_end(self.__data[self.__pos-1:], '{[(', '}])',
1298+
lax_checking=lax_checking)
12921299
if epos == -1:
12931300
self.__message('warning', None,
12941301
"unbalanced `{' in log; file names may be wrong")

0 commit comments

Comments
 (0)