def pythonNewlineHelper(self, s, i, parenCount, startIndent, underIndentedStart): trace = False breakFlag = False j, indent = g.skip_leading_ws_with_indent(s, i, self.tab_width) if trace: g.trace('startIndent', startIndent, 'indent', indent, 'parenCount', parenCount, 'line', repr(g.get_line(s, j))) if indent <= startIndent and parenCount == 0: # An underindented line: it ends the block *unless* # it is a blank or comment line or (2008/9/1) the end of a triple-quoted string. if g.match(s, j, '#'): if trace: g.trace('underindent: comment') if underIndentedStart is None: underIndentedStart = i i = j elif g.match(s, j, '\n'): if trace: g.trace('underindent: blank line') # Blank lines never start the range of underindented lines. i = j else: if trace: g.trace('underindent: end of block') breakFlag = True # The actual end of the block. else: if underIndentedStart and g.match(s, j, '\n'): # Add the blank line to the underindented range. if trace: g.trace( 'properly indented blank line extends underindent range' ) elif underIndentedStart and g.match(s, j, '#'): # Add the (properly indented!) comment line to the underindented range. if trace: g.trace( 'properly indented comment line extends underindent range' ) elif underIndentedStart is None: pass else: # A properly indented non-comment line. # Give a message for all underindented comments in underindented range. if trace: g.trace( 'properly indented line generates underindent errors') s2 = s[underIndentedStart:i] lines = g.splitlines(s2) for line in lines: if line.strip(): junk, indent = g.skip_leading_ws_with_indent( line, 0, self.tab_width) if indent <= startIndent: if j not in self.errorLines: # No error yet given. self.errorLines.append(j) self.underindentedComment(line) underIndentedStart = None if trace: g.trace('breakFlag', breakFlag, 'returns', i, 'underIndentedStart', underIndentedStart) return i, underIndentedStart, breakFlag
def pythonNewlineHelper (self,s,i,parenCount,startIndent,underIndentedStart): trace = False breakFlag = False j, indent = g.skip_leading_ws_with_indent(s,i,self.tab_width) if trace: g.trace( 'startIndent',startIndent,'indent',indent,'parenCount',parenCount, 'line',repr(g.get_line(s,j))) if indent <= startIndent and parenCount == 0: # An underindented line: it ends the block *unless* # it is a blank or comment line or (2008/9/1) the end of a triple-quoted string. if g.match(s,j,'#'): if trace: g.trace('underindent: comment') if underIndentedStart is None: underIndentedStart = i i = j elif g.match(s,j,'\n'): if trace: g.trace('underindent: blank line') # Blank lines never start the range of underindented lines. i = j else: if trace: g.trace('underindent: end of block') breakFlag = True # The actual end of the block. else: if underIndentedStart and g.match(s,j,'\n'): # Add the blank line to the underindented range. if trace: g.trace('properly indented blank line extends underindent range') elif underIndentedStart and g.match(s,j,'#'): # Add the (properly indented!) comment line to the underindented range. if trace: g.trace('properly indented comment line extends underindent range') elif underIndentedStart is None: pass else: # A properly indented non-comment line. # Give a message for all underindented comments in underindented range. if trace: g.trace('properly indented line generates underindent errors') s2 = s[underIndentedStart:i] lines = g.splitlines(s2) for line in lines: if line.strip(): junk, indent = g.skip_leading_ws_with_indent(line,0,self.tab_width) if indent <= startIndent: if j not in self.errorLines: # No error yet given. self.errorLines.append(j) self.underindentedComment(line) underIndentedStart = None if trace: g.trace('breakFlag',breakFlag,'returns',i,'underIndentedStart',underIndentedStart) return i,underIndentedStart,breakFlag
def find_class(self, parent): ''' Find the start and end of a class/def in a node. Return (kind, i, j), where kind in (None, 'class', 'def') ''' # Called from Leo's core to implement two minor commands. prev_state = Python_ScanState() target = Target(parent, prev_state) stack = [target, target] lines = g.splitlines(parent.b) index = 0 for i, line in enumerate(lines): new_state = self.scan_line(line, prev_state) if self.starts_block(i, lines, new_state, prev_state): return self.skip_block(i, index, lines, new_state, stack) prev_state = new_state index += len(line) return None, -1, -1
def find_class(self, parent): ''' Find the start and end of a class/def in a node. Return (kind, i, j), where kind in (None, 'class', 'def') ''' trace = True and not g.unitTesting prev_state = Python_ScanState() target = Target(parent, prev_state) stack = [target, target] lines = g.splitlines(parent.b) index = 0 for i, line in enumerate(lines): new_state = self.scan_line(line, prev_state) if trace: g.trace(new_state) if self.starts_block(i, lines, new_state, prev_state): return self.skip_block(i, index, lines, new_state, stack) prev_state = new_state index += len(line) return None, -1, -1
def undent_by(self, s, undent_val): ''' Remove leading whitespace equivalent to undent_val from each line. Strict languages: prepend the underindent escape for underindented lines. ''' if self.is_rst: return s # Never unindent rst code. result = [] for line in g.splitlines(s): lws_s = self.get_str_lws(line) lws = g.computeWidth(lws_s, self.tab_width) # Add underindentEscapeString only for strict languages. if self.strict and not line.isspace() and lws < undent_val: # End the underindent count with a period to # protect against lines that start with a digit! result.append("%s%s.%s" % ( self.escape, undent_val-lws, line.lstrip())) else: s = g.removeLeadingWhitespace(line, undent_val, self.tab_width) result.append(s) return ''.join(result)
def undent_by(self, s, undent_val): """ Remove leading whitespace equivalent to undent_val from each line. Strict languages: prepend the underindent escape for underindented lines. """ if self.is_rst: return s # Never unindent rst code. result = [] for line in g.splitlines(s): lws_s = self.get_str_lws(line) lws = g.computeWidth(lws_s, self.tab_width) # Add underindentEscapeString only for strict languages. if self.strict and not line.isspace() and lws < undent_val: # End the underindent count with a period to # protect against lines that start with a digit! result.append("%s%s.%s" % ( self.escape, undent_val - lws, line.lstrip())) else: s = g.removeLeadingWhitespace(line, undent_val, self.tab_width) result.append(s) return ''.join(result)
def find_class(self, parent): """ Find the start and end of a class/def in a node. Return (kind, i, j), where kind in (None, 'class', 'def') """ # Called from Leo's core to implement two minor commands. prev_state = Cython_ScanState() target = Target(parent, prev_state) stack = [target] lines = g.splitlines(parent.b) index = 0 for i, line in enumerate(lines): new_state = self.scan_line(line, prev_state) if self.prev_state.context or self.ws_pattern.match( line): # type:ignore pass else: m = self.class_or_def_pattern.match(line) if m: return self.skip_block(i, index, lines, new_state, stack) prev_state = new_state return None, -1, -1