Dirk Laurie
2018-10-31 19:00:17 UTC
I define a function to be used with LPEG that simply returns the first
character. It _cannot_ match the empty string:
function fct(str)
if #str==0 then return false
else return 2,str:sub(1,1)
end
end
I turn it into an LPEG pattern:
lpeg.version() --> 1.0.0
patt=lpeg.P(fct)
"patt" is supposed to do exactly the same as lepg.C(1). It works OK on its own:
patt:match"" --> nil
patt:match"abc" --> a
But I can't make it match twice:
(patt*patt):match"abc" --> a a [expected: a b]
This seems to contradict the manual's statement that: "If the call
returns a number, the match succeeds and the returned number becomes
the new current position."
character. It _cannot_ match the empty string:
function fct(str)
if #str==0 then return false
else return 2,str:sub(1,1)
end
end
I turn it into an LPEG pattern:
lpeg.version() --> 1.0.0
patt=lpeg.P(fct)
"patt" is supposed to do exactly the same as lepg.C(1). It works OK on its own:
patt:match"" --> nil
patt:match"abc" --> a
But I can't make it match twice:
(patt*patt):match"abc" --> a a [expected: a b]
This seems to contradict the manual's statement that: "If the call
returns a number, the match succeeds and the returned number becomes
the new current position."