##// 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 "/": (5, None, None, ("/", 5), None),
39 "/": (5, None, None, ("/", 5), None),
40 "+": (4, None, None, ("+", 4), None),
40 "+": (4, None, None, ("+", 4), None),
41 "-": (4, None, ("negate", 19), ("-", 4), None),
41 "-": (4, None, ("negate", 19), ("-", 4), None),
42 "=": (3, None, None, ("keyvalue", 3), None),
42 ",": (2, None, None, ("list", 2), None),
43 ",": (2, None, None, ("list", 2), None),
43 ")": (0, None, None, None, None),
44 ")": (0, None, None, None, None),
44 "integer": (0, "integer", None, None, None),
45 "integer": (0, "integer", None, None, None),
@@ -56,7 +57,7 b' def tokenize(program, start, end, term=N'
56 c = program[pos]
57 c = program[pos]
57 if c.isspace(): # skip inter-token whitespace
58 if c.isspace(): # skip inter-token whitespace
58 pass
59 pass
59 elif c in "(,)%|+-*/": # handle simple operators
60 elif c in "(=,)%|+-*/": # handle simple operators
60 yield (c, None, pos)
61 yield (c, None, pos)
61 elif c in '"\'': # handle quoted templates
62 elif c in '"\'': # handle quoted templates
62 s = pos + 1
63 s = pos + 1
@@ -462,6 +463,9 b' def buildfunc(exp, context):'
462 return (runfilter, (args[0], f))
463 return (runfilter, (args[0], f))
463 raise error.ParseError(_("unknown function '%s'") % n)
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 # dict of template built-in functions
469 # dict of template built-in functions
466 funcs = {}
470 funcs = {}
467
471
@@ -984,6 +988,7 b' exprmethods = {'
984 "|": buildfilter,
988 "|": buildfilter,
985 "%": buildmap,
989 "%": buildmap,
986 "func": buildfunc,
990 "func": buildfunc,
991 "keyvalue": buildkeyvaluepair,
987 "+": lambda e, c: buildarithmetic(e, c, lambda a, b: a + b),
992 "+": lambda e, c: buildarithmetic(e, c, lambda a, b: a + b),
988 "-": lambda e, c: buildarithmetic(e, c, lambda a, b: a - b),
993 "-": lambda e, c: buildarithmetic(e, c, lambda a, b: a - b),
989 "negate": buildnegate,
994 "negate": buildnegate,
@@ -134,6 +134,18 b' But negate binds closer still:'
134 ('string', '\n'))
134 ('string', '\n'))
135 -3
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 Second branch starting at nullrev:
149 Second branch starting at nullrev:
138
150
139 $ hg update null
151 $ hg update null
@@ -2668,7 +2680,7 b' Error in nested template:'
2668 hg: parse error at 2: unterminated string
2680 hg: parse error at 2: unterminated string
2669 [255]
2681 [255]
2670
2682
2671 $ hg log -T '{"foo{date|=}"}'
2683 $ hg log -T '{"foo{date|?}"}'
2672 hg: parse error at 11: syntax error
2684 hg: parse error at 11: syntax error
2673 [255]
2685 [255]
2674
2686
General Comments 0
You need to be logged in to leave comments. Login now