MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Whitespace

Class Whitespace

tools/python-3.11.9-amd64/Lib/tabnanny.py:134–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132 print("%r: Clean bill of health." % (file,))
133
134class Whitespace:
135 # the characters used for space and tab
136 S, T = ' \t'
137
138 # members:
139 # raw
140 # the original string
141 # n
142 # the number of leading whitespace characters in raw
143 # nt
144 # the number of tabs in raw[:n]
145 # norm
146 # the normal form as a pair (count, trailing), where:
147 # count
148 # a tuple such that raw[:n] contains count[i]
149 # instances of S * i + T
150 # trailing
151 # the number of trailing spaces in raw[:n]
152 # It's A Theorem that m.indent_level(t) ==
153 # n.indent_level(t) for all t >= 1 iff m.norm == n.norm.
154 # is_simple
155 # true iff raw[:n] is of the form (T*)(S*)
156
157 def __init__(self, ws):
158 self.raw = ws
159 S, T = Whitespace.S, Whitespace.T
160 count = []
161 b = n = nt = 0
162 for ch in self.raw:
163 if ch == S:
164 n = n + 1
165 b = b + 1
166 elif ch == T:
167 n = n + 1
168 nt = nt + 1
169 if b >= len(count):
170 count = count + [0] * (b - len(count) + 1)
171 count[b] = count[b] + 1
172 b = 0
173 else:
174 break
175 self.n = n
176 self.nt = nt
177 self.norm = tuple(count), b
178 self.is_simple = len(count) <= 1
179
180 # return length of longest contiguous run of spaces (whether or not
181 # preceding a tab)
182 def longest_run_of_spaces(self):
183 count, trailing = self.norm
184 return max(len(count)-1, trailing)
185
186 def indent_level(self, tabsize):
187 # count, il = self.norm
188 # for i in range(len(count)):
189 # if count[i]:
190 # il = il + (i//tabsize + 1)*tabsize * count[i]
191 # return il

Callers 1

process_tokensFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected