예제 #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 _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
예제 #4
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
예제 #5
0
        if replacement is not None:
            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(), match.groupdict())
            for match in _str.finditer(source)]


_str = re.compile("|".join([
    codeanalyze.get_comment_pattern(),
    codeanalyze.get_any_string_pattern(),
]))
_parens = re.compile(r"[\({\[\]}\)\n]")
예제 #6
0
        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]')
예제 #7
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]')