Reputation: 1378
Apparently if you add any parse action and return a result in that action, the result will always be encapsulated into a list 'deepening' the output tree.
I suppose this is for returning multiple values but it makes casual use of the library far harder because you then have to remember which parts of the tree you replaced and call result.normalstruct.replaced[0]
(or even worse result.normalstruct['replaced'][0]
)
This is a bit strange and makes refactoring harder, so i'd like a way to avoid it. Any tips?
Upvotes: 1
Views: 51
Reputation: 1378
The problem here is that the argument token of setParseAction
is already a list. Instead of operating on str(token_argument)
i should operate on str(token_argument[0])
and return that. No more deepening.
edit: though apparently it doesn't happen always. Happened to me with a word action but when i tried to 'unwrap' element zero of a 'And' expression result from a setParseAction functor it gave me the first subexpression.
Man, i'd like consistency here.
Upvotes: 1