comparison mercurial/revset.py @ 20780:403f1f73d30f

revset: try to handle hyphenated symbols if lookup callback is available Formerly an expression like "2.4-rc::" was tokenized as 2.4|-|rc|::. This allows dashes in symbols iff the whole symbol-like string can be looked up. Otherwise, it's tokenized as a series of symbols and operators. No attempt is made to accept dashed symbols inside larger symbol-like string, for instance foo-bar or bar-baz inside foo-bar-baz.
author Matt Mackall <mpm@selenic.com>
date Tue, 18 Mar 2014 17:54:42 -0500
parents ffc2295c6b80
children 3210b7930899
comparison
equal deleted inserted replaced
20779:ffc2295c6b80 20780:403f1f73d30f
176 elif c.isalnum() or c in '._@' or ord(c) > 127: 176 elif c.isalnum() or c in '._@' or ord(c) > 127:
177 s = pos 177 s = pos
178 pos += 1 178 pos += 1
179 while pos < l: # find end of symbol 179 while pos < l: # find end of symbol
180 d = program[pos] 180 d = program[pos]
181 if not (d.isalnum() or d in "._/@" or ord(d) > 127): 181 if not (d.isalnum() or d in "-._/@" or ord(d) > 127):
182 break 182 break
183 if d == '.' and program[pos - 1] == '.': # special case for .. 183 if d == '.' and program[pos - 1] == '.': # special case for ..
184 pos -= 1 184 pos -= 1
185 break 185 break
186 pos += 1 186 pos += 1
187 sym = program[s:pos] 187 sym = program[s:pos]
188 if sym in keywords: # operator keywords 188 if sym in keywords: # operator keywords
189 yield (sym, None, s) 189 yield (sym, None, s)
190 elif '-' in sym:
191 # some jerk gave us foo-bar-baz, try to check if it's a symbol
192 if lookup and lookup(sym):
193 # looks like a real symbol
194 yield ('symbol', sym, s)
195 else:
196 # looks like an expression
197 parts = sym.split('-')
198 for p in parts[:-1]:
199 if p: # possible consecutive -
200 yield ('symbol', p, s)
201 s += len(p)
202 yield ('-', None, pos)
203 s += 1
204 if parts[-1]: # possible trailing -
205 yield ('symbol', parts[-1], s)
190 else: 206 else:
191 yield ('symbol', sym, s) 207 yield ('symbol', sym, s)
192 pos -= 1 208 pos -= 1
193 else: 209 else:
194 raise error.ParseError(_("syntax error"), pos) 210 raise error.ParseError(_("syntax error"), pos)