petitparser / dart-petitparser

Dynamic parser combinators in Dart.
https://pub.dartlang.org/packages/petitparser
MIT License
457 stars 48 forks source link

Consider making `ref` and `build` usable outside of GrammarDefinition #107

Closed doppio closed 3 years ago

doppio commented 3 years ago

Would you consider moving the ref (and possibly build/resolve) functions out of the GrammarDefinition class to promote them to top-level functions?

I have a series of complex parsers that I have broken up across files for simplicity and organization. To be able to conveniently use References, I would need all of my parser functions to wrapped in subclasses of GrammarDefinition. This would make the code a lot more verbose (almost unreadable) since every reference to a parser function would go from ref0(parserFunction) to something like ref0(subparserGrammar.parserFunction), assuming that parserFunction itself needs to contain references.

Other thoughts on how to solve this would be appreciated. It would be nice to be able to define grammars across files to keep the code more organized. :)

renggli commented 3 years ago

This is a great idea, and a natural generalization of taking the grammar definition out of the Parser hierarchy (in one of the past versions). Looking into this right away ...

renggli commented 3 years ago

This will be part of petitparser 4.2.0.