lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Apr 8, 2015 at 2:38 PM, William Ahern
<william@25thandclement.com> wrote:
> Now modify yours to support escaping $, like "Hello \$planet!". Note should
> also permit escaping the escape character, "Hello \\$planet!".

Thinking out loud here: How about capturing a possible run of escape
characters immediately prior to the "$"? Then check the length of that
capture, mod 2. If even, all are escaped, so continue with expansion
as normal, prepending the capture to the return value if anything
other than false is returned. If the capture length is odd, then the
final escape character is escaping the "$", so return false
immediately.

I would think that this would also work when escaping is done by
doubling the "$", as in Python's string.Template. [1]

This is all off the top of my head and untested, though.

[1] https://docs.python.org/2/library/string.html#template-strings