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
148148from matplotlib .afm import AFM
149149from 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