##// END OF EJS Templates
templater: add parsing rule for key-value pair...
Yuya Nishihara -
r31885:d18b624c default
parent child Browse files
Show More
@@ -39,6 +39,7 b' elements = {'
39 39 "/": (5, None, None, ("/", 5), None),
40 40 "+": (4, None, None, ("+", 4), None),
41 41 "-": (4, None, ("negate", 19), ("-", 4), None),
42 "=": (3, None, None, ("keyvalue", 3), None),
42 43 ",": (2, None, None, ("list", 2), None),
43 44 ")": (0, None, None, None, None),
44 45 "integer": (0, "integer", None, None, None),
@@ -56,7 +57,7 b' def tokenize(program, start, end, term=N'
56 57 c = program[pos]
57 58 if c.isspace(): # skip inter-token whitespace
58 59 pass
59 elif c in "(,)%|+-*/": # handle simple operators
60 elif c in "(=,)%|+-*/": # handle simple operators
60 61 yield (c, None, pos)
61 62 elif c in '"\'': # handle quoted templates
62 63 s = pos + 1
@@ -462,6 +463,9 b' def buildfunc(exp, context):'
462 463 return (runfilter, (args[0], f))
463 464 raise error.ParseError(_("unknown function '%s'") % n)
464 465
466 def buildkeyvaluepair(exp, content):
467 raise error.ParseError(_("can't use a key-value pair in this context"))
468
465 469 # dict of template built-in functions
466 470 funcs = {}
467 471
@@ -984,6 +988,7 b' exprmethods = {'
984 988 "|": buildfilter,
985 989 "%": buildmap,
986 990 "func": buildfunc,
991 "keyvalue": buildkeyvaluepair,
987 992 "+": lambda e, c: buildarithmetic(e, c, lambda a, b: a + b),
988 993 "-": lambda e, c: buildarithmetic(e, c, lambda a, b: a - b),
989 994 "negate": buildnegate,
@@ -134,6 +134,18 b' But negate binds closer still:'
134 134 ('string', '\n'))
135 135 -3
136 136
137 Keyword arguments:
138
139 $ hg debugtemplate -r0 -v '{foo=bar|baz}'
140 (template
141 (keyvalue
142 ('symbol', 'foo')
143 (|
144 ('symbol', 'bar')
145 ('symbol', 'baz'))))
146 hg: parse error: can't use a key-value pair in this context
147 [255]
148
137 149 Second branch starting at nullrev:
138 150
139 151 $ hg update null
@@ -2668,7 +2680,7 b' Error in nested template:'
2668 2680 hg: parse error at 2: unterminated string
2669 2681 [255]
2670 2682
2671 $ hg log -T '{"foo{date|=}"}'
2683 $ hg log -T '{"foo{date|?}"}'
2672 2684 hg: parse error at 11: syntax error
2673 2685 [255]
2674 2686
General Comments 0
You need to be logged in to leave comments. Login now