Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 57fda4f

Browse filesBrowse files
devRDksunden
andcommitted
Add unclosed group to grammar
Co-authored-by: Kyle Sunden <git@ksunden.space>
1 parent 69d796a commit 57fda4f
Copy full SHA for 57fda4f

File tree

2 files changed

+9
-2
lines changed
Filter options

2 files changed

+9
-2
lines changed

‎lib/matplotlib/_mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_mathtext.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,8 @@ def csnames(group, names):
18651865
"|".join(map(re.escape, tex2uni)))
18661866
)("sym").leaveWhitespace()
18671867
p.unknown_symbol = Regex(r"\\[A-Za-z]+")("name")
1868+
def unclosed_group(self, s, loc, toks):
1869+
raise ParseFatalException(s, len(s), "Expected '}'")
18681870

18691871
p.font = csnames("font", self._fontnames)
18701872
p.start_group = Optional(r"\math" + oneOf(self._fontnames)("font")) + "{"
@@ -1894,6 +1896,7 @@ def csnames(group, names):
18941896
p.function = csnames("name", self._function_names)
18951897

18961898
p.group = p.start_group + ZeroOrMore(p.token)("group") + p.end_group
1899+
p.unclosed_group = (p.start_group + ZeroOrMore(p.token)("group") + StringEnd())
18971900

18981901
p.frac = cmd(r"\frac", p.required_group("num") + p.required_group("den"))
18991902
p.dfrac = cmd(r"\dfrac", p.required_group("num") + p.required_group("den"))
@@ -1942,6 +1945,7 @@ def csnames(group, names):
19421945
p.token <<= (
19431946
p.simple
19441947
| p.auto_delim
1948+
| p.unclosed_group
19451949
| p.unknown_symbol # Must be last
19461950
)
19471951

@@ -2145,6 +2149,9 @@ def symbol(self, s, loc, toks):
21452149
def unknown_symbol(self, s, loc, toks):
21462150
raise ParseFatalException(s, loc, f"Unknown symbol: {toks['name']}")
21472151

2152+
def unclosed_group(self, s, loc, toks):
2153+
raise ParseFatalException(s, len(s), "Expected '}'")
2154+
21482155
_accent_map = {
21492156
r'hat': r'\circumflexaccent',
21502157
r'breve': r'\combiningbreve',

‎lib/matplotlib/tests/test_mathtext.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_mathtext.py
+2-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.