1919
2020import numpy as np
2121from pyparsing import (
22- Empty , Forward , Literal , NotAny , oneOf , OneOrMore , Optional ,
22+ Empty , Forward , Literal , NotAny , one_of , OneOrMore , Optional ,
2323 ParseBaseException , ParseException , ParseExpression , ParseFatalException ,
2424 ParserElement , ParseResults , QuotedString , Regex , StringEnd , ZeroOrMore ,
2525 pyparsing_common , Group )
3434from packaging .version import parse as parse_version
3535from pyparsing import __version__ as pyparsing_version
3636if parse_version (pyparsing_version ).major < 3 :
37- from pyparsing import nestedExpr as nested_expr
37+ from pyparsing import nested_expr as nested_expr
3838else :
3939 from pyparsing import nested_expr
4040
4141if T .TYPE_CHECKING :
4242 from collections .abc import Iterable
4343 from .ft2font import Glyph
4444
45- ParserElement .enablePackrat ()
45+ ParserElement .enable_packrat ()
4646_log = logging .getLogger ("matplotlib.mathtext" )
4747
4848
@@ -1745,7 +1745,7 @@ def Error(msg: str) -> ParserElement:
17451745 def raise_error (s : str , loc : int , toks : ParseResults ) -> T .Any :
17461746 raise ParseFatalException (s , loc , msg )
17471747
1748- return Empty ().setParseAction (raise_error )
1748+ return Empty ().set_parse_action (raise_error )
17491749
17501750
17511751class ParserState :
@@ -1981,10 +1981,10 @@ def set_names_and_parse_actions() -> None:
19811981 # token, placeable, and auto_delim are forward references which
19821982 # are left without names to ensure useful error messages
19831983 if key not in ("token" , "placeable" , "auto_delim" ):
1984- val .setName (key )
1984+ val .set_name (key )
19851985 # Set actions
19861986 if hasattr (self , key ):
1987- val .setParseAction (getattr (self , key ))
1987+ val .set_parse_action (getattr (self , key ))
19881988
19891989 # Root definitions.
19901990
@@ -2007,24 +2007,24 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
20072007 )
20082008
20092009 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" )
20112011
2012- p .style_literal = oneOf (
2012+ p .style_literal = one_of (
20132013 [str (e .value ) for e in self ._MathStyle ])("style_literal" )
20142014
20152015 p .symbol = Regex (
20162016 r"[a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|\U00000080-\U0001ffff]"
20172017 r"|\\[%${}\[\]_|]"
20182018 + r"|\\(?:{})(?![A-Za-z])" .format (
20192019 "|" .join (map (re .escape , tex2uni )))
2020- )("sym" ).leaveWhitespace ()
2020+ )("sym" ).leave_whitespace ()
20212021 p .unknown_symbol = Regex (r"\\[A-Za-z]+" )("name" )
20222022
20232023 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" )) + "{"
20252025 p .end_group = Literal ("}" )
20262026
2027- p .delim = oneOf (self ._delims )
2027+ p .delim = one_of (self ._delims )
20282028
20292029 # Mutually recursive definitions. (Minimizing the number of Forward
20302030 # elements is important for speed.)
@@ -2085,7 +2085,7 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
20852085 r"\underset" ,
20862086 p .optional_group ("annotation" ) + p .optional_group ("body" ))
20872087
2088- p .text = cmd (r"\text" , QuotedString ('{' , '\\ ' , endQuoteChar = "}" ))
2088+ p .text = cmd (r"\text" , QuotedString ('{' , '\\ ' , end_quote_char = "}" ))
20892089
20902090 p .substack = cmd (r"\substack" ,
20912091 nested_expr (opener = "{" , closer = "}" ,
@@ -2094,7 +2094,7 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
20942094
20952095 p .subsuper = (
20962096 (Optional (p .placeable )("nucleus" )
2097- + OneOrMore (oneOf (["_" , "^" ]) - p .placeable )("subsuper" )
2097+ + OneOrMore (one_of (["_" , "^" ]) - p .placeable )("subsuper" )
20982098 + Regex ("'*" )("apostrophes" ))
20992099 | Regex ("'+" )("apostrophes" )
21002100 | (p .named_placeable ("nucleus" ) + Regex ("'*" )("apostrophes" ))
@@ -2143,8 +2143,8 @@ def csnames(group: str, names: Iterable[str]) -> Regex:
21432143
21442144 # Leaf definitions.
21452145 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 ()
21482148 p .main = (
21492149 p .non_math + ZeroOrMore (p .math_string + p .non_math ) + StringEnd ()
21502150 )
@@ -2167,15 +2167,15 @@ def parse(self, s: str, fonts_object: Fonts, fontsize: float, dpi: float) -> Hli
21672167 ParserState (fonts_object , 'default' , 'rm' , fontsize , dpi )]
21682168 self ._em_width_cache : dict [tuple [str , float , float ], float ] = {}
21692169 try :
2170- result = self ._expression .parseString (s )
2170+ result = self ._expression .parse_string (s )
21712171 except ParseBaseException as err :
21722172 # explain becomes a plain method on pyparsing 3 (err.explain(0)).
21732173 raise ValueError ("\n " + ParseException .explain (err , 0 )) from None
21742174 self ._state_stack = []
21752175 self ._in_subscript_or_superscript = False
21762176 # prevent operator spacing from leaking into a new expression
21772177 self ._em_width_cache = {}
2178- ParserElement .resetCache ()
2178+ ParserElement .reset_cache ()
21792179 return T .cast (Hlist , result [0 ]) # Known return type from main.
21802180
21812181 def get_state (self ) -> ParserState :
@@ -2191,13 +2191,13 @@ def push_state(self) -> None:
21912191 self ._state_stack .append (self .get_state ().copy ())
21922192
21932193 def main (self , toks : ParseResults ) -> list [Hlist ]:
2194- return [Hlist (toks .asList ())]
2194+ return [Hlist (toks .as_list ())]
21952195
21962196 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 )
21982198
21992199 def math (self , toks : ParseResults ) -> T .Any :
2200- hlist = Hlist (toks .asList ())
2200+ hlist = Hlist (toks .as_list ())
22012201 self .pop_state ()
22022202 return [hlist ]
22032203
@@ -2210,7 +2210,7 @@ def non_math(self, toks: ParseResults) -> T.Any:
22102210 self .get_state ().font = mpl .rcParams ['mathtext.default' ]
22112211 return [hlist ]
22122212
2213- float_literal = staticmethod (pyparsing_common .convertToFloat )
2213+ float_literal = staticmethod (pyparsing_common .convert_to_float )
22142214
22152215 def text (self , toks : ParseResults ) -> T .Any :
22162216 self .push_state ()
@@ -2809,7 +2809,7 @@ def auto_delim(self, toks: ParseResults) -> T.Any:
28092809 return self ._auto_sized_delimiter (
28102810 toks ["left" ],
28112811 # 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 [],
28132813 toks ["right" ])
28142814
28152815 def boldsymbol (self , toks : ParseResults ) -> T .Any :
0 commit comments