コード例 #1
0
ファイル: python.py プロジェクト: chiamingyen/kmol2016
    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
コード例 #2
0
ファイル: python.py プロジェクト: pmills/leo-editor
 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
コード例 #3
0
ファイル: python.py プロジェクト: hanseychen/leo-editor
    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
コード例 #4
0
ファイル: python.py プロジェクト: pmills/leo-editor
    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
コード例 #5
0
ファイル: python.py プロジェクト: hanseychen/leo-editor
 def skipString(self, s, i):
     # Returns len(s) on unterminated string.
     return g.skip_python_string(s, i, verbose=False)
コード例 #6
0
ファイル: python.py プロジェクト: pmills/leo-editor
 def skipString(self, s, i):
     # Returns len(s) on unterminated string.
     return g.skip_python_string(s, i, verbose=False)
コード例 #7
0
ファイル: dart.py プロジェクト: chiamingyen/kmol2016
 def skipString(self, s, i):
     """Skip a string, including a Python triple string."""
     # Returns len(s) on unterminated string.
     return g.skip_python_string(s, i, verbose=False)
コード例 #8
0
 def skipString (self,s,i):
     '''Skip a string, including a Python triple string.'''
     # Returns len(s) on unterminated string.
     return g.skip_python_string(s,i,verbose=False)