lua-users home
lua-l archive

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


While trying to create a grammar with lpegrex (a derivative of lpeg) the author came with an implementation of https://lua-users.org/lists/lua-l/2009-10/msg00774.html and that helped to figure out the problem I had with one grammar (see discussion here https://github.com/edubart/lpegrex/issues/3#issuecomment-1344083774).

Then I tried to improve it a bit (noticed return false in "failed"):

====

    if lpegrex.debug then
      for k, patt in pairs(G) do
        if k ~= 1 then
          local enter = lpeg.Cmt(lpeg.P(true), function(s, p)
            local lineno, colno = lpegrex.calcline(s, p)
            io.stderr:write(string.format('ENTER %s (%d:%d)\n', k, lineno, colno))
            return true
          end)
          local succeded = lpeg.Cmt(lpeg.P(true), function(s, p)
            local lineno, colno = lpegrex.calcline(s, p)
            io.stderr:write(string.format('OK %s (%d:%d)\n', k, lineno, colno))
            return true
          end)
          local failed = lpeg.Cmt(lpeg.P(true), function(s, p)
            local lineno, colno = lpegrex.calcline(s, p)
            io.stderr:write(string.format('FAILED %s (%d:%d)\n', k, lineno, colno))
            return false
          end)
          G[k] = enter * (patt + failed) * succeded --!!!<<< here is the key change
        end
      end
    end

====

 But I'm getting this error:

====

rule 'Primary_expression' may be left recursive

====

Has anyone any idea of a workaround ?

Cheers !