Mercurial > hg
changeset 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 | 1a6a117d0b95 |
children | 48919d246a47 |
files | mercurial/revset.py tests/test-revset.t |
diffstat | 2 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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.