[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [LPeg] Pattern issues
- From: Sean Conner <sean@...>
- Date: Wed, 27 Jul 2016 13:20:34 -0400
It was thus said that the Great Soni L. once stated:
> Let's say I have a pattern `pat`.
>
> If I do `Ct(Cg(pat, 0) * Cg(Ct(Cg(Cb(0), "tag")), 0))`, and `pat`
> matches, do I get `{[0] = result_of_pat}` or do I get `{[0] =
> {tag=result_of_pat}}` or do I get an error?
Did you try it? That's what I tend to do and figure out why I got the
result I did.
> Also, are LPeg patterns evaluated left-to-right? (The Lua reference
> manual isn't very clear on that...)
They are evaluated in the order of mathematical precedence (* before +, ^
before *, etc). Also, it's an ordered search. So:
a = lpeg.P"aaab"
+ lpeg.P"aaac"
+ lpeg.P"aaad"
+ lpeg.P"a"
is tried in the order seen, and the first match terminates the expression
and returns the match.
-spc