chore: [#1411] dedup parser boilerplate in cst#1428
Open
milkyskies wants to merge 1 commit into
Open
Conversation
Three concrete duplications, three small fixes. Net -23 lines, no behavior change (parse trees identical, all 1654 + 114 LSP tests pass). - `expect_kind` was byte-identical to `expect`; deleted, 3 call sites in items.rs migrated. - Five binary-precedence parsers (or, and, equality, additive, multiplicative) collapse onto a `parse_left_assoc(ops, next)` helper. Pipe + comparison stay separate (match-into-pipe, newline guard). - `at_any(&[TokenKind])` helper replaces long `at(...) || at(...) || ...` chains, including the 13-op chain in dot-shorthand-predicate parsing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
closes #1411
Summary
Pure refactor — three concrete duplications collapsed in
crates/floe-core/src/cst.rsandcst/exprs.rs. Net -23 lines, no behavior change. All parse-tree-shaped tests still pass byte-for-byte.What changed
expectandexpect_kindwere byte-identicalexpect_kind, 3 call sites initems.rsmigrated toexpectparse_left_assoc(ops, next). Each parser is now a one-liner.at(...) || at(...) || ...chains, including a 13-op chain in dot-shorthand-predicate parsingat_any(&[TokenKind]). Applied at the 13-op chain and the 4-op comparison parser.parse_pipe_exprandparse_comparison_expropt out ofparse_left_assocbecause they need extra rules: pipe handlesmatch-into-pipe(x \|> match { ... }), and comparison has the!preceded_by_newline()guard for JSX disambiguation. Both still useat_anyinternally.The 2-token
Let \|\| Asyncchains initems.rswere left as||chains —at_anyonly earns its keep at 3+ alternatives.Backstory
Spotted by reviewers on #1409 (brace-form record construction):
parse_brace_construct_exprandparse_constructor_argsshared a lot of scaffolding. That specific dedup is a follow-up issue, but #1411 covered the three lower-hanging duplications in the same file area.Test plan
cargo clippy --workspace --lib -- -D warnings)🤖 Generated with Claude Code