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

Method _study2

Lib/idlelib/pyparse.py:335–456  ·  view source on GitHub ↗

study1 was sufficient to determine the continuation status, but doing more requires looking at every character. study2 does this for the last interesting statement in the block. Creates: self.stmt_start, stmt_end slice indices of last int

(self)

Source from the content-addressed store, hash-verified

333 return self.continuation
334
335 def _study2(self):
336 """
337 study1 was sufficient to determine the continuation status,
338 but doing more requires looking at every character. study2
339 does this for the last interesting statement in the block.
340 Creates:
341 self.stmt_start, stmt_end
342 slice indices of last interesting stmt
343 self.stmt_bracketing
344 the bracketing structure of the last interesting stmt; for
345 example, for the statement "say(boo) or die",
346 stmt_bracketing will be ((0, 0), (0, 1), (2, 0), (2, 1),
347 (4, 0)). Strings and comments are treated as brackets, for
348 the matter.
349 self.lastch
350 last interesting character before optional trailing comment
351 self.lastopenbracketpos
352 if continuation is C_BRACKET, index of last open bracket
353 """
354 if self.study_level >= 2:
355 return
356 self._study1()
357 self.study_level = 2
358
359 # Set p and q to slice indices of last interesting stmt.
360 code, goodlines = self.code, self.goodlines
361 i = len(goodlines) - 1 # Index of newest line.
362 p = len(code) # End of goodlines[i]
363 while i:
364 assert p
365 # Make p be the index of the stmt at line number goodlines[i].
366 # Move p back to the stmt at line number goodlines[i-1].
367 q = p
368 for nothing in range(goodlines[i-1], goodlines[i]):
369 # tricky: sets p to 0 if no preceding newline
370 p = code.rfind('\n', 0, p-1) + 1
371 # The stmt code[p:q] isn't a continuation, but may be blank
372 # or a non-indenting comment line.
373 if _junkre(code, p):
374 i = i-1
375 else:
376 break
377 if i == 0:
378 # nothing but junk!
379 assert p == 0
380 q = p
381 self.stmt_start, self.stmt_end = p, q
382
383 # Analyze this stmt, to find the last open bracket (if any)
384 # and last interesting character (if any).
385 lastch = ""
386 stack = [] # stack of open bracket indices
387 push_stack = stack.append
388 bracketing = [(p, 0)]
389 while p < q:
390 # suck up all except ()[]{}'"#\\
391 m = _chew_ordinaryre(code, p, q)
392 if m:

Callers 6

is_block_openerMethod · 0.95
is_block_closerMethod · 0.95

Calls 5

_study1Method · 0.95
rfindMethod · 0.45
endMethod · 0.45
appendMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected