Subgrammars: prototype design for #25 (re-usable parsers) #181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Essentially a very crude and unassuming design for how you might choose to implement #25.
The essential stuff:
share
rules, which marks thempub(crate)
but doesn't produce the wrapper api. Since templates are inlined, they can't be shared.import
other grammars, which opens up their shared rules to be used under that grammar name with the syntax<grammar_name>::<rule_name>
.converter
, which is a piece of Rust code which is the arguments to the second grammar written in terms of the arguments of the first (if any)import
ed grammar's code lives in a module of the same name under the parent module - if either of these things are not true, you get a cryptic compile errorParseState
is created at each boundary, etc.This isn't meant to be the final design - cache persistence of subgrammars would be good, for example, and a better build-time system of catching errors (such as by sharing a Compiler, maybe?) - but I would appreciate any feedback about how this aligns with what you imagined and what could/should be improved.