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

Commit713919d

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

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
@@ -1777,6 +1778,43 @@ def raise_error(s, loc, toks):
17771778
returnempty
17781779

17791780

1781+
classParserState:
1782+
"""
1783+
Parser state.
1784+
1785+
States are pushed and popped from a stack as necessary, and the "current"
1786+
state is always at the top of the stack.
1787+
1788+
Upon entering and leaving a group { } or math/non-math, the stack is pushed
1789+
and popped accordingly.
1790+
"""
1791+
1792+
def__init__(self,font_output,font,font_class,fontsize,dpi):
1793+
self.font_output=font_output
1794+
self._font=font
1795+
self.font_class=font_class
1796+
self.fontsize=fontsize
1797+
self.dpi=dpi
1798+
1799+
defcopy(self):
1800+
returncopy.copy(self)
1801+
1802+
@property
1803+
deffont(self):
1804+
returnself._font
1805+
1806+
@font.setter
1807+
deffont(self,name):
1808+
ifnamein ('rm','it','bf'):
1809+
self.font_class=name
1810+
self._font=name
1811+
1812+
defget_current_underline_thickness(self):
1813+
"""Return the underline thickness for this state."""
1814+
returnself.font_output.get_underline_thickness(
1815+
self.font,self.fontsize,self.dpi)
1816+
1817+
17801818
classParser:
17811819
"""
17821820
A pyparsing-based parser for strings containing math expressions.
@@ -2122,7 +2160,7 @@ def parse(self, s, fonts_object, fontsize, dpi):
21222160
Returns the parse tree of `Node` instances.
21232161
"""
21242162
self._state_stack= [
2125-
self.State(fonts_object,'default','rm',fontsize,dpi)]
2163+
ParserState(fonts_object,'default','rm',fontsize,dpi)]
21262164
self._em_width_cache= {}
21272165
try:
21282166
result=self._expression.parseString(s)
@@ -2136,47 +2174,6 @@ def parse(self, s, fonts_object, fontsize, dpi):
21362174
self._expression.resetCache()
21372175
returnresult[0]
21382176

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp