I've spent the last day reading up on LPEG, looking at examples, trying to figure out why LPEG is special, and I just don't see it. Every example that I've seen, I can instantly think of a solution in PCRE that does the exact same thing with a simple syntax change.
Can you think of anything -specific- that LPEG makes easy which is hard with PCRE?
Requesting LPEG
Re: Requesting LPEG
I think his point is just that instead of having a regex pattern + setting of variables in a script, you'd have a lua type that matches + sets all your variables in the pattern.
Re: Requesting LPEG
I can. Matching pairs of parenthesis, ie: parsing XMLish stuff, etc. (Simplified for brevity) <(\w+)>.*</\1> is no match for what PEGs can do (like managing recursive tags, etc). Both have their place. Believe me, I'm a regex freak. I've lived and breathed regex professionally for years, and I still appreciate PEGs being judiciously applied where appropriate.tsuujin wrote:I've spent the last day reading up on LPEG, looking at examples, trying to figure out why LPEG is special, and I just don't see it. Every example that I've seen, I can instantly think of a solution in PCRE that does the exact same thing with a simple syntax change.
Can you think of anything -specific- that LPEG makes easy which is hard with PCRE?
Sure, some things that PEGs can do you can still do in regex. But it's non-elegant, difficult to maintain, and just plain ugly (and can sometimes react in unexpected ways). I could use a slotted screwdriver on a phillips screw, but the next mechanic to look at your car may not appreciate the fact that it's stripped.
No one is trying to say YOU should use LPEG, nor is anyone saying that LPEG replaces PCRE. They're both useful tools to have in your toolbox.
Re: Requesting LPEG
I really am not arguing against implementation. If it does something unique it has my support on basically everything. I'm just curous as to what that something unique is.
Frankly, if it gives me named callbacks, I'll be happy. I've been asking for those.
Frankly, if it gives me named callbacks, I'll be happy. I've been asking for those.
Re: Requesting LPEG
By the way: would lpeg be a new match type for triggers? That'd be cool.
Re: Requesting LPEG
You'd just use a Lua Function pattern type. Make a script leaf to define the grammar, and then a trigger leaf that does myLpeg:match(line) in the pattern.tsuujin wrote:By the way: would lpeg be a new match type for triggers? That'd be cool.
Oh, and yes it's another tool, and not the perfect tool for every job, but it is also faster than PCRE (especially lrexlib) in a lot of applications.