19
19
20
20
import numpy as np
21
21
from pyparsing import (
22
- Empty , Forward , Literal , NotAny , oneOf , OneOrMore , Optional ,
22
+ Empty , Forward , Literal , NotAny , one_of , OneOrMore , Optional ,
23
23
ParseBaseException , ParseException , ParseExpression , ParseFatalException ,
24
24
ParserElement , ParseResults , QuotedString , Regex , StringEnd , ZeroOrMore ,
25
25
pyparsing_common , Group )
34
34
from packaging .version import parse as parse_version
35
35
from pyparsing import __version__ as pyparsing_version
36
36
if parse_version (pyparsing_version ).major < 3 :
37
- from pyparsing import nestedExpr as nested_expr
37
+ from pyparsing import nested_expr as nested_expr
38
38
else :
39
39
from pyparsing import nested_expr
40
40
41
41
if T .TYPE_CHECKING :
42
42
from collections .abc import Iterable
43
43
from .ft2font import Glyph
44
44
45
- ParserElement .enablePackrat ()
45
+ ParserElement .enable_packrat ()
46
46
_log = logging .getLogger ("matplotlib.mathtext" )
47
47
48
48
@@ -1745,7 +1745,7 @@ def Error(msg: str) -> ParserElement:
1745
1745
def raise_error (s : str , loc : int , toks : ParseResults ) -> T .Any :
1746
1746
raise ParseFatalException (s , loc , msg )
1747
1747
1748
- return Empty ().setParseAction (raise_error )
1748
+ return Empty ().set_parse_action (raise_error )
1749
1749
1750
1750
1751
1751
class ParserState :
@@ -1981,10 +1981,10 @@ def set_names_and_parse_actions() -> None:
1981
1981
# token, placeable, and auto_delim are forward references which
1982
1982
# are left without names to ensure useful error messages
1983
1983
if key not in ("token" , "placeable" , "auto_delim" ):
1984
- val .setName (key )
1984
+ val .set_name (key )
1985
1985
# Set actions
1986
1986
if hasattr (self , key ):
1987
- val .setParseAction (getattr (self , key ))
1987
+ val .set_parse_action (getattr (self , key ))
1988
1988
1989
1989
# Root definitions.
1990
1990
@@ -2007,24 +2007,24 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
2007
2007
)
2008
2008
2009
2009
p .float_literal = Regex (r"[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)" )
2010
- p .space = oneOf (self ._space_widths )("space" )
2010
+ p .space = one_of (self ._space_widths )("space" )
2011
2011
2012
- p .style_literal = oneOf (
2012
+ p .style_literal = one_of (
2013
2013
[str (e .value ) for e in self ._MathStyle ])("style_literal" )
2014
2014
2015
2015
p .symbol = Regex (
2016
2016
r"[a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|\U00000080-\U0001ffff]"
2017
2017
r"|\\[%${}\[\]_|]"
2018
2018
+ r"|\\(?:{})(?![A-Za-z])" .format (
2019
2019
"|" .join (map (re .escape , tex2uni )))
2020
- )("sym" ).leaveWhitespace ()
2020
+ )("sym" ).leave_whitespace ()
2021
2021
p .unknown_symbol = Regex (r"\\[A-Za-z]+" )("name" )
2022
2022
2023
2023
p .font = csnames ("font" , self ._fontnames )
2024
- p .start_group = Optional (r"\math" + oneOf (self ._fontnames )("font" )) + "{"
2024
+ p .start_group = Optional (r"\math" + one_of (self ._fontnames )("font" )) + "{"
2025
2025
p .end_group = Literal ("}" )
2026
2026
2027
- p .delim = oneOf (self ._delims )
2027
+ p .delim = one_of (self ._delims )
2028
2028
2029
2029
# Mutually recursive definitions. (Minimizing the number of Forward
2030
2030
# elements is important for speed.)
@@ -2085,7 +2085,7 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
2085
2085
r"\underset" ,
2086
2086
p .optional_group ("annotation" ) + p .optional_group ("body" ))
2087
2087
2088
- p .text = cmd (r"\text" , QuotedString ('{' , '\\ ' , endQuoteChar = "}" ))
2088
+ p .text = cmd (r"\text" , QuotedString ('{' , '\\ ' , end_quote_char = "}" ))
2089
2089
2090
2090
p .substack = cmd (r"\substack" ,
2091
2091
nested_expr (opener = "{" , closer = "}" ,
@@ -2094,7 +2094,7 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
2094
2094
2095
2095
p .subsuper = (
2096
2096
(Optional (p .placeable )("nucleus" )
2097
- + OneOrMore (oneOf (["_" , "^" ]) - p .placeable )("subsuper" )
2097
+ + OneOrMore (one_of (["_" , "^" ]) - p .placeable )("subsuper" )
2098
2098
+ Regex ("'*" )("apostrophes" ))
2099
2099
| Regex ("'+" )("apostrophes" )
2100
2100
| (p .named_placeable ("nucleus" ) + Regex ("'*" )("apostrophes" ))
@@ -2143,8 +2143,8 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
2143
2143
2144
2144
# Leaf definitions.
2145
2145
p .math = OneOrMore (p .token )
2146
- p .math_string = QuotedString ('$' , '\\ ' , unquoteResults = False )
2147
- p .non_math = Regex (r"(?:(?:\\[$])|[^$])*" ).leaveWhitespace ()
2146
+ p .math_string = QuotedString ('$' , '\\ ' , unquote_results = False )
2147
+ p .non_math = Regex (r"(?:(?:\\[$])|[^$])*" ).leave_whitespace ()
2148
2148
p .main = (
2149
2149
p .non_math + ZeroOrMore (p .math_string + p .non_math ) + StringEnd ()
2150
2150
)
@@ -2167,15 +2167,15 @@ def parse(self, s: str, fonts_object: Fonts, fontsize: float, dpi: float) -> Hli
2167
2167
ParserState (fonts_object , 'default' , 'rm' , fontsize , dpi )]
2168
2168
self ._em_width_cache : dict [tuple [str , float , float ], float ] = {}
2169
2169
try :
2170
- result = self ._expression .parseString (s )
2170
+ result = self ._expression .parse_string (s )
2171
2171
except ParseBaseException as err :
2172
2172
# explain becomes a plain method on pyparsing 3 (err.explain(0)).
2173
2173
raise ValueError ("\n " + ParseException .explain (err , 0 )) from None
2174
2174
self ._state_stack = []
2175
2175
self ._in_subscript_or_superscript = False
2176
2176
# prevent operator spacing from leaking into a new expression
2177
2177
self ._em_width_cache = {}
2178
- ParserElement .resetCache ()
2178
+ ParserElement .reset_cache ()
2179
2179
return T .cast (Hlist , result [0 ]) # Known return type from main.
2180
2180
2181
2181
def get_state (self ) -> ParserState :
@@ -2191,13 +2191,13 @@ def push_state(self) -> None:
2191
2191
self ._state_stack .append (self .get_state ().copy ())
2192
2192
2193
2193
def main (self , toks : ParseResults ) -> list [Hlist ]:
2194
- return [Hlist (toks .asList ())]
2194
+ return [Hlist (toks .as_list ())]
2195
2195
2196
2196
def math_string (self , toks : ParseResults ) -> ParseResults :
2197
- return self ._math_expression .parseString (toks [0 ][1 :- 1 ], parseAll = True )
2197
+ return self ._math_expression .parse_string (toks [0 ][1 :- 1 ], parse_all = True )
2198
2198
2199
2199
def math (self , toks : ParseResults ) -> T .Any :
2200
- hlist = Hlist (toks .asList ())
2200
+ hlist = Hlist (toks .as_list ())
2201
2201
self .pop_state ()
2202
2202
return [hlist ]
2203
2203
@@ -2210,7 +2210,7 @@ def non_math(self, toks: ParseResults) -> T.Any:
2210
2210
self .get_state ().font = mpl .rcParams ['mathtext.default' ]
2211
2211
return [hlist ]
2212
2212
2213
- float_literal = staticmethod (pyparsing_common .convertToFloat )
2213
+ float_literal = staticmethod (pyparsing_common .convert_to_float )
2214
2214
2215
2215
def text (self , toks : ParseResults ) -> T .Any :
2216
2216
self .push_state ()
@@ -2809,7 +2809,7 @@ def auto_delim(self, toks: ParseResults) -> T.Any:
2809
2809
return self ._auto_sized_delimiter (
2810
2810
toks ["left" ],
2811
2811
# if "mid" in toks ... can be removed when requiring pyparsing 3.
2812
- toks ["mid" ].asList () if "mid" in toks else [],
2812
+ toks ["mid" ].as_list () if "mid" in toks else [],
2813
2813
toks ["right" ])
2814
2814
2815
2815
def boldsymbol (self , toks : ParseResults ) -> T .Any :
0 commit comments