lua-users home
lua-l archive

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


It was thus said that the Great Daurnimator once stated:
> On 30 June 2017 at 04:53, Benas Vaitkevičius <vsbenas@gmail.com> wrote:
> > 1) a new function for a "silent match" lpeg.Sm, that consumes the input but
> > does not produce it in the capture list.
> > Say we have patt1 and patt2 that do not produce any captures.
> > Current behaviour:
> > lpeg.C(patt1 * lpeg.P ' ' * patt2) --> captures patt1 .. " " .. patt2
> > Wanted behaviour:
> > lpeg.C(patt1 * lpeg.Sm(lpeg.P ' ') * patt2) --> captures patt1 .. patt2
> > patt1 * lpeg.Sm(lpeg.P ' ') * patt2 --> no capture
> >
> > In a way, it is similar to lpeg.P ' ' / '', but it does not create a new
> > capture. I think this function could be useful for other purposes as well,
> > to create simpler grammars.
> >
> > I don't know if this is possible with the current implementation of lpeg, so
> > I'm open to other suggestions as well.
> 
> Divide by zero to discard captures:
> http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html#cap-num

  That doesn't solve the issue:

lpeg  = require "lpeg"
SP    = lpeg.P" "^0 / 0
patt  = lpeg.P"a" * SP
thing = lpeg.C(patt)
print(string.format("%q",thing:match "a    "))

"a    "

  -spc