Skip to content

Simplify grammar by factoring duplicated rule shapes - #3858

Merged
codeshaunted merged 1 commit into
canaryfrom
avery/grammar-simplify
Jun 26, 2026
Merged

codeshaunted merged 1 commit into
canaryfrom
avery/grammar-simplify

Conversation

@codeshaunted

@codeshaunted codeshaunted commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

DRY cleanup of typescript2/pkg-grammar/src/baml.ts — no behavior change.

Byte-identical output. baml.tmLanguage.json, its app-vscode-ext mirror, and all 79 grammar snapshots are unchanged. Verified: the distinct begin/end/match regex set and the scope set are identical, and the repository entry count is unchanged (255). Only src/baml.ts differs.

What changed (all in src/baml.ts):

  • CALL_ARGS_LOOKAHEAD const for the (?=\s*(?:<…>\s*)?\() call lookahead that was hand-copied at three call begins
  • memberCall / memberAccess factories for the four near-identical optional/postfix method-call and field-access rules (they differ only by the ?. vs [.$] accessor)
  • isPatternRule factory for the two is-expression variants
  • keywordStatement factory for return / break / continue / defer / watch
  • interpolationKeyword factory for the backtick else / endfor / endif controls
  • deleted the dead block const (never referenced, never emitted)

Note: this is a de-duplication refactor, not a line reduction — the grammar was already slimmed, so the factory definitions roughly offset the call-site savings (net +21 lines). The value is one-source-of-truth: a future change to e.g. the call lookahead now touches one site instead of three.

Based on canary (the grammar from #3843 is merged).

Summary by CodeRabbit

  • Bug Fixes
    • Improved syntax highlighting consistency for function calls, field access, pattern matching, and control-flow keywords.
    • Better handling of optional chaining, postfix calls, and backtick interpolation markers.
  • Refactor
    • Simplified the grammar by sharing common matching logic across related language forms.

DRY cleanup of typescript2/pkg-grammar/src/baml.ts. The emitted grammar is
byte-identical: baml.tmLanguage.json, its app-vscode-ext mirror, and all 79
snapshots are unchanged.

- CALL_ARGS_LOOKAHEAD const for the call `(?=...<...>...\()` lookahead that was
  hand-copied at three call begins
- memberCall / memberAccess factories for the four near-identical optional /
  postfix method-call and field-access rules (differ only by the `?.` vs `[.$]`
  accessor)
- isPatternRule factory for the two `is`-expression variants
- keywordStatement factory for return / break / continue / defer / watch
- interpolationKeyword factory for the backtick else / endfor / endif controls
- delete the dead `block` const (never referenced, never emitted)

This removes repetition rather than lines (the grammar was already slimmed): a
future change to e.g. the call lookahead now touches one site instead of three.
@vercel

vercel Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jun 26, 2026 8:10pm
promptfiddle Ready Ready Preview, Comment Jun 26, 2026 8:10pm
promptfiddle2 Ready Ready Preview, Comment Jun 26, 2026 8:10pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a702521c-c566-4223-b579-114bfab5a615

📥 Commits

Reviewing files that changed from the base of the PR and between 62cc633 and 20fa1f4.

📒 Files selected for processing (1)
  • typescript2/pkg-grammar/src/baml.ts

📝 Walkthrough

Walkthrough

The BAML TextMate grammar consolidates repeated rule definitions into shared helpers for member calls and access, is patterns, interpolation keywords, and keyword statements, and removes one generic block rule.

Changes

BAML grammar helper refactors

Layer / File(s) Summary
Generic block rule removal
typescript2/pkg-grammar/src/baml.ts
Removes the generic block grammar rule from the literals section.
Shared member-call and access helpers
typescript2/pkg-grammar/src/baml.ts
Adds CALL_ARGS_LOOKAHEAD, memberCall(...), and memberAccess(...), and rewrites function-call-expression plus the optional and postfix member rules to use them.
Shared is-pattern helper
typescript2/pkg-grammar/src/baml.ts
Adds isPatternRule(...) and rewires the expression and condition-position is pattern rules through the helper.
Backtick interpolation keyword helper
typescript2/pkg-grammar/src/baml.ts
Adds interpolationKeyword(...) and replaces the explicit else, endfor, and endif interpolation rules with helper-generated versions.
Shared keyword statement helper
typescript2/pkg-grammar/src/baml.ts
Adds keywordStatement(...) and rewrites the return, break, continue, defer, and watch statements to use it.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop, hop—my grammar garden glows,
With shared little helpers in tidy rows.
Calls and patterns now twirl with ease,
Keywords rustle like burrow-breezes.
Hooray for code that rhymes and flows!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the refactor to factor out duplicated grammar rule shapes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch avery/grammar-simplify

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@vercel
vercel Bot temporarily deployed to Preview – beps June 26, 2026 19:52 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 June 26, 2026 19:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle June 26, 2026 20:10 Inactive
@codeshaunted
codeshaunted added this pull request to the merge queue Jun 26, 2026
Merged via the queue into canary with commit 6cb913c Jun 26, 2026
34 checks passed
@codeshaunted
codeshaunted deleted the avery/grammar-simplify branch June 26, 2026 22:50

This branch was previously deployed

3 inactive deployments
Preview – promptfiddle — 20fa1f45 Deployed Jun 26, 2026 by vercel[bot]
Preview – promptfiddle2 — 20fa1f45 Deployed Jun 26, 2026 by vercel[bot]
Preview – beps — 20fa1f45 Deployed Jun 26, 2026 by vercel[bot]
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