[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LPEG bug?
- From: Daurnimator <quae@...>
- Date: Sun, 17 May 2015 20:36:38 +1000
Today I was working on an lpeg pattern, and ran into this oddity,
which I believe to be a bug.
I've condensed it down as far as I could, if I remove any more the bug
seems to disappear.
The following script throws in the assert.
If you uncomment either of the alternate `path_abempty` definitions, it works.
local lpeg = require "lpeg"
local P = lpeg.P
local HEXDIG = lpeg.R("09","af", "AF")
local pct_encoded = P"%" * lpeg.C ( HEXDIG * HEXDIG ) / function (hex_num)
return string.char(tonumber(hex_num, 16))
end
local pchar = lpeg.R("az","AZ") + pct_encoded
local path_abempty = ( P"/" * pchar^0 )^0
-- local path_abempty = ( P"/" * pchar^0 )^0 * ( P"/" * pchar^0 )^0
-- local path_abempty = ( P"/" * pchar^0 )^0 * function() return true end
local path_rootless = pchar^1 * path_abempty
local path_absolute = P"/" * path_rootless^-1
assert(lpeg.Cs ( path_absolute ):match "/var/log/messages" ==
"/var/log/messages")