Description of lpeg.B

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Description of lpeg.B

Matthias Kluwe
Hi!

On http://www.inf.puc-rio.br/~roberto/lpeg/ the description of lpeg.B says
"Matches patt behind the current position, consuming no input" in the
summary table.

The long description says "a pattern that matches only if the input string
at the current position is preceded by patt".

I've pondered over the contrast "behind the current position" and "the
current position is preceded by" for some time now, but it does not parse in
my head. Can someone please shed some light on this?

Additionally, I'm not sure what this "current position" is. I've found that

    lpeg.match( 2 * lpeg.B'sd', 'asdf' )

matches (and returns 3). If the "current position" is preceded by 'sd', it
must be "before the 'f'"? But the call returns 3, which is the index of the
first character after the match, and that is the 'd'!?

Regards,
Matthias



Reply | Threaded
Open this post in threaded view
|

Re: Description of lpeg.B

Dirk Laurie-2
2014/1/22 Matthias Kluwe <[hidden email]>:
> I've found that
>
>     lpeg.match( 2 * lpeg.B'sd', 'asdf' )
>
> matches (and returns 3). If the "current position" is preceded by 'sd', it
> must be "before the 'f'"? But the call returns 3, which is the index of the
> first character after the match, and that is the 'd'!?

I can't reproduce the reported behaviour.

$ lua -l lpeg
Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> print(lpeg.version())
0.12
> print(lpeg.match( 2 * lpeg.B'sd', 'asdf' ))
nil
> our.

Reply | Threaded
Open this post in threaded view
|

Re: Description of lpeg.B

Matthias Kluwe
Hi!

Dirk Laurie <dirk.laurie <at> gmail.com> writes:

> 2014/1/22 Matthias Kluwe <mkluwe <at> gmail.com>:
> > I've found that
> >
> >     lpeg.match( 2 * lpeg.B'sd', 'asdf' )
> >
> > matches (and returns 3). If the "current position" is preceded by 'sd', it
> > must be "before the 'f'"? But the call returns 3, which is the index of the
> > first character after the match, and that is the 'd'!?
>
> I can't reproduce the reported behaviour.
>
> $ lua -l lpeg
> Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> > print(lpeg.version())
> 0.12
> > print(lpeg.match( 2 * lpeg.B'sd', 'asdf' ))
> nil

Thank you for testing this!

I'm outdated -- my installed LPeg version is 0.10.2.

Regards,
Matthias



Reply | Threaded
Open this post in threaded view
|

Re: Description of lpeg.B

Matthias Kluwe
Matthias Kluwe <mkluwe <at> gmail.com> writes:

>
> Hi!
>
> Dirk Laurie <dirk.laurie <at> gmail.com> writes:
>
> > 2014/1/22 Matthias Kluwe <mkluwe <at> gmail.com>:
> > > I've found that
> > >
> > >     lpeg.match( 2 * lpeg.B'sd', 'asdf' )
> > >
> > > matches (and returns 3). If the "current position" is preceded by 'sd', it
> > > must be "before the 'f'"? But the call returns 3, which is the index
of the

> > > first character after the match, and that is the 'd'!?
> >
> > I can't reproduce the reported behaviour.
> >
> > $ lua -l lpeg
> > Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> > > print(lpeg.version())
> > 0.12
> > > print(lpeg.match( 2 * lpeg.B'sd', 'asdf' ))
> > nil
>
> Thank you for testing this!
>
> I'm outdated -- my installed LPeg version is 0.10.2.

After updating to 0.12, the modified call

    lpeg.match( 2 * lpeg.B'as', 'asdf' )

yields 3, as expected.

Thank you again,
Matthias