Scope memo expansions to sub-branches rather than globally #10
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 is an experimental new feature to enable memo expansions to be scoped to branches, meaning that the memos can be set multiple times for a single grammar run and will remain consistent throughout subtree expansions, but reset at higher levels of the tree.
Standard memo expansions are global, so the following grammar will always expand to the same repeating
name
:What we want here is to reuse sub-branches with the same text patterns while changing the memoized value at the top level branch, so that we can repeat the same expansion multiple times and get different results across each top level branch, while keeping the memoization consistent within the branch.
There are some problems with this implementation so it can’t be merged as-is, but it’s hopefully a useful starting point for further discussion both around the context of the feature and syntax change, and about the implementation.
What I’d also like to consider is if some of this functionality can be moved from the registry into the syntax nodes so that some of the random selection details can be better encapsulated, rather than letting the registry drive nearly all the behaviour.