lua-users home
lua-l archive

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


On Wednesday, September 18, 2013 11:11:10 PM Pierre Chapuis wrote:
> The Cosmo templating engine has been broken for a while with lpeg 0.12. I
> do not know lpeg well enough to fix it. Can somebody here help?
> 
> Details here: https://github.com/mascarenhas/cosmo/issues/5

The problem is the construction

    local longstring = #("[" * lpeg.S"[=") * (longstring1 + longstring2)

longstring1 is fine, but longstring2 is a match-time-capture that consumes an 
unknown amount of input. Although the function will match a long string or 
fail, the compiler doesn't know that and assumes it will match with no input.

I changed Cosmo's longstring pattern to this from the LPEG manual

    local ls_equals = lpeg.P'='^0
    local ls_open = '[' * lpeg.Cg(ls_equals, "init") * '['
    local ls_close = ']' * lpeg.C(ls_equals) * ']'
    local ls_closeeq = lpeg.Cmt(ls_close * lpeg.Cb("init"),
          function (s, i, a, b)
            return a == b
          end)
    longstring = ls_open * (lpeg.P(1) - ls_closeeq)^0 * ls_close / 1

And deleted the old longstring, longstring1, longstring2, start_ls, and start. 
It compiles without error, though I haven't tested if it still matches 
correctly.

-- 
tom <telliamed@whoopdedo.org>