Conversation
…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.
Contributor
There was a problem hiding this comment.
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_listhelper. - Extract selector bracket parsing (
[N]) intoparse_selector_bracket. - Change
Trivia::comment()to returnOption<&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(); |
There was a problem hiding this comment.
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.
…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.
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.
No description provided.