lua-users home
lua-l archive

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


I seem to have come across a bug in LPeg 0.9 that didn't exist in 0.8.1:

    local lpeg = require 'lpeg'

    local ws = lpeg.S' \t\r\n'^1

    local pat =
        lpeg.R'az'^1 *
        function(s, i) print('here1',i) return i end *
        (ws^-1 *
         function(s, i) print('here2',i) return i end *
         #lpeg.P(1) *
         function(s, i) print(s:len(), i) error('wtf') end)^-1

    print(pat:match([[helloworld    ]]))

On 0.8.1 I get:

    :; lua /tmp/wtf.lua
    here1   11
    here2   15
    11

...which indicates that the #lpeg.P(1) rule is failing as I would expect.

On 0.9, however, I get:

    :; LUA_CPATH='.../lpeg-0.9/?.so' lua /tmp/wtf.lua
    here1   11
    here2   15
    14      15
    lua: /tmp/wtf.lua:11: wtf
    stack traceback:
            [C]: in function 'error'
            /tmp/wtf.lua:11: in function </tmp/wtf.lua:11>
            [C]: in function 'match'
            /tmp/wtf.lua:13: in main chunk
            [C]: ?

That would seem to indicate that the #lpeg.P(1) is not failing at the
end of the input.

If I replace #lpeg.P(1) with lpeg.P(1) it works, though since it consumes
a character it makes writing the reported error position off by one.

Any ideas?

-bcd