##// END OF EJS Templates
revset: check invalid function syntax "func-name"() explicitly...
Yuya Nishihara -
r29441:9e8d2587 default
parent child Browse files
Show More
@@ -302,6 +302,11 b' def tokenize(program, lookup=None, symin'
302 302
303 303 # helpers
304 304
305 def getsymbol(x):
306 if x and x[0] == 'symbol':
307 return x[1]
308 raise error.ParseError(_('not a symbol'))
309
305 310 def getstring(x, err):
306 311 if x and (x[0] == 'string' or x[0] == 'symbol'):
307 312 return x[1]
@@ -414,13 +419,14 b' def keyvaluepair(repo, subset, k, v):'
414 419 raise error.ParseError(_("can't use a key-value pair in this context"))
415 420
416 421 def func(repo, subset, a, b):
417 if a[0] == 'symbol' and a[1] in symbols:
418 return symbols[a[1]](repo, subset, b)
422 f = getsymbol(a)
423 if f in symbols:
424 return symbols[f](repo, subset, b)
419 425
420 426 keep = lambda fn: getattr(fn, '__doc__', None) is not None
421 427
422 428 syms = [s for (s, fn) in symbols.items() if keep(fn)]
423 raise error.UnknownIdentifier(a[1], syms)
429 raise error.UnknownIdentifier(f, syms)
424 430
425 431 # functions
426 432
@@ -2304,11 +2310,11 b' def _matchonly(revs, bases):'
2304 2310 """
2305 2311 if (revs is not None
2306 2312 and revs[0] == 'func'
2307 and getstring(revs[1], _('not a symbol')) == 'ancestors'
2313 and getsymbol(revs[1]) == 'ancestors'
2308 2314 and bases is not None
2309 2315 and bases[0] == 'not'
2310 2316 and bases[1][0] == 'func'
2311 and getstring(bases[1][1], _('not a symbol')) == 'ancestors'):
2317 and getsymbol(bases[1][1]) == 'ancestors'):
2312 2318 return ('list', revs[2], bases[1][2])
2313 2319
2314 2320 def _optimize(x, small):
@@ -2419,7 +2425,7 b' def _optimize(x, small):'
2419 2425 ws, ts = zip(*(_optimize(y, small) for y in x[1:]))
2420 2426 return sum(ws), (op,) + ts
2421 2427 elif op == 'func':
2422 f = getstring(x[1], _("not a symbol"))
2428 f = getsymbol(x[1])
2423 2429 wa, ta = _optimize(x[2], small)
2424 2430 if f in ("author branch closed date desc file grep keyword "
2425 2431 "outgoing user"):
@@ -434,6 +434,12 b' quoting needed'
434 434 4
435 435 $ hg book -d date
436 436
437 function name should be a symbol
438
439 $ log '"date"(2005)'
440 hg: parse error: not a symbol
441 [255]
442
437 443 keyword arguments
438 444
439 445 $ log 'extra(branch, value=a)'
@@ -2033,6 +2039,16 b' no crash by empty group "()" while optim'
2033 2039 hg: parse error: missing argument
2034 2040 [255]
2035 2041
2042 invalid function call should not be optimized to only()
2043
2044 $ log '"ancestors"(6) and not ancestors(4)'
2045 hg: parse error: not a symbol
2046 [255]
2047
2048 $ log 'ancestors(6) and not "ancestors"(4)'
2049 hg: parse error: not a symbol
2050 [255]
2051
2036 2052 we can use patterns when searching for tags
2037 2053
2038 2054 $ log 'tag("1..*")'
General Comments 0
You need to be logged in to leave comments. Login now