Requesting LPEG

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Requesting LPEG

Post by tsuujin » Wed May 12, 2010 6:55 am

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?

User avatar
Vadi
Posts: 4728
Joined: Sat Mar 14, 2009 3:13 pm

Re: Requesting LPEG

Post by Vadi » Wed May 12, 2010 12:13 pm

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.

robg
Posts: 7
Joined: Tue Apr 06, 2010 2:07 pm

Re: Requesting LPEG

Post by robg » Wed May 12, 2010 3:17 pm

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?
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.

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.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Requesting LPEG

Post by tsuujin » Wed May 12, 2010 6:03 pm

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.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Requesting LPEG

Post by tsuujin » Wed May 12, 2010 6:06 pm

By the way: would lpeg be a new match type for triggers? That'd be cool.

WillFa
Posts: 19
Joined: Mon May 10, 2010 4:16 pm

Re: Requesting LPEG

Post by WillFa » Wed May 12, 2010 6:46 pm

tsuujin wrote:By the way: would lpeg be a new match type for triggers? That'd be cool.
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.


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.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests