コード例 #1
0
 def _get_pattern(cls):
     if cls._match_pattern is None:
         pattern = codeanalyze.get_comment_pattern() + '|' + \
             codeanalyze.get_string_pattern() + '|' + \
             r'(?P<name>\$\{[^\s\$\}]*\})'
         cls._match_pattern = re.compile(pattern)
     return cls._match_pattern
コード例 #2
0
 def _get_pattern(cls):
     if cls._match_pattern is None:
         pattern = codeanalyze.get_comment_pattern() + '|' + \
                   codeanalyze.get_string_pattern() + '|' + \
                   r'(?P<name>\$\{[^\s\$\}]*\})'
         cls._match_pattern = re.compile(pattern)
     return cls._match_pattern
コード例 #3
0
 def __init__(self, name, docs=False):
     self.name = name
     self.docs = docs
     self.comment_pattern = _TextualFinder.any('comment', [r'#[^\n]*'])
     self.string_pattern = _TextualFinder.any(
         'string', [codeanalyze.get_string_pattern()])
     self.pattern = self._get_occurrence_pattern(self.name)
コード例 #4
0
 def __init__(self, name, docs=False):
     self.name = name
     self.docs = docs
     self.comment_pattern = _TextualFinder.any('comment', [r'#[^\n]*'])
     self.string_pattern = _TextualFinder.any(
         'string', [codeanalyze.get_string_pattern()])
     self.pattern = self._get_occurrence_pattern(self.name)
コード例 #5
0
 def _get_pattern(cls):
     if cls._match_pattern is None:
         pattern = (codeanalyze.get_comment_pattern() + "|" +
                    codeanalyze.get_string_pattern() + "|" +
                    r"(?P<name>\$\{[^\s\$\}]*\})")
         cls._match_pattern = re.compile(pattern)
     return cls._match_pattern
コード例 #6
0
ファイル: patchedast.py プロジェクト: Kha/rope
 def consume_string(self, end=None):
     if _Source._string_pattern is None:
         original = codeanalyze.get_string_pattern()
         pattern = r'(%s)((\s|\\\n|#[^\n]*\n)*(%s))*' % \
                   (original, original)
         _Source._string_pattern = re.compile(pattern)
     repattern = _Source._string_pattern
     return self._consume_pattern(repattern, end)
コード例 #7
0
 def consume_string(self, end=None):
     if _Source._string_pattern is None:
         original = codeanalyze.get_string_pattern()
         pattern = r'(%s)((\s|\\\n|#[^\n]*\n)*(%s))*' % \
                   (original, original)
         _Source._string_pattern = re.compile(pattern)
     repattern = _Source._string_pattern
     return self._consume_pattern(repattern, end)
コード例 #8
0
 def __init__(self, name, docs=False):
     self.name = name
     self.docs = docs
     self.comment_pattern = _TextualFinder.any("comment", [r"#[^\n]*"])
     self.string_pattern = _TextualFinder.any(
         "string", [codeanalyze.get_string_pattern()])
     self.f_string_pattern = _TextualFinder.any(
         "fstring", [codeanalyze.get_formatted_string_pattern()])
     self.pattern = self._get_occurrence_pattern(self.name)
コード例 #9
0
 def consume_string(self, end=None):
     if _Source._string_pattern is None:
         string_pattern = codeanalyze.get_string_pattern()
         formatted_string_pattern = codeanalyze.get_formatted_string_pattern()
         original = r"(?:%s)|(?:%s)" % (string_pattern, formatted_string_pattern)
         pattern = r"(%s)((\s|\\\n|#[^\n]*\n)*(%s))*" % (original, original)
         _Source._string_pattern = re.compile(pattern)
     repattern = _Source._string_pattern
     return self._consume_pattern(repattern, end)
コード例 #10
0
ファイル: similarfinder.py プロジェクト: Kha/rope
 def _get_pattern(cls):
     if cls._match_pattern is None:
         pattern = (
             codeanalyze.get_comment_pattern()
             + "|"
             + codeanalyze.get_string_pattern()
             + "|"
             + r"(?P<name>\$\{[^\s\$\}]*\})"
         )
         cls._match_pattern = re.compile(pattern)
     return cls._match_pattern
