Revision: 3777
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3777&view=rev
Author:   mdboom
Date:     2007-09-04 12:29:45 -0700 (Tue, 04 Sep 2007)

Log Message:
-----------
Better error messages.

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

Modified: trunk/matplotlib/lib/matplotlib/mathtext.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/mathtext.py 2007-09-04 19:00:18 UTC (rev 
3776)
+++ trunk/matplotlib/lib/matplotlib/mathtext.py 2007-09-04 19:29:45 UTC (rev 
3777)
@@ -138,7 +138,7 @@
      Combine, Group, Optional, Forward, NotAny, alphas, nums, alphanums, \
      StringStart, StringEnd, ParseFatalException, FollowedBy, Regex, \
      operatorPrecedence, opAssoc, ParseResults, Or, Suppress, oneOf, \
-     ParseException, MatchFirst, NoMatch
+     ParseException, MatchFirst, NoMatch, Empty
 
 from matplotlib.afm import AFM
 from matplotlib.cbook import enumerate, iterable, Bunch, 
get_realpath_and_stat, \
@@ -1787,6 +1787,14 @@
 ##############################################################################
 # PARSER
 
+def Error(msg):
+    def raise_error(s, loc, toks):
+        raise ParseFatalException(msg)
+
+    empty = Empty()
+    empty.setParseAction(raise_error)
+    return empty
+    
 class Parser(object):
     _binary_operators = Set(r'''
       + *
@@ -1887,9 +1895,10 @@
                       ).setParseAction(self.space).setName('space')
 
         customspace  =(Literal(r'\hspace')
-                     + lbrace
-                     + float
-                     + rbrace
+                     + (( lbrace
+                        + float
+                        + rbrace
+                       ) | Error(r"Expected \hspace{n}"))
                      ).setParseAction(self.customspace).setName('customspace')
 
         symbol       =(Regex(r"([a-zA-Z0-9 +\-*/<>=:,.;!'@()])|(\\[%${}\[\]])")
@@ -1926,8 +1935,8 @@
                          bslash
                        + Literal("frac")
                        )
-                     + group
-                     + group
+                     + ((group + group)
+                        | Error(r"Expected \frac{num}{den}"))
                      ).setParseAction(self.frac).setName("frac")
 
         sqrt         = Group(
@@ -1946,7 +1955,7 @@
                        + Suppress(Literal("]")),
                          default = None
                        )
-                     + group
+                     + (group | Error("Expected \sqrt{value}"))
                      ).setParseAction(self.sqrt).setName("sqrt")
 
         placeable   <<(accent
@@ -1955,7 +1964,7 @@
                      ^ group
                      ^ frac
                      ^ sqrt
-                     )
+                     ) | Error("Expected symbol or group")
 
         simple      <<(space
                      | customspace  
@@ -1983,12 +1992,12 @@
         leftDelim    = oneOf(r"( [ { \lfloor \langle \lceil")
         rightDelim   = oneOf(r") ] } \rfloor \rangle \rceil")
         autoDelim   <<(Suppress(Literal(r"\left"))
-                     + (leftDelim | ambiDelim)
+                     + ((leftDelim | ambiDelim) | Error("Expected a 
delimiter"))
                      + Group(
                          autoDelim
                        ^ OneOrMore(simple))
                      + Suppress(Literal(r"\right"))
-                     + (rightDelim | ambiDelim)
+                     + ((rightDelim | ambiDelim) | Error("Expected a 
delimiter"))
                      )
 
         math         = OneOrMore(
@@ -2007,7 +2016,8 @@
           + ZeroOrMore(
                 Suppress(math_delim)
               + math
-              + Suppress(math_delim)
+              + (Suppress(math_delim)
+                 | Error("Expected end of math '$'"))
               + non_math
             )  
           ) + StringEnd()


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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to