changeset 34329:6367318327f0

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
author Yuya Nishihara <yuya@tcha.org>
date Mon, 24 Apr 2017 21:37:11 +0900
parents dd28b1f55eb8
children 89aec1834a86
files mercurial/templater.py tests/test-command-template.t
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Sun Sep 24 15:22:46 2017 +0900
+++ b/mercurial/templater.py	Mon Apr 24 21:37:11 2017 +0900
@@ -34,7 +34,7 @@
 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),
--- a/tests/test-command-template.t	Sun Sep 24 15:22:46 2017 +0900
+++ b/tests/test-command-template.t	Mon Apr 24 21:37:11 2017 +0900
@@ -134,6 +134,20 @@
     (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}'