Skip to content

Instantly share code, notes, and snippets.

@binki
Created September 5, 2016 19:01
Show Gist options
  • Save binki/bd892b155798d047922b663b12ffd066 to your computer and use it in GitHub Desktop.
Save binki/bd892b155798d047922b663b12ffd066 to your computer and use it in GitHub Desktop.

Mercurial supports nested quoting contexts:

ohnobinki@gibby ~/dcx-ridik-variable-substitution $ t="{'a{'b{pad('x', 2, ',', True)}'}'}"; echo "${t}"; hg log -l1 --template "${t}"; echo
{'a{'b{pad('x', 2, ',', True)}'}'}
ab,x

It also supports “weirdly quoted strings”, as I call them:

ohnobinki@gibby ~/dcx-ridik-variable-substitution $ t="{\'a{\\\\\\'b\\\\\\'}\'}"; echo "${t}"; hg log -l1 --template "${t}"; echo
{\'a{\\\'b\\\'}\'}
ab

In the following, “at 3” refers to the third opening curly brace in the whole expression. I.e., it is a templating context starting at the first \'. It is like nested parser contexts cannot be mixed with “weirdly quoted strings”.

ohnobinki@gibby ~/dcx-ridik-variable-substitution $ t="{'\\\\{\\'  {\\'author\\'}\\'}'}"; echo "${t}"; hg log -l1 --template "${t}\n"
{'\\{\'  {\'author\'}\'}'}
hg: parse error at 3: unterminated template expansion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment