Revision: 4725
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4725&view=rev
Author: mdboom
Date: 2007-12-13 10:13:49 -0800 (Thu, 13 Dec 2007)
Log Message:
-----------
Minor speedup in mathtext parsing.
Modified Paths:
--------------
branches/transforms/lib/matplotlib/mathtext.py
Modified: branches/transforms/lib/matplotlib/mathtext.py
===================================================================
--- branches/transforms/lib/matplotlib/mathtext.py 2007-12-13 18:13:04 UTC
(rev 4724)
+++ branches/transforms/lib/matplotlib/mathtext.py 2007-12-13 18:13:49 UTC
(rev 4725)
@@ -147,7 +147,9 @@
from matplotlib.pyparsing import Combine, Group, Optional, Forward, \
Literal, OneOrMore, ZeroOrMore, ParseException, Empty, \
ParseResults, Suppress, oneOf, StringEnd, ParseFatalException, \
- FollowedBy, Regex
+ FollowedBy, Regex, ParserElement
+# Enable packrat parsing
+ParserElement.enablePackrat()
from matplotlib.afm import AFM
from matplotlib.cbook import Bunch, get_realpath_and_stat, \
@@ -1982,7 +1984,7 @@
autoDelim = Forward().setParseAction(self.auto_sized_delimiter)
self._expression =
Forward().setParseAction(self.finish).setName("finish")
- float = Regex(r"-?[0-9]+\.?[0-9]*")
+ float = Regex(r"-?[0-9]*(\.[0-9]+)?")
lbrace = Literal('{').suppress()
rbrace = Literal('}').suppress()
@@ -2001,14 +2003,13 @@
latex2efont = oneOf(['math' + x for x in self._fontnames])
space =(FollowedBy(bslash)
- + (Literal(r'\ ')
- | Literal(r'\/')
- | Literal(r'\,')
- | Literal(r'\;')
- | Literal(r'\quad')
- | Literal(r'\qquad')
- | Literal(r'\!')
- )
+ + oneOf([r'\ ',
+ r'\/',
+ r'\,',
+ r'\;',
+ r'\quad',
+ r'\qquad',
+ r'\!'])
).setParseAction(self.space).setName('space')
customspace =(Literal(r'\hspace')
@@ -2055,19 +2056,13 @@
+ latex2efont)
frac = Group(
- Suppress(
- bslash
- + Literal("frac")
- )
+ Suppress(Literal(r"\frac"))
+ ((group + group)
| Error(r"Expected \frac{num}{den}"))
).setParseAction(self.frac).setName("frac")
sqrt = Group(
- Suppress(
- bslash
- + Literal("sqrt")
- )
+ Suppress(Literal(r"\sqrt"))
+ Optional(
Suppress(Literal("["))
+ Group(
@@ -2096,9 +2091,7 @@
| subsuper
)
- subsuperop =(Literal("_")
- | Literal("^")
- )
+ subsuperop = oneOf(["_", "^"])
subsuper << Group(
( Optional(placeable)
@@ -2127,8 +2120,7 @@
^ simple
).setParseAction(self.math).setName("math")
- math_delim =(~bslash
- + Literal('$'))
+ math_delim = ~bslash + Literal('$')
non_math = Regex(r"(?:(?:\\[$])|[^$])*"
).setParseAction(self.non_math).setName("non_math").leaveWhitespace()
@@ -2144,8 +2136,6 @@
)
) + StringEnd()
- self._expression.enablePackrat()
-
self.clear()
def clear(self):
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins