Closed MegaIng closed 9 months ago
I wonder if instead of having to add a new parameter on all these methods, we can instead clear the callbacks on the copy method which accepts()
uses. Like new_cursor = self.copy(callbacks = {})
.
Then all we need is to change in the parser is value = callbacks[rule](s) if callbacks else s
It's a bit more implicit, but it feels cleaner to me. What do you think?
We are currently avoiding creating a copy of the ParserConf object since it's semantically immutable. So we have to either:
accepts
(very expensive)ParserConf
in the normal __copy__
(unnessary, although it wouldn't be that expensive)InteractiveParser
, ParserState
(and maybe ParserConf
) just for this usecase that specifcally doesn't copy callbacks ParserConf
after doing a normal copy of InteractiveParser
. (Not sure if I like this)
ParserConf
in accepts
and use that for all Tokens...An alternative implementation has been merged.
This also has the nice benefit of making
accepts
faster since it does less work. Technically this is an option that an end user can access on their instance ofInteractiveParser
, so I added a bit of documentation.