self.last_match = self.regex.search(string)
return self.last_match
+ def finditer(self, string):
+ """
+ Alias to re.finditer.
+ """
+
+ return self.regex.finditer(string)
+
def findall(self, string):
"""
Alias to re.findall.
return self.last_match.groups()
+#: Nested delimited pairs (brackets and parenthesis)
+DELIMITER_PAIRS = {
+ '{': '}',
+ '(': ')',
+ '[': ']',
+}
+
+#: compiled delimiters
+RE_DELIM = KernRe(r'[\{\}\[\]\(\)]')
+
class NestedMatch:
"""
#
# FOO(arg1, arg2, arg3)
- DELIMITER_PAIRS = {
- '{': '}',
- '(': ')',
- '[': ']',
- }
-
- RE_DELIM = re.compile(r'[\{\}\[\]\(\)]')
-
def _search(self, regex, line):
"""
Finds paired blocks for a regex that ends with a delimiter.
escape = False
d = line[offset - 1]
- if d not in self.DELIMITER_PAIRS:
+ if d not in DELIMITER_PAIRS:
continue
- end = self.DELIMITER_PAIRS[d]
+ end = DELIMITER_PAIRS[d]
stack.append(end)
- for match in self.RE_DELIM.finditer(line[offset:]):
+ for match in RE_DELIM.finditer(line[offset:]):
pos = match.start() + offset
d = line[pos]
string_char = d
continue
- if d in self.DELIMITER_PAIRS:
- end = self.DELIMITER_PAIRS[d]
+ if d in DELIMITER_PAIRS:
+ end = DELIMITER_PAIRS[d]
stack.append(end)
continue