[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LPeg indent/whitespace based grammar
- From: Matthias Dörfelt <lists@...>
- Date: Fri, 7 Jul 2017 15:30:14 -0700
Thank you so much! re module looks very nice, will give it a shot I think after I got it to work with pure LPeg!
Best
Matthias
> On Jul 7, 2017, at 14:21, Duncan Cross <duncan.cross@gmail.com> wrote:
>
> On Fri, Jul 7, 2017 at 9:09 PM, Matthias Dörfelt <lists@mokafolio.de> wrote:
>> Awesome, thanks that is super helpful!
>> Haven’t looked at the “re” portion of lpeg, yet. I was initially gonna stick with pure LPeg, but let’s see!
>>
>> Is it pretty straight forward to express your re code in pure lua & LPeg?
>>
>> Thanks!
>
> Sure, I think this should be the equivalent:
>
>
> --
> local hierarchy = lpeg.P {
>
> 'hierarchy';
>
> hierarchy = initial_indent
> *
> lpeg.Ct(
> lpeg.Cg(
> lpeg.Ct(
> (
> lpeg.V('first_root')
> *
> lpeg.V('next_root')^0
> )^-1
> ),
> 'children'
> )
> )
> *
> lpeg.P(-1);
>
> first_root = lpeg.V('entry');
>
> next_root = '\n' * lpeg.V('entry');
>
> entry = lpeg.Ct(
> lpeg.Cg(lpeg.V('name'), 'name')
> *
> lpeg.Cg(
> lpeg.Ct(
> (
> lpeg.V('first_child')
> *
> lpeg.V('next_child')^0
> )^-1
> ),
> 'children'
> )
> );
>
> first_child = '\n' * capture_deeper_indent * lpeg.V('entry');
> next_child = '\n' * match_same_indent * lpeg.V('entry');
>
> name = (1 - lpeg.P('\n'))^0;
>
> }
> --
>
>
> -Duncan
>
>