[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Need lpeg hint
- From: Peter Cawley <lua@...>
- Date: Sat, 13 Aug 2011 22:49:23 +0100
On Sat, Aug 13, 2011 at 10:43 PM, Martin Kortmann <mail@kortmann.de> wrote:
>
> Am 13.08.2011 um 23:37 schrieb Peter Cawley:
>
>> On Sat, Aug 13, 2011 at 10:33 PM, Martin Kortmann <mail@kortmann.de> wrote:
>>>
>>> Am 13.08.2011 um 22:26 schrieb Peter Cawley:
>>>
> [schnipps]
>>>
>>>
>>> Hello Peter,
>>>
>>> but i can't see the difference between your example and my my code. Maybe there are too many trees in the wood...
>>> Where is the difference between your "pattern" and my "block"?
>>
>> Your "block" has "/ function() ..." as part of it, causing that
>> function to be applied at every match of "block". My "pattern" has "/
>> function() ..." outside of the grammar, causing it to be applied only
>> to the top-level block.
>>
>
> OK. now that you say it, i can see it. But is it possible to get your (the right) behavior with my grammar table?
>
> Sorry for my penetrant questions, i will learn more over time and then i will try to answer these questions to other newbies.
Something like the following might be what you want.
local grammar = L.P { "standalone_block",
entry = ws * id * ws * value + L.V('block'), -- key value OR block
block = ws * id * ws * "{" * (L.Ct(L.V"entry"^0) / makepairs) * ws * "}",
standalone_block = L.V"block" / function(k, v) return {[k] = v} end
}