コード例 #11
0
ファイル: inline.py プロジェクト: JacekPliszka/rope
    def _get_return_pattern(cls):
        if not hasattr(cls, "_return_pattern"):

            def named_pattern(name, list_):
                return "(?P<%s>" % name + "|".join(list_) + ")"

            comment_pattern = named_pattern("comment", [r"#[^\n]*"])
            string_pattern = named_pattern("string", [codeanalyze.get_string_pattern()])
            return_pattern = r"\b(?P<return>return)\b"
            cls._return_pattern = re.compile(comment_pattern + "|" + string_pattern + "|" + return_pattern)
        return cls._return_pattern
コード例 #12
0
ファイル: inline.py プロジェクト: FredSanders/emacs.d
 def _get_return_pattern(cls):
     if not hasattr(cls, '_return_pattern'):
         def named_pattern(name, list_):
             return "(?P<%s>" % name + "|".join(list_) + ")"
         comment_pattern = named_pattern('comment', [r'#[^\n]*'])
         string_pattern = named_pattern('string',
                                        [codeanalyze.get_string_pattern()])
         return_pattern = r'\b(?P<return>return)\b'
         cls._return_pattern = re.compile(comment_pattern + "|" +
                                          string_pattern + "|" +
                                          return_pattern)
     return cls._return_pattern
コード例 #13
0
 def _get_return_pattern(cls):
     if not hasattr(cls, '_return_pattern'):
         def named_pattern(name, list_):
             return "(?P<%s>" % name + "|".join(list_) + ")"
         comment_pattern = named_pattern('comment', [r'#[^\n]*'])
         string_pattern = named_pattern('string',
                                        [codeanalyze.get_string_pattern()])
         return_pattern = r'\b(?P<return>return)\b'
         cls._return_pattern = re.compile(comment_pattern + "|" +
                                          string_pattern + "|" +
                                          return_pattern)
     return cls._return_pattern
コード例 #14
0
ファイル: simplify.py プロジェクト: 0Chuzz/python-mode
        if source[start] == '#':
            replacement = ' ' * (end - start)
        else:
            replacement = '"%s"' % (' ' * (end - start - 2))
        collector.add_change(start, end, replacement)
    source = collector.get_changed() or source
    collector = codeanalyze.ChangeCollector(source)
    parens = 0
    for match in _parens.finditer(source):
        i = match.start()
        c = match.group()
        if c in '({[':
            parens += 1
        if c in ')}]':
            parens -= 1
        if c == '\n' and parens > 0:
            collector.add_change(i, i + 1, ' ')
    source = collector.get_changed() or source
    return source.replace('\\\n', '  ').replace('\t', ' ').replace(';', '\n')


@utils.cached(7)
def ignored_regions(source):
    """Return ignored regions like strings and comments in `source` """
    return [(match.start(), match.end()) for match in _str.finditer(source)]


_str = re.compile('%s|%s' % (codeanalyze.get_comment_pattern(),
                             codeanalyze.get_string_pattern()))
_parens = re.compile(r'[\({\[\]}\)\n]')
コード例 #15
0
            replacement = ' ' * (end - start)
        else:
            replacement = '"%s"' % (' ' * (end - start - 2))
        collector.add_change(start, end, replacement)
    source = collector.get_changed() or source
    collector = codeanalyze.ChangeCollector(source)
    parens = 0
    for match in _parens.finditer(source):
        i = match.start()
        c = match.group()
        if c in '({[':
            parens += 1
        if c in ')}]':
            parens -= 1
        if c == '\n' and parens > 0:
            collector.add_change(i, i + 1, ' ')
    source = collector.get_changed() or source
    return source.replace('\\\n', '  ').replace('\t', ' ').replace(';', '\n')


@utils.cached(7)
def ignored_regions(source):
    """Return ignored regions like strings and comments in `source` """
    return [(match.start(), match.end()) for match in _str.finditer(source)]


_str = re.compile(
    '%s|%s' %
    (codeanalyze.get_comment_pattern(), codeanalyze.get_string_pattern()))
_parens = re.compile(r'[\({\[\]}\)\n]')