WIP: add a more comfortable way of adding grammars #4
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.
This uses the grammar compiler of the parsing module but adds a new mechanism of specifying grammars via a metaclass (rather than using a module as a container for a grammar), using a simple DSL for specifying grammar rules, and a simple mechanism for specifying a (bare-bones but usable) scanner that interacts with the grammar.
Using this, you can specify a grammar more succinctly as in
and instead of repeatedly callling
parser.token(...)
you'd callSimpleGrammar.feed(text, parser)
to invoke the scanner derived from the token declarations.This is essentially a forward port of the
yv/parsing
fork to the mainline parsing repo. I haven't ported the tests yet, and one potentially controversial item that's yet to be ported is an addition toreduce
that addstype
andrange
attributes to the nonterminals where the reduction method returns None. This makes it easier to create sensible ASTs from simple grammar descriptions.I've put "WIP" in the title to signify that there are things missing from a merge-able state, but that I'm already interested in opinions/comments on this.