[Pyparsing] left-recursion again: expression of attribute
Brought to you by:
ptmcg
From: spir ☣ <den...@gm...> - 2010-03-30 19:32:10
|
Hello, This time, that's me having a left-recursion issue. I'm trying to parse var names that can possibly refer to attributes, like "a.b.c". I can parse it as simpleName + ZeroOrMore(extension) but then I need to reformat the result resursively, to get the real semantics of: getattr(getattr(container, name), name) i.e. in the case of "a.b.c": ((a).b).c In PEG, I cannot find a way to avoid left-recursion: simpleName : [a-zA-Z_] [a-zA-Z_0-9]* attribute : name '.' simpleName name : attribute / simpleName and still get an expression of the recursive pattern directly. The issue is indeed that (unlike the way I wrote it above) the expression of an attribute is not nicely wrapped in delimiters. [I really look for that because in my case any name ends up mapping to getattr(world, name), ie it refers an attribute of <world>, the equivalent of in the language I'm parsing of py globals().] Is there any workaround? Thanks for reading, Denis ________________________________ vit esse estrany ☣ spir.wikidot.com |