8000 Use named groups in mathtext parser. · matplotlib/matplotlib@5392fc1 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 5392fc1

Browse files
committed
Use named groups in mathtext parser.
This makes the definitions much easier to read, by removing the need to use Group() and Suppress(): previously, these would be used to nest the parsed tokens and remove the unnecessary ones (e.g, braces), but such tokens can also easily be ignored by giving names to the tokens we use (instead of accessing them by position). (See e.g. the implementation of subsuper, which is also somewhat simplified.) Also remove a few other pyparsing combinators that are not needed: Combine (just concatenate the strings ourselves), FollowedBy (use lookahead regexes), Literal (use plain strings, in particular braces which are very common). Also remove right_delim_safe, as self._right_delim already includes the backslash-escaped closing brace rather than the unescaped one (right_delim_safe dates back to when it didn't). The error message for `a^2_2^2` now changed to "double superscript" as we now simply check for subscripts and superscripts one at a time, and fail when we see either two subscript or two superscripts, emitting the corresponding error.
1 parent a76e037 commit 5392fc1

File tree

2 files changed

+153
-246
lines changed

2 files changed

+153
-246
lines changed

0 commit comments

Comments
 (0)
0