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.
--- a/mercurial/revset.py Tue Mar 18 17:19:44 2014 -0500
+++ b/mercurial/revset.py Tue Mar 18 17:54:42 2014 -0500
@@ -178,7 +178,7 @@
pos += 1
while pos < l: # find end of symbol
d = program[pos]
- if not (d.isalnum() or d in "._/@" or ord(d) > 127):
+ if not (d.isalnum() or d in "-._/@" or ord(d) > 127):
break
if d == '.' and program[pos - 1] == '.': # special case for ..
pos -= 1
@@ -187,6 +187,22 @@
sym = program[s:pos]
if sym in keywords: # operator keywords
yield (sym, None, s)
+ elif '-' in sym:
+ # some jerk gave us foo-bar-baz, try to check if it's a symbol
+ if lookup and lookup(sym):
+ # looks like a real symbol
+ yield ('symbol', sym, s)
+ else:
+ # looks like an expression
+ parts = sym.split('-')
+ for p in parts[:-1]:
+ if p: # possible consecutive -
+ yield ('symbol', p, s)
+ s += len(p)
+ yield ('-', None, pos)
+ s += 1
+ if parts[-1]: # possible trailing -
+ yield ('symbol', parts[-1], s)
else:
yield ('symbol', sym, s)
pos -= 1