-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp the PieceWriter API some. (#1298)
Revamp the PieceWriter API some. The current API is pretty confusing around when you should use `pop()`, `split()`, or both. If you get it wrong, sometimes it silently works but may leave a bug for later, or sometimes it fails it seemingly unrelated ways. Also, it's not clear whether you should call `pop()` first or `split()`. (It actually didn't matter.) I tried to simplify the API some. It's still more subtle and brittle than I would like, but it's not clear to me if the complexity is essential. I'm trying to build Piece trees that don't have unnecessary nodes, so some slippage between AST node boundaries and Piece tree boundaries is essential. I hope this API is better. The changes are: - Make `split()` implicitly `pop()` the previous piece. This means you never need to call both `split()` and `pop()`. Just call `split()`. You do still have to know when to prefer `pop()` instead of `split()`, but I added some documentation to try to clarify that. - Rename the main PieceWriter field from `writer` to `pieces`. I think this reads a little better at the callsites and makes it clearer what is being pushed, popped, and split. "Writer" doesn't really mean much. - Rename `space()` to `writeSpace()`. Then add a helper method in PieceFactory called `space()`. This way, almost all calls on `pieces` deal with pieces and calls that recurse into or write pieces of an AST are bare function calls: `token()`, `visit()`, and `space()`. - Change `push()` to `give()` and `pop()` to `take()`. Co-authored-by: Nate Bosch <nbosch@google.com>
- Loading branch information
1 parent
cca55a3
commit 19f42a9
Showing
6 changed files
with
256 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.