Next / Previous / Contents / Shipman's homepage

6.17. traceParseAction(): Decorate a parse action with trace output

You can use this decorator to wrap a parse action, so that whenever the parse action is used, two messages will appear on the sys.stderr stream, showing the arguments on entry and the value returned.

>>> @pp.traceParseAction
... def basil(toks):
...     '''Dummy parse action
...     '''
...     return None
... 
>>> number = pp.Word(pp.nums).setParseAction(basil)
>>> print number.parseString('575')
>>entering wrapper(line: '575', 0, ['575'])
<<leaving wrapper (ret: None)
['575']