I have this pyparsing variable in a class:
def takeval(type, name, value):
#do stuff with args
self.variable = pp.Optional(self.let_ | self.const_ | self.var_).set_results_name('vartype') ^ self.varname ^ self.set_ ^ self.object
#I want to set the function
self.variable = self.variable.setParseAction(takeval(vartype, varname, object))
How would I get the values of vartype, varname and object from a parse action?
- I want vartype to be the value of one of: self.let_, self.const_ or self.var_
- I want varname to be the value of self.varname
- I wan object to be the value of self.object
Example of goal output:
I parse the string: 'const hi = "hello"'
I want 'const', 'hi', 'hello' to be sent to the target function.