lua-users home
lua-l archive

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


> 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