lua-users home
lua-l archive

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


On 16 April 2016 at 02:53, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> This whole story goes back to these messages:
>
>   https://github.com/xolox/lua-lxsh/issues/5             (the problem)
>   http://lua-users.org/lists/lua-l/2015-07/msg00356.html   (the "fix")
>
> The issue is that I "fixed" the wrong problem, because of a bad
> error message. The original problem was the one that appeared in the
> OP:
>
>> lpeg = require"lpeg"
>> D = lpeg.R'09'
>> BB = lpeg.B(-D, 1)
> stdin:1: bad argument #1 to 'B' (pattern may not have fixed length)
>
> But of course 'B' has a fixed length, and so the "obvious fix" for that
> message was to allow fixed lengths equal to zero. But look behind with
> zero lengths may be correct from a formal point of view, but they are
> useless (as it means "go back zero positions") and probably not doing
> what the programmer expects. The correct fix should be to rephrase the
> error message, not to allow look behind with zero-length patterns.
>
> -- Roberto
>

btw, I just had this lpeg.B issue come up in a totally separate context.
I was updating lunamark to work with 5.3, and wrote this:
https://github.com/jgm/lunamark/pull/14/commits/51756bfca858795a423f4ced9e7c164a35f1638b

Interestingly, they were passing a fixed-length pattern of length 1 to
lpeg.B, but passing a second argument of 2.
i.e. checking which single character was 2 before the current position.