LPEG filtering

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

LPEG filtering

Mark Hamburg-5
Is it possible as part of the semantic action/capture logic in LPEG to attach filter functions? For example, could I match a number using the LPEG patterns and then range check it with a Lua function? Or would I need to do that work after the pattern match finishes?

I just read the LPEG paper and I don't recall seeing anything about this sort of functionality.

Mark


Reply | Threaded
Open this post in threaded view
|

Re: LPEG filtering

Miles Bader-2
Mark Hamburg <[hidden email]> writes:
> Is it possible as part of the semantic action/capture logic in LPEG to
> attach filter functions? For example, could I match a number using the
> LPEG patterns and then range check it with a Lua function? Or would I
> need to do that work after the pattern match finishes?

Read about the / operator.

-Miles

-- 
Abstainer, n. A weak person who yields to the temptation of denying himself a
pleasure. A total abstainer is one who abstains from everything but
abstention, and especially from inactivity in the affairs of others.

Reply | Threaded
Open this post in threaded view
|

Re: LPEG filtering

Gavin Wraith
In message <87bq2iik8l.fsf@...> you wrote:

> Mark Hamburg <[hidden email]> writes:
> > Is it possible as part of the semantic action/capture logic in LPEG to
> > attach filter functions? For example, could I match a number using the
> > LPEG patterns and then range check it with a Lua function? Or would I
> > need to do that work after the pattern match finishes?

If you are using Lpeg 8 then you can use lpeg.Cmt to evaluate the
capture before the pattern-matching finishes. See the docs for
Lpeg 8 and the example on the wiki of a pattern that matches
only sequences of consecutive integers.

-- 
Gavin Wraith ([hidden email])
Home page: http://www.wra1th.plus.com/

Reply | Threaded
Open this post in threaded view
|

Re: LPEG filtering

Roberto Ierusalimschy
In reply to this post by Mark Hamburg-5
> I just read the LPEG paper and I don't recall seeing anything about this 

The paper does not intend to cover all LPEG features. The part about
captures, specifically, gives only a flavor of what LPEG offers.

-- Roberto