lua-users home
lua-l archive

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


On 12 February 2014 14:56, Simon Cozens <simon@simon-cozens.org> wrote:

Here's an even more reduced case:

local newline = P"\r"^-1 * "\n" / function (a) print("newline"); end
local incrementline = Cg ( Cb"linenum" / function ( a ) print("incrementline"); return a + 1 end , "linenum" )

local setup = Cg ( Cc ( 1) , "linenum" )
local test = (setup * newline * incrementline):match("\n")
test:match("\n")

Produces:

newline

Why doesn't incrementline do anything when it matches? (Incidentally, I've just tried the example where I got this pattern from and it doesn't work. :( )


unfortunally I can't answer the question, but I found a fix (note that dummy Cb):

    local test = (setup * newline * incrementline * Cb"linenum"):match("\n")

now it produces both output lines (`newline` and `incrementline`) as expected.
_Maybe_ this is the reason: "During match time it only gathers enough information to produce the capture values later."(c)

Wbr