def skipCodeBlock (self,s,i,kind): trace = False ; verbose = True # if trace: g.trace('***',g.callers()) startIndent = self.startSigIndent if trace: g.trace('startIndent',startIndent) assert startIndent is not None i = start = g.skip_ws_and_nl(s,i) parenCount = 0 underIndentedStart = None # The start of trailing underindented blank or comment lines. while i < len(s): progress = i ch = s[i] if g.is_nl(s,i): if trace and verbose: g.trace(g.get_line(s,i)) backslashNewline = (i > 0 and g.match(s,i-1,'\\\n')) if backslashNewline: # An underindented line, including docstring, # does not end the code block. i += 1 # 2010/11/01 else: i = g.skip_nl(s,i) j = g.skip_ws(s,i) if g.is_nl(s,j): pass # We have already made progress. else: i,underIndentedStart,breakFlag = self.pythonNewlineHelper( s,i,parenCount,startIndent,underIndentedStart) if breakFlag: break elif ch == '#': i = g.skip_to_end_of_line(s,i) elif ch == '"' or ch == '\'': i = g.skip_python_string(s,i) elif ch in '[{(': i += 1 ; parenCount += 1 # g.trace('ch',ch,parenCount) elif ch in ']})': i += 1 ; parenCount -= 1 # g.trace('ch',ch,parenCount) else: i += 1 assert(progress < i) # The actual end of the block. if underIndentedStart is not None: i = underIndentedStart if trace: g.trace('***backtracking to underindent range') if trace: g.trace(g.get_line(s,i)) if 0 < i < len(s) and not g.match(s,i-1,'\n'): g.trace('Can not happen: Python block does not end in a newline.') g.trace(g.get_line(s,i)) return i,False # 2010/02/19: Include all following material # until the next 'def' or 'class' i = self.skipToTheNextClassOrFunction(s,i,startIndent) if (trace or self.trace) and s[start:i].strip(): g.trace('%s returns\n' % (kind) + s[start:i]) return i,True
def skipCodeBlock(self, s, i, kind): trace = False verbose = True # if trace: g.trace('***',g.callers()) startIndent = self.startSigIndent if trace: g.trace('startIndent', startIndent) assert startIndent is not None i = start = g.skip_ws_and_nl(s, i) parenCount = 0 underIndentedStart = None # The start of trailing underindented blank or comment lines. while i < len(s): progress = i ch = s[i] if g.is_nl(s, i): if trace and verbose: g.trace(g.get_line(s, i)) backslashNewline = (i > 0 and g.match(s, i - 1, '\\\n')) if backslashNewline: # An underindented line, including docstring, # does not end the code block. i += 1 # 2010/11/01 else: i = g.skip_nl(s, i) j = g.skip_ws(s, i) if g.is_nl(s, j): pass # We have already made progress. else: i, underIndentedStart, breakFlag = self.pythonNewlineHelper( s, i, parenCount, startIndent, underIndentedStart) if breakFlag: break elif ch == '#': i = g.skip_to_end_of_line(s, i) elif ch == '"' or ch == '\'': i = g.skip_python_string(s, i) elif ch in '[{(': i += 1 parenCount += 1 # g.trace('ch',ch,parenCount) elif ch in ']})': i += 1 parenCount -= 1 # g.trace('ch',ch,parenCount) else: i += 1 assert (progress < i) # The actual end of the block. if underIndentedStart is not None: i = underIndentedStart if trace: g.trace('***backtracking to underindent range') if trace: g.trace(g.get_line(s, i)) if 0 < i < len(s) and not g.match(s, i - 1, '\n'): g.trace('Can not happen: Python block does not end in a newline.') g.trace(g.get_line(s, i)) return i, False # 2010/02/19: Include all following material # until the next 'def' or 'class' i = self.skipToTheNextClassOrFunction(s, i, startIndent) if (trace or self.trace) and s[start:i].strip(): g.trace('%s returns\n' % (kind) + s[start:i]) return i, True
def skipInterface(self, s, i): """Skip from the opening delim to *past* the matching closing delim. If no matching is found i is set to len(s)""" trace = False start = i delim2 = "end." level = 0 start = i startIndent = self.startSigIndent if trace: g.trace("***", "startIndent", startIndent, g.callers()) while i < len(s): progress = i if g.is_nl(s, i): backslashNewline = i > 0 and g.match(s, i - 1, "\\\n") i = g.skip_nl(s, i) if not backslashNewline and not g.is_nl(s, i): j, indent = g.skip_leading_ws_with_indent(s, i, self.tab_width) line = g.get_line(s, j) if trace: g.trace("indent", indent, line) if indent < startIndent and line.strip(): # An non-empty underindented line. # Issue an error unless it contains just the closing bracket. if level == 1 and g.match(s, j, delim2): pass else: if j not in self.errorLines: # No error yet given. self.errorLines.append(j) self.underindentedLine(line) elif s[i] in (" ", "\t"): i += 1 # speed up the scan. elif self.startsComment(s, i): i = self.skipComment(s, i) elif self.startsString(s, i): i = self.skipString(s, i) elif g.match(s, i, delim2): i += len(delim2) if trace: g.trace("returns\n", repr(s[start:i])) return i else: i += 1 assert progress < i self.error("no interface") if 1: g.pr("** no interface **") i, j = g.getLine(s, start) g.trace(i, s[i:j]) else: if trace: g.trace("** no interface") return start
def skipInterface(self, s, i): '''Skip from the opening delim to *past* the matching closing delim. If no matching is found i is set to len(s)''' trace = False start = i delim2 = 'end.' level = 0 start = i startIndent = self.startSigIndent if trace: g.trace('***', 'startIndent', startIndent, g.callers()) while i < len(s): progress = i if g.is_nl(s, i): backslashNewline = i > 0 and g.match(s, i - 1, '\\\n') i = g.skip_nl(s, i) if not backslashNewline and not g.is_nl(s, i): j, indent = g.skip_leading_ws_with_indent( s, i, self.tab_width) line = g.get_line(s, j) if trace: g.trace('indent', indent, line) if indent < startIndent and line.strip(): # An non-empty underindented line. # Issue an error unless it contains just the closing bracket. if level == 1 and g.match(s, j, delim2): pass else: if j not in self.errorLines: # No error yet given. self.errorLines.append(j) self.underindentedLine(line) elif s[i] in ( ' ', '\t', ): i += 1 # speed up the scan. elif self.startsComment(s, i): i = self.skipComment(s, i) elif self.startsString(s, i): i = self.skipString(s, i) elif g.match(s, i, delim2): i += len(delim2) if trace: g.trace('returns\n', repr(s[start:i])) return i else: i += 1 assert progress < i self.error('no interface') if 1: g.pr('** no interface **') i, j = g.getLine(s, start) g.trace(i, s[i:j]) else: if trace: g.trace('** no interface') return start
def extendSignature(self, s, i): '''Extend the text to be added to the class node following the signature. The text *must* end with a newline.''' # Add a docstring to the class node, # And everything on the line following it j = g.skip_ws_and_nl(s, i) if g.match(s, j, '"""') or g.match(s, j, "'''"): j = g.skip_python_string(s, j) if j < len(s): # No scanning error. # Return the docstring only if nothing but whitespace follows. j = g.skip_ws(s, j) if g.is_nl(s, j): return j + 1 return i
def skipBlock(self, s, i, delim1, delim2): '''Skip from the opening delim to *past* the matching closing delim. If no matching is found i is set to len(s)''' # pylint: disable=signature-differs trace = False and not g.unitTesting # k1, k2 = g.getLine(s,i) # g.trace(s[i:]) i1, level = i, 0 assert s[i] == delim1, (s[i], delim1, g.callers()) while i < len(s): progress = i ch = s[i] if g.is_nl(s, i): i = g.skip_nl(s, i) elif self.startsComment(s, i): i = self.skipComment(s, i) elif ch in '"\'': i = self.skipString(s, i) elif ch == '/': i = self.skipRegex(s, i) elif ch == delim1: level += 1 i += 1 elif ch == delim2: level -= 1 i += 1 if level <= 0: # g.trace('returns:\n\n%s\n\n' % s[i1: i]) return i else: i += 1 assert progress < i self.error('no block: %s' % i) if trace: i2, j2 = g.getLine(s, i1) g.trace(i, level, s[i2:j2 + 1]) return i
def skipBlock(self, s, i, delim1, delim2): '''Skip from the opening delim to *past* the matching closing delim. If no matching is found i is set to len(s)''' # pylint: disable=signature-differs trace = False and not g.unitTesting # k1, k2 = g.getLine(s,i) # g.trace(s[i:]) i1, level = i, 0 assert s[i] == delim1, (s[i], delim1, g.callers()) while i < len(s): progress = i ch = s[i] if g.is_nl(s, i): i = g.skip_nl(s, i) elif self.startsComment(s, i): i = self.skipComment(s, i) elif ch in '"\'': i = self.skipString(s, i) elif ch == '/': i = self.skipRegex(s, i) elif ch == delim1: level += 1 i += 1 elif ch == delim2: level -= 1 i += 1 if level <= 0: # g.trace('returns:\n\n%s\n\n' % s[i1: i]) return i else: i += 1 assert progress < i self.error('no block: %s' % i) if trace: i2, j2 = g.getLine(s, i1) g.trace(i, level, s[i2:j2+1]) return i