lua-users home
lua-l archive

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


> [...]
> 
> 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
> 
> [...]
> 
> And deleted the old longstring, longstring1, longstring2, start_ls, and start. 
A less intrusive change is to change only longstring2 itself:

local longstring2 = lpeg.Cmt(start, function (s, i, start)
  local p = string.gsub(start, "%[", "]")
  local _, e = string.find(s, p, i)
  return (e and e + 1)
end)

(Many thanks to Tom for doing the hard part.)

-- Roberto