fix: resolve merge conflict with master; clean up token visibility and check_op#57
Conversation
…token matching by introducing a zero-allocation `as_str()` method on `DelimTokenType` and using string references (`&str`) during tokenizer checks. This prevents creating new `String` instances whenever matching a parenthesis, bracket, or brace in the parser.\n\nAlso centralized check logic for Comma and Semicolon into `check_op`. Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #57 +/- ##
==========================================
+ Coverage 89.55% 89.67% +0.11%
==========================================
Files 11 11
Lines 1063 1065 +2
==========================================
+ Hits 952 955 +3
+ Misses 111 110 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request refactors DelimTokenType to use a zero-allocation as_str method and updates the check_op function to support Comma and Semicolon tokens. A critical logic bug was identified in the expect function within src/tokenizer.rs, where a token mismatch could incorrectly result in a successful return; it is recommended to refactor this function to use check_op for better consistency and correctness.
| match token { | ||
| Token::Delim(bracket, _) => { | ||
| if bracket.string() == op { | ||
| if bracket.as_str() == op { | ||
| return Ok(()); | ||
| } | ||
| } |
There was a problem hiding this comment.
The expect function contains a logic bug. If the token variant matches (e.g., Token::Delim) but the inner value does not match the expected op, the function currently falls through the match and returns Ok(()) at the end (line 166). This causes the parser to incorrectly assume the expectation was met when it actually failed.
Additionally, expect is missing a case for Token::Semicolon, which was added to check_op in this PR. To ensure consistency and correctness, consider refactoring expect to leverage the check_op function from src/token.rs.
There was a problem hiding this comment.
Pull request overview
This PR targets tokenizer/parser hot paths by avoiding heap allocations when comparing delimiter tokens, introducing a zero-allocation DelimTokenType::as_str() and switching delimiter comparisons to use it.
Changes:
- Added
DelimTokenType::as_str() -> &'static strand reimplementedstring()in terms of it. - Updated delimiter comparisons in
Tokenizer::expectandcheck_opto useas_str()instead of allocating viastring(). - Expanded
check_opto also treatToken::CommaandToken::Semicolonas comparable op tokens.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/tokenizer.rs | Switches delimiter comparison in expect() to DelimTokenType::as_str() to avoid allocations. |
| src/token.rs | Adds as_str() for delimiter tokens, updates check_op to avoid allocations, and broadens check_op matching to comma/semicolon. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.next()?; | ||
| match token { | ||
| Token::Delim(bracket, _) => { | ||
| if bracket.string() == op { | ||
| if bracket.as_str() == op { | ||
| return Ok(()); |
There was a problem hiding this comment.
In Tokenizer::expect, when the token is a Delim (and similarly for other op-like tokens), a mismatch with op does not produce an error; it falls through and the function ultimately returns Ok(()) after advancing. This can silently accept invalid syntax. Consider returning Err(Error::ExpectedOpNotExist(op.to_string())) (or similar) whenever the token value doesn't equal op.
src/token.rs
Outdated
| pub fn as_str(&self) -> &'static str { | ||
| use DelimTokenType::*; | ||
| match self { | ||
| OpenParen => "(".to_string(), | ||
| CloseParen => ")".to_string(), | ||
| OpenBracket => "[".to_string(), | ||
| CloseBracket => "]".to_string(), | ||
| OpenBrace => "{".to_string(), | ||
| CloseBrace => "}".to_string(), | ||
| Unknown => "??".to_string(), | ||
| OpenParen => "(", | ||
| CloseParen => ")", |
There was a problem hiding this comment.
New DelimTokenType::as_str() and the expanded check_op behavior (now matching Comma/Semicolon) are not covered by unit tests in this module. Adding small table-driven tests for as_str() outputs and check_op on comma/semicolon would help prevent regressions in this tokenizer hot path.
Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
src/token.rs
Outdated
| } | ||
| } | ||
|
|
||
| #[cfg(not(tarpaulin_include))] |
|
@copilot fix merge conflict |
…-comparison-9775148041958261230 # Conflicts: # src/token.rs Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
Merged
All 237 tests pass. |
Branch had diverged from
origin/masterafter consolidation PR #58 landed overlapping changes tosrc/token.rs, causing a merge conflict.Conflict resolutions
as_str()visibility: changed frompub→pub(crate)— avoids unnecessary public API expansionstring()attribute: removed#[cfg(not(tarpaulin_include))]— was flagged by clippy as an unknown cfg conditioncheck_op: preserved this PR'sComma/Semicolonmatching (unique contribution not in master), rewritten in master's concise one-expression-per-arm style:test_check_optable +test_delim_token_type_as_str+ close-delim tests, plus this branch'stest_check_op_comma,test_check_op_semicolon,test_is_question_mark,test_is_colon,test_is_eofsrc/context.rs,src/tokenizer.rs,src/value.rsfrom master applied cleanly with no conflicts