lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It doesn't take a ton of effort to rewrite most LPEG's functionality
in a scripting environment.  For performance, one really nice thing
you can do in a dynamically compiled language is compile LPEG patterns
into code instead of writing a VM to interpret LPEG ops.  I really
missed LPEG syntax and composability in JS, so I ported the parts that
made sense to a JS script:

https://github.com/weshoke/pattern.js

It might be good design inspiration for someone wanting to make a pure
Lua version.  The entire thing is only 1600 lines, which includes a
bootstrapped interpreter of standard LPEG syntax.

wes

On Tue, Mar 4, 2014 at 12:23 AM, Coroutines <coroutines@gmail.com> wrote:
> On Tue, Mar 4, 2014 at 12:00 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> Is LPeg useful enough to justify how very much larger
>> Lua's C source code will become if it is included?
>>
>> IMHO, if the gain will merely be that the ordinary user
>> would no longer need to build/download it separately
>> (which LuaRocks can do for you) and require it (which
>> takes one line of code), the answer is NO.
>>
>> On the other hand, if the Lua implementation itself exploits
>> it for its lexer/parser/VM encoder and its string library,
>> thus demonstrating how useful it can be while at the same
>> time providing some highly instructive well-written LPeg
>> code, the answer is YES!
>>
>
> I'd also like to see LPeg make it into Lua's core, it offers so much
> compared to what Lua's patterns or even PCRE can do.  That said, I
> don't think it's C implementation is that friendly.  I had high hopes
> when I found out about the Lua-only "lulzpeg" project but it looks
> like the author tried to emulate the C implementation of LPeg in Lua.
> I was hoping for something simpler and more "functional" (as in
> functional programming).  Lua's pattern matching code is very concise,
> but it is similarly difficult to hack on and add to (if one wanted).
> I have for a long time wished Lua allowed for alternation and grouped
> ranged matches ("(cat|dog){3,5}").  I did some from Perl but I don't
> want all of PCRE.
>
> Anyway, I don't like LPeg's C.  It would make sense to use it for
> parsing Lua source, it just feels funny to embed the LPeg VM within
> the Lua VM.  Maybe I'm superficial for running from that thought..
>