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

Method compute_backslash_indent

Lib/idlelib/pyparse.py:499–554  ·  view source on GitHub ↗

Return number of spaces the next line should be indented. Line continuation must be C_BACKSLASH. Also assume that the new line is the first one following the initial line of the stmt.

(self)

Source from the content-addressed store, hash-verified

497 return goodlines[-1] - goodlines[-2]
498
499 def compute_backslash_indent(self):
500 """Return number of spaces the next line should be indented.
501
502 Line continuation must be C_BACKSLASH. Also assume that the new
503 line is the first one following the initial line of the stmt.
504 """
505 self._study2()
506 assert self.continuation == C_BACKSLASH
507 code = self.code
508 i = self.stmt_start
509 while code[i] in " \t":
510 i = i+1
511 startpos = i
512
513 # See whether the initial line starts an assignment stmt; i.e.,
514 # look for an = operator
515 endpos = code.find('\n', startpos) + 1
516 found = level = 0
517 while i < endpos:
518 ch = code[i]
519 if ch in "([{":
520 level = level + 1
521 i = i+1
522 elif ch in ")]}":
523 if level:
524 level = level - 1
525 i = i+1
526 elif ch == '"' or ch == "'":
527 i = _match_stringre(code, i, endpos).end()
528 elif ch == '#':
529 # This line is unreachable because the # makes a comment of
530 # everything after it.
531 break
532 elif level == 0 and ch == '=' and \
533 (i == 0 or code[i-1] not in "=<>!") and \
534 code[i+1] != '=':
535 found = 1
536 break
537 else:
538 i = i+1
539
540 if found:
541 # found a legit =, but it may be the last interesting
542 # thing on the line
543 i = i+1 # move beyond the =
544 found = re.match(r"\s*\\", code[i:endpos]) is None
545
546 if not found:
547 # oh well ... settle for moving beyond the first chunk
548 # of non-whitespace chars
549 i = startpos
550 while code[i] not in " \t\n":
551 i = i+1
552
553 return len(code[self.stmt_start:i].expandtabs(\
554 self.tabwidth)) + 1
555
556 def get_base_indent_string(self):

Callers 1

Calls 5

_study2Method · 0.95
findMethod · 0.45
endMethod · 0.45
matchMethod · 0.45
expandtabsMethod · 0.45

Tested by

no test coverage detected