[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Bug in Lpeg v0.11/v0.12??
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 7 May 2013 10:47:34 -0300
> The following code:
>
> local re=require('re')
> local a="[c]?"
> re.compile(a)
>
> shows the error: (using luajit in linux / macosx)
>
> ERROR: bad argument #1 to '?' (lpeg-pattern expected, got string)
>
> if line 2 is changed to:
> local a="[cd]?"
>
> works ok.
>
> in lpeg v0.10 both works ok.
Yes, it is a bug. Many thanks for the report. You can fix it in re.lua:
@@ -136,7 +136,9 @@
"["
* (m.C(m.P"^"^-1)) -- optional complement symbol
* m.Cf(item * (item - "]")^0, mt.__add) /
- function (c, p) return c == "^" and any - p or p end
+ function (c, p)
+ return c == "^" and any - p or mm.P(p)
+ end
* "]"
But I think it is better to fix lptree.c:
@@ -525,7 +525,7 @@
static int lp_star (lua_State *L) {
int size1;
int n = luaL_checkint(L, 2);
- TTree *tree1 = gettree(L, 1, &size1);
+ TTree *tree1 = getpatt(L, 1, &size1);
if (n >= 0) { /* seq tree1 (seq tree1 ... (seq tree1 (rep tree1))) */
TTree *tree = newtree(L, (n + 1) * (size1 + 1));
if (nullable(tree1))
-- Roberto