I'm working with ANTLR to parse some language these days. I chose to work with Python. The parser class which ANTLR generates, contains many methods with similar names:
class autogeneratedparser(xxx):
def something_enter(self,ctx):
pass
def something_exit(self,ctx)
pass
I override these by defining an inheriting class
class myclass(autogeneratedparser)
particularthing = False
def particularthing_enter(self,ctx):
print(ctx.name)
myclass.particularthing = true
def particularthing_exit(self,ctx):
print(ctx.name)
myclass.particularthing = false
I'd like to dynamically and automatically generate all those methods, changing their respective variable name included. In pseudo-code:
generate for particularthing in anything:
$(particularthing) = False
def $(particularthing)_enter(self,ctx):
print(ctx.name)
myclass.$(particularthing) = true
def $(particularthing)_exit(self,ctx):
print(ctx.name)
myclass.$(particularthing) = false
I could obviously just tell vim to do it, but I'm sure Python has a way too, just don't know how :-)
Thanks for your valuable input :)