erikrose / parsimonious

The fastest pure-Python PEG parser I can muster
MIT License
1.79k stars 126 forks source link

Initialize NodeVisitor with default grammar #223

Closed thehappycheese closed 1 year ago

thehappycheese commented 1 year ago

Proposal to allow NodeVisitor to be initialized using a default grammar object. Old behaviour still works.

For your consideration / comment. Not sure if I should have raised an issue to discuss first? Many thanks to you and other contributors for great package :)

thehappycheese commented 1 year ago

Actually now I am reading RuleDecoratorMeta and I can see how a grammar passed into NodeVisitor.__init__ would just replace anything set up in NodeVisitor.__new__ ... I have probably jumped the gun creating a pull request.

It feels like NodeVisitor.__init__ should accept a default grammar and @rule annotations should extend / overwrite that. But if the logic in __new__ were moved to __init__ then inheritance / mro becomes a problem...