lua-users home
lua-l archive

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


I actually do have a follow up question:

I am now trying to wrap my head around the re module and tried making a simple grammar to parse something like this

a = 'b'

and put it into a dictionary style table a la:

{ a = 'b'}

I tried to do so using table and named group capture, but I can’t for the life of me figure out how to dynamically set the name of the group capture. Will I have to write a custom helper function to achieve this or is there a pure re way?

Here is the code:

local attribute = re.compile([[
    attr <- {| {:<identifier>: <attributeValue> :} |}
    identifier <- (!%nl [a-zA-Z][a-zA-Z0-9_]*)+
    attributeValue <- (" "+ "=" " "+ "'" {<identifier>} "'")
    ]])

This is the line where I try to capture the first identifier as the name for the group capture: attribute <- {| {:<identifier>: <attributeValue> :} |}

Which fails with: pattern error near ': <attributeValue> :}…'

Any thoughts welcome!

Thanks
Matthias

On Jul 7, 2017, at 19:38, Matthias Dörfelt <lists@mokafolio.de> wrote:

Awesome, I think that did the trick! thanks! Still trying to wrap my head around a lot of whats going on but that should get me started.

Matthias

On Jul 7, 2017, at 18:41, Duncan Cross <duncan.cross@gmail.com> wrote:

On Sat, Jul 8, 2017 at 2:34 AM, Matthias Dörfelt <lists@mokafolio.de> wrote:
I just tried your implementation and I can’t really get it to work. My main question is where current_indent inside match_same_indent comes from. I tried some different things based on guessing without success.

Oops -- "current_indent" should have been "indent" there. Sorry about that.

-Duncan