Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e422891

Browse files
committed
Fix the parser so it doesn't silently fail. Speed up by using
pyparsing's packrat feature. svn path=/trunk/matplotlib/; revision=3725
1 parent aca130b commit e422891

2 files changed

Lines changed: 22 additions & 23 deletions

File tree

lib/matplotlib/_mathtext_data.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
r'\bigwedge' : ('cmex10', 4),
3131
r'\bigvee' : ('cmex10', 37),
3232
r'\coprod' : ('cmex10', 42),
33-
r'\sqrt' : ('cmex10', 48),
3433
r'\leftbrace' : ('cmex10', 92),
3534
r'{' : ('cmex10', 92),
3635
r'\{' : ('cmex10', 92),
@@ -317,7 +316,6 @@
317316
r'\Pi' : ('psyr', 213),
318317
r'\prod' : ('psyr', 213),
319318
r'\surd' : ('psyr', 214),
320-
r'\sqrt' : ('psyr', 214),
321319
r'\cdot' : ('psyr', 215),
322320
r'\urcorner' : ('psyr', 216),
323321
r'\vee' : ('psyr', 217),
@@ -2046,7 +2044,6 @@
20462044
'rightzigzagarrow': 8669,
20472045
'rightarrow': 8594,
20482046
'leftarrow': 8592,
2049-
'sqrt': 8730,
20502047
'twoheaddownarrow': 8609,
20512048
'oint': 8750,
20522049
'bigvee': 8897,
@@ -2556,7 +2553,6 @@
25562553
'rightzigzagarrow': 'uni21DD',
25572554
'rightarrow': 'uni2192',
25582555
'leftarrow': 'uni2190',
2559-
'sqrt': 'uni221A',
25602556
'twoheaddownarrow': 'uni21A1',
25612557
'oint': 'uni222E',
25622558
'bigvee': 'uni22C1',

lib/matplotlib/mathtext.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
Combine, Group, Optional, Forward, NotAny, alphas, nums, alphanums, \
144144
StringStart, StringEnd, ParseFatalException, FollowedBy, Regex, \
145145
operatorPrecedence, opAssoc, ParseResults, Or, Suppress, oneOf, \
146-
ParseException, MatchFirst
146+
ParseException, MatchFirst, NoMatch
147147

148148
from matplotlib.afm import AFM
149149
from matplotlib.cbook import enumerate, iterable, Bunch, get_realpath_and_stat, \
@@ -1806,12 +1806,12 @@ def __init__(self):
18061806
+ rbrace
18071807
).setParseAction(self.customspace).setName('customspace')
18081808

1809-
symbol =(Regex(r"[a-zA-Z0-9 +\-*/<>=:,.;!'@()[\]]")
1810-
^ Combine(
1811-
bslash
1812-
+ oneOf(tex2uni.keys())
1813-
)
1814-
).setParseAction(self.symbol).leaveWhitespace()
1809+
symbol =(Regex(r"([a-zA-Z0-9 +\-*/<>=:,.;!'@()])|(\\[%${}\[\]])")
1810+
| Combine(
1811+
bslash
1812+
+ oneOf(tex2uni.keys())
1813+
)
1814+
).setParseAction(self.symbol).leaveWhitespace()
18151815

18161816
accent = Group(
18171817
Combine(bslash + accent)
@@ -1823,7 +1823,7 @@ def __init__(self):
18231823

18241824
group = Group(
18251825
start_group
1826-
+ OneOrMore(
1826+
+ ZeroOrMore(
18271827
autoDelim
18281828
| simple)
18291829
+ end_group
@@ -1907,7 +1907,7 @@ def __init__(self):
19071907

19081908
math = OneOrMore(
19091909
autoDelim
1910-
| simple
1910+
^ simple
19111911
).setParseAction(self.math).setName("math")
19121912

19131913
math_delim =(~bslash
@@ -1916,16 +1916,18 @@ def __init__(self):
19161916
non_math = Regex(r"(?:[^$]|(?:\\\$))*"
19171917
).setParseAction(self.non_math).setName("non_math").leaveWhitespace()
19181918

1919-
self._expression <<(
1920-
non_math
1921-
+ ZeroOrMore(
1922-
Suppress(math_delim)
1923-
+ math
1924-
+ Suppress(math_delim)
1925-
+ non_math
1926-
)
1927-
)
1928-
1919+
self._expression << (
1920+
non_math
1921+
+ ZeroOrMore(
1922+
Suppress(math_delim)
1923+
+ math
1924+
+ Suppress(math_delim)
1925+
+ non_math
1926+
)
1927+
) + StringEnd()
1928+
1929+
self._expression.enablePackrat()
1930+
19291931
self.clear()
19301932

19311933
def clear(self):
@@ -1966,6 +1968,7 @@ def push_state(self):
19661968
self._state_stack.append(self.get_state().copy())
19671969

19681970
def finish(self, s, loc, toks):
1971+
#~ print "finish", toks
19691972
self._expr = Hlist(toks)
19701973
return [self._expr]
19711974

0 commit comments

Comments
 (0)