Skip to content

♻️ refactor(cst): deduplicate parser with shared helpers and improve Trivia::comment API#1231

Merged
harehare merged 3 commits intomainfrom
refactor/cst-parser-dedup-helpers
Feb 7, 2026
Merged

♻️ refactor(cst): deduplicate parser with shared helpers and improve Trivia::comment API#1231
harehare merged 3 commits intomainfrom
refactor/cst-parser-dedup-helpers

Conversation

@harehare
Copy link
Copy Markdown
Owner

@harehare harehare commented Feb 7, 2026

No description provided.

…Trivia::comment API

Extract parse_separated_list(), peek_token(), and parse_selector_bracket() helpers
to eliminate repeated patterns in the CST parser. Change Trivia::comment() to return
Option<&str> instead of String to avoid unnecessary allocations.
Copilot AI review requested due to automatic review settings February 7, 2026 10:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the CST parser to reduce duplication by introducing shared parsing helpers, and adjusts the Trivia::comment API to return an optional borrowed string slice.

Changes:

  • Replace repeated “peek + loop + comma/close handling” with a shared parse_separated_list helper.
  • Extract selector bracket parsing ([N]) into parse_selector_bracket.
  • Change Trivia::comment() to return Option<&str> and update comment collection/tests accordingly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
crates/mq-lang/src/cst/parser.rs Introduces shared helpers (peek_token, parse_separated_list, parse_selector_bracket) and rewires call sites to reduce duplicated list/selector parsing logic.
crates/mq-lang/src/cst/node.rs Updates Trivia::comment to return Option<&str> and adjusts Node::comments plus unit tests to match the new API.

let token = Shared::clone(self.peek_token()?);
if close_token(&token.kind) {
let leading_trivia = self.parse_leading_trivia();
let token = self.tokens.next().unwrap();
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new parse_separated_list helper introduces multiple unwrap() calls on self.tokens.next(). Even if logically guarded today, project guidelines discourage panics in parsing code. Prefer converting these to ok_or(ParseError::UnexpectedEOFDetected)? (or equivalent) so unexpected stream states become parse errors rather than panics.

Copilot uses AI. Check for mistakes.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 7, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing refactor/cst-parser-dedup-helpers (e60ea01) with main (5479ab8)

Open in CodSpeed

…g NotFound

Refactor module import error handling from if-let chain to match expression,
which properly propagates the original ModuleError variant (e.g., IOError)
instead of converting all non-AlreadyLoaded errors to NotFound.
@harehare harehare requested a review from Copilot February 7, 2026 12:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

@harehare harehare merged commit df71121 into main Feb 7, 2026
7 checks passed
@harehare harehare deleted the refactor/cst-parser-dedup-helpers branch February 7, 2026 12:28
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.

2 participants