# HG changeset patch # User Yuya Nishihara # Date 1435392328 -32400 # Node ID 70a2082f855af06c0a1ae240806ecf6598e54c40 # Parent 1a6a117d0b95a7d41e54009467287ac83c652084 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. diff -r 1a6a117d0b95 -r 70a2082f855a mercurial/revset.py --- a/mercurial/revset.py Sun Jun 28 12:46:34 2015 -0700 +++ b/mercurial/revset.py Sat Jun 27 17:05:28 2015 +0900 @@ -133,6 +133,7 @@ "or": (4, None, ("or", 4)), "|": (4, None, ("or", 4)), "+": (4, None, ("or", 4)), + "=": (3, None, ("keyvalue", 3)), ",": (2, None, ("list", 2)), ")": (0, None, None), "symbol": (0, ("symbol",), None), @@ -190,7 +191,7 @@ elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully yield ('##', None, pos) pos += 1 # skip ahead - elif c in "():,-|&+!~^%": # handle simple operators + elif c in "():=,-|&+!~^%": # handle simple operators yield (c, None, pos) elif (c in '"\'' or c == 'r' and program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings @@ -388,6 +389,9 @@ def listset(repo, subset, a, b): raise error.ParseError(_("can't use a list in this context")) +def keyvaluepair(repo, subset, k, v): + raise error.ParseError(_("can't use a key-value pair in this context")) + def func(repo, subset, a, b): if a[0] == 'symbol' and a[1] in symbols: return symbols[a[1]](repo, subset, b) @@ -2180,6 +2184,7 @@ "or": orset, "not": notset, "list": listset, + "keyvalue": keyvaluepair, "func": func, "ancestor": ancestorspec, "parent": parentspec, diff -r 1a6a117d0b95 -r 70a2082f855a tests/test-revset.t --- a/tests/test-revset.t Sun Jun 28 12:46:34 2015 -0700 +++ b/tests/test-revset.t Sat Jun 27 17:05:28 2015 +0900 @@ -322,6 +322,17 @@ 4 $ hg book -d date +keyword arguments + + $ try 'foo=bar|baz' + (keyvalue + ('symbol', 'foo') + (or + ('symbol', 'bar') + ('symbol', 'baz'))) + hg: parse error: can't use a key-value pair in this context + [255] + Test that symbols only get parsed as functions if there's an opening parenthesis.