comparison mercurial/revset.py @ 25704:70a2082f855a

revset: add parsing rule for key=value pair It will be used as an keyword argument. Note that our "=" operator is left-associative. In general, the assignment operator is right-associative, but we don't care because it isn't allowed to chain "=" operations.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 27 Jun 2015 17:05:28 +0900
parents 1cce81121472
children 48919d246a47
comparison
equal deleted inserted replaced
25703:1a6a117d0b95 25704:70a2082f855a
131 "&": (5, None, ("and", 5)), 131 "&": (5, None, ("and", 5)),
132 "%": (5, None, ("only", 5), ("onlypost", 5)), 132 "%": (5, None, ("only", 5), ("onlypost", 5)),
133 "or": (4, None, ("or", 4)), 133 "or": (4, None, ("or", 4)),
134 "|": (4, None, ("or", 4)), 134 "|": (4, None, ("or", 4)),
135 "+": (4, None, ("or", 4)), 135 "+": (4, None, ("or", 4)),
136 "=": (3, None, ("keyvalue", 3)),
136 ",": (2, None, ("list", 2)), 137 ",": (2, None, ("list", 2)),
137 ")": (0, None, None), 138 ")": (0, None, None),
138 "symbol": (0, ("symbol",), None), 139 "symbol": (0, ("symbol",), None),
139 "string": (0, ("string",), None), 140 "string": (0, ("string",), None),
140 "end": (0, None, None), 141 "end": (0, None, None),
188 yield ('..', None, pos) 189 yield ('..', None, pos)
189 pos += 1 # skip ahead 190 pos += 1 # skip ahead
190 elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully 191 elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully
191 yield ('##', None, pos) 192 yield ('##', None, pos)
192 pos += 1 # skip ahead 193 pos += 1 # skip ahead
193 elif c in "():,-|&+!~^%": # handle simple operators 194 elif c in "():=,-|&+!~^%": # handle simple operators
194 yield (c, None, pos) 195 yield (c, None, pos)
195 elif (c in '"\'' or c == 'r' and 196 elif (c in '"\'' or c == 'r' and
196 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings 197 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
197 if c == 'r': 198 if c == 'r':
198 pos += 1 199 pos += 1
385 def notset(repo, subset, x): 386 def notset(repo, subset, x):
386 return subset - getset(repo, subset, x) 387 return subset - getset(repo, subset, x)
387 388
388 def listset(repo, subset, a, b): 389 def listset(repo, subset, a, b):
389 raise error.ParseError(_("can't use a list in this context")) 390 raise error.ParseError(_("can't use a list in this context"))
391
392 def keyvaluepair(repo, subset, k, v):
393 raise error.ParseError(_("can't use a key-value pair in this context"))
390 394
391 def func(repo, subset, a, b): 395 def func(repo, subset, a, b):
392 if a[0] == 'symbol' and a[1] in symbols: 396 if a[0] == 'symbol' and a[1] in symbols:
393 return symbols[a[1]](repo, subset, b) 397 return symbols[a[1]](repo, subset, b)
394 398
2178 "symbol": stringset, 2182 "symbol": stringset,
2179 "and": andset, 2183 "and": andset,
2180 "or": orset, 2184 "or": orset,
2181 "not": notset, 2185 "not": notset,
2182 "list": listset, 2186 "list": listset,
2187 "keyvalue": keyvaluepair,
2183 "func": func, 2188 "func": func,
2184 "ancestor": ancestorspec, 2189 "ancestor": ancestorspec,
2185 "parent": parentspec, 2190 "parent": parentspec,
2186 "parentpost": p1, 2191 "parentpost": p1,
2187 } 2192 }