From patchwork Sun Sep 24 12:21:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6, of, 8] templater: adjust binding strength of '%' and '|' operators (BC) From: Yuya Nishihara X-Patchwork-Id: 24132 Message-Id: <078f9566d9a9cdab1f4c.1506255715@mimosa> To: mercurial-devel@mercurial-scm.org Date: Sun, 24 Sep 2017 21:21:55 +0900 # HG changeset patch # User Yuya Nishihara # Date 1493037431 -32400 # Mon Apr 24 21:37:11 2017 +0900 # Node ID 078f9566d9a9cdab1f4c9c116f12ce5cec5a392a # Parent 669f28277c7b70f9f58d252bf4e57f84aff2268e templater: adjust binding strength of '%' and '|' operators (BC) This makes 'foo|bar%baz' parsed as '(foo|bar)%baz', not 'foo|(bar%baz)'. Perhaps it was a mistake that '%' preceded '|'. Both '|' and '%' can be considered a kind of function application, and '|' is more like a '.' operator seen in OO languages. So IMHO '|' should have the same (or higher) binding as '%'. The BC breakage should be minimal since both '|' and '%' operators have strict requirements for their operands and 'foo|bar%baz' was invalid: - right-hand side of '|' must be a symbol - left-hand side of '%' must be a dict or list - right-hand side of '%' must be a string or symbol diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -34,7 +34,7 @@ from . import ( elements = { # token-type: binding-strength, primary, prefix, infix, suffix "(": (20, None, ("group", 1, ")"), ("func", 1, ")"), None), - "%": (16, None, None, ("%", 16), None), + "%": (15, None, None, ("%", 15), None), "|": (15, None, None, ("|", 15), None), "*": (5, None, None, ("*", 5), None), "/": (5, None, None, ("/", 5), None), diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -134,6 +134,20 @@ But negate binds closer still: (string '\n')) -3 +Filters bind as close as map operator: + + $ hg debugtemplate -r0 -v '{desc|splitlines % "{line}\n"}' + (template + (% + (| + (symbol 'desc') + (symbol 'splitlines')) + (template + (symbol 'line') + (string '\n')))) + line 1 + line 2 + Keyword arguments: $ hg debugtemplate -r0 -v '{foo=bar|baz}'