[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: bug in Lpeg re.lua
- From: "Fabio Mascarenhas" <mascarenhas@...>
- Date: Wed, 23 Jan 2008 04:54:55 -0200
Hi,
There's a bug in re.lua that manifests when you use re grammars with a definitions table:
require"lpeg"
require"re"
local grammar = [[
foo <- bar
bar <- baz
]]
local defs = { baz = lpeg.P"baz" }
exp = re.compile(grammar, defs)
print(re:match"baz")
This code blows up with:
lua: ./re.lua:103: bad argument #1 to 'P' (pattern expected, got nil)
stack traceback:
[C]: in function 'P'
./re.lua:103: in function <./re.lua:102>
[C]: in function 'match'
./re.lua:133: in function 'compile'
foo.lua:11: in main chunk
[C]: ?
The attached patch fixes this.
--
Fabio Mascarenhas
--- re.lua 2007-10-10 15:56:59.000000000 -0300
+++ ../lpeg-0.7-patched/re.lua 2008-01-23 04:44:08.000000000 -0200
@@ -5,7 +5,7 @@
local print, error = print, error
local mt = getmetatable(m.P(0))
-module "re"
+module(...)
local I = m.P(function (s,i) print(i, s:sub(1, i-1)); return i end)
@@ -100,7 +100,7 @@
+ Class
+ m.P"." * m.Cc(any)
+ Identifier * -(S * '<-') / function (n)
- return Defs and m.P(Defs[n]) or m.V(n)
+ return (Defs and Defs[n] and m.P(Defs[n])) or m.V(n)
end;
}