Skip to content

chore: [#1411] dedup parser boilerplate in cst#1428

Open
milkyskies wants to merge 1 commit into
mainfrom
chore/#1411.cst-parser-dedup
Open

chore: [#1411] dedup parser boilerplate in cst#1428
milkyskies wants to merge 1 commit into
mainfrom
chore/#1411.cst-parser-dedup

Conversation

@milkyskies
Copy link
Copy Markdown
Collaborator

closes #1411

Summary

Pure refactor — three concrete duplications collapsed in crates/floe-core/src/cst.rs and cst/exprs.rs. Net -23 lines, no behavior change. All parse-tree-shaped tests still pass byte-for-byte.

What changed

Duplication Fix
expect and expect_kind were byte-identical Deleted expect_kind, 3 call sites in items.rs migrated to expect
5 left-associative binary parsers (or, and, equality, additive, multiplicative) all followed the same checkpoint + while + bump + recurse template Extracted parse_left_assoc(ops, next). Each parser is now a one-liner.
Long at(...) || at(...) || ... chains, including a 13-op chain in dot-shorthand-predicate parsing Added at_any(&[TokenKind]). Applied at the 13-op chain and the 4-op comparison parser.

parse_pipe_expr and parse_comparison_expr opt out of parse_left_assoc because they need extra rules: pipe handles match-into-pipe (x \|> match { ... }), and comparison has the !preceded_by_newline() guard for JSX disambiguation. Both still use at_any internally.

The 2-token Let \|\| Async chains in items.rs were left as || chains — at_any only earns its keep at 3+ alternatives.

Backstory

Spotted by reviewers on #1409 (brace-form record construction): parse_brace_construct_expr and parse_constructor_args shared 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

  • All 1654 core unit tests pass (parse trees byte-identical pre/post)
  • All 114 LSP unit tests pass
  • Lib clippy clean (cargo clippy --workspace --lib -- -D warnings)
  • No example-app changes needed; no docs needed (internal compiler refactor)

🤖 Generated with Claude Code

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>
@github-actions github-actions Bot added the chore label May 4, 2026
@milkyskies milkyskies marked this pull request as ready for review May 4, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor parser duplication in cst.rs

1 participant