eric6/ThirdParty/EditorConfig/editorconfig/fnmatch.py

changeset 7981
89e8d8d8a9b5
parent 6996
7d5a103bdb76
equal deleted inserted replaced
7980:2c3f14a3c595 7981:89e8d8d8a9b5
26 _cache = {} 26 _cache = {}
27 27
28 LEFT_BRACE = re.compile( 28 LEFT_BRACE = re.compile(
29 r""" 29 r"""
30 30
31 (?: ^ | [^\\] ) # Beginning of string or a character besides "\" 31 (?<! \\ ) # Not preceded by "\"
32 32
33 \{ # "{" 33 \{ # "{"
34 34
35 """, re.VERBOSE 35 """, re.VERBOSE
36 ) 36 )
37 37
38 RIGHT_BRACE = re.compile( 38 RIGHT_BRACE = re.compile(
39 r""" 39 r"""
40 40
41 (?: ^ | [^\\] ) # Beginning of string or a character besides "\" 41 (?<! \\ ) # Not preceded by "\"
42 42
43 \} # "}" 43 \} # "}"
44 44
45 """, re.VERBOSE 45 """, re.VERBOSE
46 ) 46 )
133 if pos < length and pat[pos] == '*': 133 if pos < length and pat[pos] == '*':
134 result += '.*' 134 result += '.*'
135 else: 135 else:
136 result += '[^/]*' 136 result += '[^/]*'
137 elif current_char == '?': 137 elif current_char == '?':
138 result += '.' 138 result += '[^/]'
139 elif current_char == '[': 139 elif current_char == '[':
140 if in_brackets: 140 if in_brackets:
141 result += '\\[' 141 result += '\\['
142 else: 142 else:
143 pos = index 143 pos = index
146 if pat[pos] == '/' and pat[pos-1] != '\\': 146 if pat[pos] == '/' and pat[pos-1] != '\\':
147 has_slash = True 147 has_slash = True
148 break 148 break
149 pos += 1 149 pos += 1
150 if has_slash: 150 if has_slash:
151 result += '\\[' + pat[index:(pos + 1)] + '\\]' 151 result += '\\[' + pat[index:(pos + 1)]
152 index = pos + 2 152 index = pos + 1
153 else: 153 else:
154 if index < length and pat[index] in '!^': 154 if index < length and pat[index] in '!^':
155 index += 1 155 index += 1
156 result += '[^' 156 result += '[^'
157 else: 157 else:
161 if in_brackets: 161 if in_brackets:
162 result += current_char 162 result += current_char
163 else: 163 else:
164 result += '\\' + current_char 164 result += '\\' + current_char
165 elif current_char == ']': 165 elif current_char == ']':
166 result += current_char 166 if in_brackets and pat[index-2] == '\\':
167 in_brackets = False 167 result += '\\]'
168 else:
169 result += current_char
170 in_brackets = False
168 elif current_char == '{': 171 elif current_char == '{':
169 pos = index 172 pos = index
170 has_comma = False 173 has_comma = False
171 while pos < length and (pat[pos] != '}' or is_escaped): 174 while pos < length and (pat[pos] != '}' or is_escaped):
172 if pat[pos] == ',' and not is_escaped: 175 if pat[pos] == ',' and not is_escaped:
176 pos += 1 179 pos += 1
177 if not has_comma and pos < length: 180 if not has_comma and pos < length:
178 num_range = NUMERIC_RANGE.match(pat[index:pos]) 181 num_range = NUMERIC_RANGE.match(pat[index:pos])
179 if num_range: 182 if num_range:
180 numeric_groups.append(map(int, num_range.groups())) 183 numeric_groups.append(map(int, num_range.groups()))
181 result += "([+-]?\d+)" 184 result += r"([+-]?\d+)"
182 else: 185 else:
183 inner_result, inner_groups = translate(pat[index:pos], 186 inner_result, inner_groups = translate(pat[index:pos],
184 nested=True) 187 nested=True)
185 result += '\\{%s\\}' % (inner_result,) 188 result += '\\{%s\\}' % (inner_result,)
186 numeric_groups += inner_groups 189 numeric_groups += inner_groups
214 result += re.escape(current_char) 217 result += re.escape(current_char)
215 is_escaped = not is_escaped 218 is_escaped = not is_escaped
216 else: 219 else:
217 is_escaped = False 220 is_escaped = False
218 if not nested: 221 if not nested:
219 result += '\Z(?ms)' 222 result = r'(?s)%s\Z' % result
220 return result, numeric_groups 223 return result, numeric_groups

eric ide

mercurial