Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subgrammars: prototype design for #25 (re-usable parsers) #181

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ivanbakel
Copy link

Essentially a very crude and unassuming design for how you might choose to implement #25.

The essential stuff:

  • grammars can share rules, which marks them pub(crate) but doesn't produce the wrapper api. Since templates are inlined, they can't be shared.
  • grammars can import other grammars, which opens up their shared rules to be used under that grammar name with the syntax <grammar_name>::<rule_name>.
  • grammars can import with a 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)
  • Rules are actually accessed by assuming that the imported 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 error
  • subgrammar types are converted to/from at need, but are not yet persisted by the parent grammar i.e. a new ParseState 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant