Skip to content

Commit 7f65d6b

Browse files
devRDksunden
andcommitted
Add unclosed group to grammar
Co-authored-by: Kyle Sunden <git@ksunden.space>
1 parent 69d796a commit 7f65d6b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,7 @@ def csnames(group, names):
18941894
p.function = csnames("name", self._function_names)
18951895

18961896
p.group = p.start_group + ZeroOrMore(p.token)("group") + p.end_group
1897+
p.unclosed_group = (p.start_group + ZeroOrMore(p.token)("group") + StringEnd())
18971898

18981899
p.frac = cmd(r"\frac", p.required_group("num") + p.required_group("den"))
18991900
p.dfrac = cmd(r"\dfrac", p.required_group("num") + p.required_group("den"))
@@ -1942,6 +1943,7 @@ def csnames(group, names):
19421943
p.token <<= (
19431944
p.simple
19441945
| p.auto_delim
1946+
| p.unclosed_group
19451947
| p.unknown_symbol # Must be last
19461948
)
19471949

@@ -2251,6 +2253,9 @@ def end_group(self, s, loc, toks):
22512253
self.pop_state()
22522254
return []
22532255

2256+
def unclosed_group(self, s, loc, toks):
2257+
raise ParseFatalException(s, len(s), "Expected '}'")
2258+
22542259
def font(self, s, loc, toks):
22552260
self.get_state().font = toks["font"]
22562261
return []

lib/matplotlib/tests/test_mathtext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_fontinfo():
320320
(r'$a^2^2$', r'Double superscript'),
321321
(r'$a_2_2$', r'Double subscript'),
322322
(r'$a^2_a^2$', r'Double superscript'),
323-
(r'$a = {b$', r'Expected end of text'),
323+
(r'$a = {b$', r"Expected '}'"),
324324
],
325325
ids=[
326326
'hspace without value',
@@ -349,7 +349,7 @@ def test_fontinfo():
349349
'double superscript',
350350
'double subscript',
351351
'super on sub without braces',
352-
'math string with no closing braces'
352+
'unclosed group'
353353
]
354354
)
355355
def test_mathtext_exceptions(math, msg):

0 commit comments

Comments
 (0)