Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc9c04e1

Browse files
committed
Lift Parser.State to toplevel as standalone class.
It doesn't need to be a nested class.
1 parente145328 commitc9c04e1

File tree

1 file changed

+39
-42
lines changed

1 file changed

+39
-42
lines changed

‎lib/matplotlib/_mathtext.py

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Implementation details for :mod:`.mathtext`.
33
"""
44

5+
importcopy
56
fromcollectionsimportnamedtuple
67
importenum
78
importfunctools
@@ -1785,6 +1786,43 @@ def raise_error(s, loc, toks):
17851786
returnempty
17861787

17871788

1789+
classParserState:
1790+
"""
1791+
Parser state.
1792+
1793+
States are pushed and popped from a stack as necessary, and the "current"
1794+
state is always at the top of the stack.
1795+
1796+
Upon entering and leaving a group { } or math/non-math, the stack is pushed
1797+
and popped accordingly.
1798+
"""
1799+
1800+
def__init__(self,font_output,font,font_class,fontsize,dpi):
1801+
self.font_output=font_output
1802+
self._font=font
1803+
self.font_class=font_class
1804+
self.fontsize=fontsize
1805+
self.dpi=dpi
1806+
1807+
defcopy(self):
1808+
returncopy.copy(self)
1809+
1810+
@property
1811+
deffont(self):
1812+
returnself._font
1813+
1814+
@font.setter
1815+
deffont(self,name):
1816+
ifnamein ('rm','it','bf'):
1817+
self.font_class=name
1818+
self._font=name
1819+
1820+
defget_current_underline_thickness(self):
1821+
"""Return the underline thickness for this state."""
1822+
returnself.font_output.get_underline_thickness(
1823+
self.font,self.fontsize,self.dpi)
1824+
1825+
17881826
classParser:
17891827
"""
17901828
A pyparsing-based parser for strings containing math expressions.
@@ -2130,7 +2168,7 @@ def parse(self, s, fonts_object, fontsize, dpi):
21302168
Returns the parse tree of `Node` instances.
21312169
"""
21322170
self._state_stack= [
2133-
self.State(fonts_object,'default','rm',fontsize,dpi)]
2171+
ParserState(fonts_object,'default','rm',fontsize,dpi)]
21342172
self._em_width_cache= {}
21352173
try:
21362174
result=self._expression.parseString(s)
@@ -2144,47 +2182,6 @@ def parse(self, s, fonts_object, fontsize, dpi):
21442182
self._expression.resetCache()
21452183
returnresult[0]
21462184

2147-
# The state of the parser is maintained in a stack. Upon
2148-
# entering and leaving a group { } or math/non-math, the stack
2149-
# is pushed and popped accordingly. The current state always
2150-
# exists in the top element of the stack.
2151-
classState:
2152-
"""
2153-
Stores the state of the parser.
2154-
2155-
States are pushed and popped from a stack as necessary, and
2156-
the "current" state is always at the top of the stack.
2157-
"""
2158-
def__init__(self,font_output,font,font_class,fontsize,dpi):
2159-
self.font_output=font_output
2160-
self._font=font
2161-
self.font_class=font_class
2162-
self.fontsize=fontsize
2163-
self.dpi=dpi
2164-
2165-
defcopy(self):
2166-
returnParser.State(
2167-
self.font_output,
2168-
self.font,
2169-
self.font_class,
2170-
self.fontsize,
2171-
self.dpi)
2172-
2173-
@property
2174-
deffont(self):
2175-
returnself._font
2176-
2177-
@font.setter
2178-
deffont(self,name):
2179-
ifnamein ('rm','it','bf'):
2180-
self.font_class=name
2181-
self._font=name
2182-
2183-
defget_current_underline_thickness(self):
2184-
"""Return the underline thickness for this state."""
2185-
returnself.font_output.get_underline_thickness(
2186-
self.font,self.fontsize,self.dpi)
2187-
21882185
defget_state(self):
21892186
"""Get the current `State` of the parser."""
21902187
returnself._state_stack[-1]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp