Revision: 3725
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3725&view=rev
Author:   mdboom
Date:     2007-08-21 12:08:55 -0700 (Tue, 21 Aug 2007)

Log Message:
-----------
Fix the parser so it doesn't silently fail.  Speed up by using
pyparsing's packrat feature.

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/_mathtext_data.py
    trunk/matplotlib/lib/matplotlib/mathtext.py

Modified: trunk/matplotlib/lib/matplotlib/_mathtext_data.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/_mathtext_data.py   2007-08-21 17:25:57 UTC 
(rev 3724)
+++ trunk/matplotlib/lib/matplotlib/_mathtext_data.py   2007-08-21 19:08:55 UTC 
(rev 3725)
@@ -30,7 +30,6 @@
     r'\bigwedge'            : ('cmex10',   4),
     r'\bigvee'              : ('cmex10',  37),
     r'\coprod'              : ('cmex10',  42),
-    r'\sqrt'                : ('cmex10',  48),
     r'\leftbrace'           : ('cmex10',  92),
     r'{'                    : ('cmex10',  92),
     r'\{'                   : ('cmex10',  92),
@@ -317,7 +316,6 @@
     r'\Pi'              : ('psyr', 213),
     r'\prod'            : ('psyr', 213),
     r'\surd'            : ('psyr', 214),
-    r'\sqrt'            : ('psyr', 214),
     r'\cdot'            : ('psyr', 215),
     r'\urcorner'        : ('psyr', 216),
     r'\vee'             : ('psyr', 217),
@@ -2046,7 +2044,6 @@
 'rightzigzagarrow': 8669,
 'rightarrow': 8594,
 'leftarrow': 8592,
-'sqrt': 8730,
 'twoheaddownarrow': 8609,
 'oint': 8750,
 'bigvee': 8897,
@@ -2556,7 +2553,6 @@
 'rightzigzagarrow': 'uni21DD',
 'rightarrow': 'uni2192',
 'leftarrow': 'uni2190',
-'sqrt': 'uni221A',
 'twoheaddownarrow': 'uni21A1',
 'oint': 'uni222E',
 'bigvee': 'uni22C1',

Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-21 17:25:57 UTC (rev 
3724)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-08-21 19:08:55 UTC (rev 
3725)
@@ -143,7 +143,7 @@
      Combine, Group, Optional, Forward, NotAny, alphas, nums, alphanums, \
      StringStart, StringEnd, ParseFatalException, FollowedBy, Regex, \
      operatorPrecedence, opAssoc, ParseResults, Or, Suppress, oneOf, \
-     ParseException, MatchFirst
+     ParseException, MatchFirst, NoMatch
 
 from matplotlib.afm import AFM
 from matplotlib.cbook import enumerate, iterable, Bunch, 
get_realpath_and_stat, \
@@ -1806,12 +1806,12 @@
                      + rbrace
                      ).setParseAction(self.customspace).setName('customspace')
 
-        symbol       =(Regex(r"[a-zA-Z0-9 +\-*/<>=:,.;!'@()[\]]")
-                     ^  Combine(
-                          bslash
-                        + oneOf(tex2uni.keys())
-                        )
-                      ).setParseAction(self.symbol).leaveWhitespace()
+        symbol       =(Regex(r"([a-zA-Z0-9 +\-*/<>=:,.;!'@()])|(\\[%${}\[\]])")
+                     | Combine(
+                         bslash
+                       + oneOf(tex2uni.keys())
+                       )
+                     ).setParseAction(self.symbol).leaveWhitespace()
 
         accent       = Group(
                          Combine(bslash + accent)
@@ -1823,7 +1823,7 @@
 
         group        = Group(
                          start_group
-                       + OneOrMore(
+                       + ZeroOrMore(
                            autoDelim
                          | simple)
                        + end_group
@@ -1907,7 +1907,7 @@
 
         math         = OneOrMore(
                        autoDelim
-                     | simple
+                     ^ simple
                      ).setParseAction(self.math).setName("math")
 
         math_delim   =(~bslash
@@ -1916,16 +1916,18 @@
         non_math     = Regex(r"(?:[^$]|(?:\\\$))*"
                      
).setParseAction(self.non_math).setName("non_math").leaveWhitespace()
 
-        self._expression <<(
-                         non_math
-                       + ZeroOrMore(
-                           Suppress(math_delim)
-                         + math
-                         + Suppress(math_delim)
-                         + non_math
-                         )
-                       )
+        self._expression << (
+            non_math
+          + ZeroOrMore(
+                Suppress(math_delim)
+              + math
+              + Suppress(math_delim)
+              + non_math
+            )  
+          ) + StringEnd()
 
+        self._expression.enablePackrat()
+        
         self.clear()
 
     def clear(self):
@@ -1966,6 +1968,7 @@
         self._state_stack.append(self.get_state().copy())
 
     def finish(self, s, loc, toks):
+        #~ print "finish", toks
         self._expr = Hlist(toks)
         return [self._expr]
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to