8000 Use delimited list to parse substack · matplotlib/matplotlib@a48e51b · GitHub
[go: up one dir, main page]

Skip to content

Commit a48e51b

Browse files
ksundendevRD
authored andcommitted
Use delimited list to parse substack
1 parent cefc54e commit a48e51b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import numpy as np
1616
from pyparsing import (
17-
Empty, Forward, Literal, NotAny, oneOf, OneOrMore, Optional,
17+
Empty, Forward, Literal, NotAny, oneOf, OneOrMore, Optional, delimited_list,
1818
ParseBaseException, ParseException, ParseExpression, ParseFatalException,
1919
ParserElement, ParseResults, QuotedString, Regex, StringEnd, ZeroOrMore,
2020
pyparsing_common)
@@ -1700,6 +1700,7 @@ def names(elt):
17001700
csname = expr.split("{", 1)[0]
17011701
err = (csname + "".join("{%s}" % name for name in names(args))
17021702
if expr == csname else expr)
1703+
print(csname, args, err)
17031704
return csname - (args | Error(f"Expected {err}"))
17041705

17051706

@@ -1855,7 +1856,7 @@ def csnames(group, names):
18551856
+ r"|\\(?:{})(?![A-Za-z])".format(
18561857
"|".join(map(re.escape, tex2uni)))
18571858
)("sym").leaveWhitespace()
1858-
p.unknown_symbol = Regex(r"\\[A-Za-z]*")("name")
1859+
p.unknown_symbol = Regex(r"\\[A-Za-z]+")("name")
18591860

18601861
p.font = csnames("font", self._fontnames)
18611862
p.start_group = Optional(r"\math" + oneOf(self._fontnames)("font")) + "{"
@@ -1935,7 +1936,7 @@ def csnames(group, names):
19351936
p.operatorname = cmd(r"\operatorname", "{" + ZeroOrMore(p.simple)("name") + "}")
19361937

19371938
p.substack <<= cmd(
1938-
r"\substack", OneOrMore(p.required_group("value")))
1939+
r"\substack", "{"+delimited_list(OneOrMore(p.token), delim="\\\\", combine=True)("parts")+"}")
19391940

19401941
p.placeable <<= (
19411942
p.accent # Must be before symbol as all accents are symbols
@@ -1952,8 +1953,8 @@ def csnames(group, names):
19521953
| p.underset
19531954
| p.sqrt
19541955
| p.overline
1955-
| p.text
19561956
| p.substack
1957+
| p.text
19571958
)
19581959

19591960
p.auto_delim <<= (
@@ -1976,6 +1977,7 @@ def csnames(group, names):
19761977

19771978
# To add space to nucleus operators after sub/superscripts
19781979
self._in_subscript_or_superscript = False
1980+
self.p = p
19791981

19801982
def parse(self, s, fonts_object, fontsize, dpi):
19811983
"""
@@ -2604,13 +2606,17 @@ def auto_delim(self, s, loc, toks):
26042606
toks["right"])
26052607

26062608
def substack(self, s, loc, toks):
2609+
print(list(toks.keys()))
2610+
print(toks["parts"])
2611+
parts = toks["parts"].split("\\\\")
2612+
print(parts)
26072613
state = self.get_state()
26082614
thickness = state.get_current_underline_thickness()
26092615
vlist = []
26102616

2611-
max_width = max(map(lambda c: c.width, toks[1:]))
2617+
max_width = max(map(lambda c: c.width, parts))
26122618

2613-
for sub in toks[1:]:
2619+
for sub in parts:
26142620
cp = HCentered([sub])
26152621
cp.hpack(max_width, 'exactly')
26162622
vlist.append(cp)

0 commit comments

Comments
 (0)
0