MCPcopy Index your code
hub / github.com/python/cpython / _study1

Method _study1

Lib/idlelib/pyparse.py:197–329  ·  view source on GitHub ↗

Find the line numbers of non-continuation lines. As quickly as humanly possible , find the line numbers (0- based) of the non-continuation lines. Creates self.{goodlines, continuation}.

(self)

Source from the content-addressed store, hash-verified

195 self.code = self.code[lo:]
196
197 def _study1(self):
198 """Find the line numbers of non-continuation lines.
199
200 As quickly as humanly possible <wink>, find the line numbers (0-
201 based) of the non-continuation lines.
202 Creates self.{goodlines, continuation}.
203 """
204 if self.study_level >= 1:
205 return
206 self.study_level = 1
207
208 # Map all uninteresting characters to "x", all open brackets
209 # to "(", all close brackets to ")", then collapse runs of
210 # uninteresting characters. This can cut the number of chars
211 # by a factor of 10-40, and so greatly speed the following loop.
212 code = self.code
213 code = code.translate(trans)
214 code = code.replace('xxxxxxxx', 'x')
215 code = code.replace('xxxx', 'x')
216 code = code.replace('xx', 'x')
217 code = code.replace('xx', 'x')
218 code = code.replace('\nx', '\n')
219 # Replacing x\n with \n would be incorrect because
220 # x may be preceded by a backslash.
221
222 # March over the squashed version of the program, accumulating
223 # the line numbers of non-continued stmts, and determining
224 # whether & why the last stmt is a continuation.
225 continuation = C_NONE
226 level = lno = 0 # level is nesting level; lno is line number
227 self.goodlines = goodlines = [0]
228 push_good = goodlines.append
229 i, n = 0, len(code)
230 while i < n:
231 ch = code[i]
232 i = i+1
233
234 # cases are checked in decreasing order of frequency
235 if ch == 'x':
236 continue
237
238 if ch == '\n':
239 lno = lno + 1
240 if level == 0:
241 push_good(lno)
242 # else we're in an unclosed bracket structure
243 continue
244
245 if ch == '(':
246 level = level + 1
247 continue
248
249 if ch == ')':
250 if level:
251 level = level - 1
252 # else the program is invalid, but we can't complain
253 continue
254

Callers 3

get_continuation_typeMethod · 0.95
_study2Method · 0.95
get_num_lines_in_stmtMethod · 0.95

Calls 3

translateMethod · 0.45
replaceMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected