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

Support eagerly pinning a piece to a specific state. #1291

Merged
merged 3 commits into from
Oct 21, 2023
Merged

Conversation

munificent
Copy link
Member

The BlockPiece had some bespoke support for being in an "always split" configuration that overrode the two different ways it could be formatted. While working on conditional expressions, I found myself needing something similar to InfixPiece.

Instead of adding similar code to that and likely other pieces in the future, I figured it made more sense to bake support for locking a piece into a specific state directly in the Piece base class.

The BlockPiece had some bespoke support for being in an "always split"
configuration that overrode the two different ways it could be
formatted. While working on conditional expressions, I found myself
needing something similar to InfixPiece.

Instead of adding similar code to that and likely other pieces in the
future, I figured it made more sense to bake support for locking a
piece into a specific state directly in the Piece base class.
lib/src/piece/block.dart Show resolved Hide resolved
lib/src/back_end/solution.dart Outdated Show resolved Hide resolved
- Rename State.initial to `State.unsplit` to describe what it
  represents. (This is a little bit of a misnomer for SequencePiece
  where there is still a hard newline between each child piece, but it's
  clearer for all of the other pieces.)

- Piece subclasses implement Piece.additionalStates to enumerate the
  possible set of states, if they support more than just `State.unsplit`.

- Have Piece.states return only the pinned state if there is one and
  otherwise return `State.unsplit` followed by `additionalStates`.

- Also reorganized the format code in InfixPiece to have less
  copy/paste.
@munificent munificent merged commit 15fef68 into main Oct 21, 2023
7 checks passed
@munificent munificent deleted the piece-pinning branch October 21, 2023 00:32
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.

3 participants