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

Scope memo expansions to sub-branches rather than globally #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maetl
Copy link
Collaborator

@maetl maetl commented Nov 15, 2022

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:

{
  start: "{report};{report}",
  report: "{@name}:{description}",
  description: "{@name}",
  name: ["fluorite", "pyrite", "sodalite"]
}

result.text => "pyrite:pyrite;pyrite:pyrite"

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.

{
  start: "{report};{report}",
  report: "{@@name}:{description}",
  description: "{@@name}",
  name: ["fluorite", "pyrite", "sodalite"]
}

result.text => "sodalite:sodalite;fluorite:fluorite"

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.

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.

```
{
  start: "{report};{report}",
  report: "{@@name}:{description}",
  description: "{@@name}",
  name: ["fluorite", "pyrite", "sodalite"]
}
```

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.
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.

1 participant