Mercurial > hg-stable
diff tests/test-command-template.t @ 25783:1f6878c87c25
templater: introduce one-pass parsing of nested template strings
Instead of re-parsing quoted strings as templates, the tokenizer can delegate
the parsing of nested template strings to the parser. It has two benefits:
1. syntax errors can be reported with absolute positions
2. nested template can use quotes just like shell: "{"{rev}"}"
It doesn't sound nice that the tokenizer recurses into the parser. We could
instead make the tokenize itself recursive, but it would be much more
complicated because we would have to adjust binding strengths carefully and
put dummy infix operators to concatenate template fragments.
Now "string" token without r"" never appears. It will be removed by the next
patch.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 15 Jun 2015 23:11:35 +0900 |
parents | babd2c93bd99 |
children | 11ab8714f529 |
line wrap: on
line diff
--- a/tests/test-command-template.t Mon Jun 15 23:03:30 2015 +0900 +++ b/tests/test-command-template.t Mon Jun 15 23:11:35 2015 +0900 @@ -2541,6 +2541,16 @@ abort: template filter 'datefilter' is not compatible with keyword 'author' [255] +Error in nested template: + + $ hg log -T '{"date' + hg: parse error at 2: unterminated string + [255] + + $ hg log -T '{"foo{date|=}"}' + hg: parse error at 11: syntax error + [255] + Thrown an error if a template function doesn't exist $ hg tip --template '{foo()}\n' @@ -2952,7 +2962,7 @@ $ hg log -r 2 -T "{if(rev, '{if(rev, r\'foo\')}')}"'\n' foo $ hg log -r 2 -T '{if(rev, "{if(rev, \")}")}\n' - hg: parse error at 11: unterminated string + hg: parse error at 21: unterminated string [255] $ hg log -r 2 -T '{if(rev, \"\\"")}\n' hg: parse error at 11: syntax error @@ -3069,6 +3079,14 @@ 3:\x6eo user, \x6eo domai\x6e 4:\x5c\x786eew bra\x5c\x786ech +Test quotes in nested expression are evaluated just like a $(command) +substitution in POSIX shells: + + $ hg log -R a -r 8 -T '{"{"{rev}:{node|short}"}"}\n' + 8:95c24699272e + $ hg log -R a -r 8 -T '{"{"\{{rev}} \"{node|short}\""}"}\n' + {8} "95c24699272e" + Test recursive evaluation: $ hg init r