Skip to content

Fix all remaining ParseError::new deprecation warnings - #195

Merged
logbie merged 1 commit into
parserrefactorfrom
devin/1765135204-fix-clippy-warnings
Dec 8, 2025
Merged

Fix all remaining ParseError::new deprecation warnings#195
logbie merged 1 commit into
parserrefactorfrom
devin/1765135204-fix-clippy-warnings

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

Fix all ParseError::new deprecation warnings in parser module

Summary

This PR completes the migration from the deprecated ParseError::new() API to the modern ParseError::from_token() and ParseError::from_span() constructors across the entire parser module. The new API provides proper span information for better error diagnostics.

Changes include:

  • Replaced ~182 ParseError::new() calls with the appropriate modern constructor
  • Fixed needless_borrow clippy warnings via cargo clippy --fix
  • Added #[allow(clippy::type_complexity)] for a complex return type in containers.rs
  • Fixed parse_count_loop to capture count_token at function start for proper error reporting
  • Removed unused for_token variable in parse_for_each_loop

Review & Testing Checklist for Human

  • Verify parse_count_loop behavior: The function now captures count_token = self.bump_sync().unwrap() instead of just self.bump_sync(). Confirm this doesn't change parsing behavior for count loops.
  • Spot-check token selection for errors: In several places, I chose which token to use for error reporting. Verify that errors like "Expected 'to' or 'down to'" use a sensible token for the error location.
  • Check placeholder spans: Some end-of-input errors use Span { start: 0, end: 0 } as a placeholder. This matches the deprecated API behavior but may warrant future improvement.

Recommended test plan: Run the full test suite and verify clippy passes with -D warnings. The pre-existing test_complete_completion_workflow failure in wfl-lsp is unrelated to these changes (confirmed by testing before/after).

Notes

Summary by CodeRabbit

  • New Features
    • Added HTTP GET statement support, enabling URL-based data retrieval operations.

✏️ Tip: You can customize this high-level summary in your review settings.

- Replace all ParseError::new() calls with ParseError::from_token() or ParseError::from_span()
- Fix needless_borrow clippy warnings via cargo clippy --fix
- Add #[allow(clippy::type_complexity)] for complex return type in containers.rs
- Capture count_token at start of parse_count_loop for proper error reporting

Files modified:
- src/parser/expr/binary.rs (1 usage)
- src/parser/expr/primary.rs (27 usages)
- src/parser/mod.rs (8 usages)
- src/parser/mod_complete.rs (13 usages)
- src/parser/stmt/actions.rs (17 usages)
- src/parser/stmt/collections.rs (needless_borrow fixes)
- src/parser/stmt/containers.rs (31 usages + type_complexity)
- src/parser/stmt/control_flow.rs (12 usages)
- src/parser/stmt/errors.rs (needless_borrow fixes)
- src/parser/stmt/io.rs (21 usages)
- src/parser/stmt/patterns.rs (53 usages)
- src/parser/stmt/processes.rs (needless_borrow fixes)

This completes the migration from the deprecated ParseError::new() API to the modern from_token/from_span constructors, which provide proper span information for better error diagnostics.

Co-Authored-By: Bradley Byrd <bsbyrd@logbie.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai

coderabbitai Bot commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The PR refactors parser error handling across 12 files, replacing raw line/column coordinates with token-based error constructors. Error creation now consistently uses ParseError::from_token() and ParseError::from_span() to carry token context. Additionally, a new Statement::HttpGetStatement variant is introduced for HTTP URL parsing in the I/O module.

Changes

Cohort / File(s) Summary
Expression parsing error refactoring
src/parser/expr/binary.rs, src/parser/expr/primary.rs
Replaced ParseError::new(...) constructors with ParseError::from_token(...) and ParseError::from_span(...), passing token references instead of raw line/column coordinates to embed token context in error messages.
Core parser module refactoring
src/parser/mod.rs, src/parser/mod_complete.rs
Consistently replaced ParseError::new(line, column) with token-based constructors across all error paths—unexpected tokens, end-of-input, and identifier parsing now attach token or span context.
Statement parsing error standardization
src/parser/stmt/actions.rs, src/parser/stmt/collections.rs, src/parser/stmt/control_flow.rs, src/parser/stmt/errors.rs, src/parser/stmt/patterns.rs, src/parser/stmt/processes.rs
Unified error construction across statement parsers to use from_token and from_span with token references, removed borrowed references (&token → token), and adjusted intermediate token captures for error position derivation.
Statement parsing enhancements
src/parser/stmt/containers.rs, src/parser/stmt/io.rs
Added #[allow(clippy::type_complexity)] attribute to parse_container_body in ContainerParser trait; introduced new public enum variant Statement::HttpGetStatement { url, variable_name, line, column } for HTTP URL request handling in file-open parsing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

Areas requiring extra attention:

  • src/parser/stmt/io.rs: Review the new HttpGetStatement variant for correct parameter ordering and integration with existing file-open parsing logic.
  • src/parser/stmt/patterns.rs: Verify the new reserved keyword check (is_reserved_pattern_name) is applied consistently and that token-contextual errors are correctly propagated.
  • Cross-file consistency: Ensure all error constructor replacements consistently use from_token vs. from_span and that token-passing conventions (by value vs. reference) are uniform across statement parsers.
  • Homogeneous refactoring verification: Spot-check 2–3 representative files (e.g., mod.rs, actions.rs, patterns.rs) to confirm error messages remain clear and token context is properly attached.

Possibly related PRs

Poem

🐰 Errors now speak through tokens' tongue,
No more bare lines where bugs are flung!
From spans we've built a clearer way,
And HTTP dreams can parse the day! 🌐
~Hop, refactor, parse with glee!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.20% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main objective: fixing remaining ParseError::new deprecation warnings throughout the parser module.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1765135204-fix-clippy-warnings

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 and usage tips.

@logbie

logbie commented Dec 8, 2025

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 8, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
src/parser/stmt/actions.rs (1)

437-445: Lost location information in container action definition.

The ActionDefinition at lines 437-444 hardcodes line: 0, column: 0, losing the location where the action was defined. Consider capturing the position when consuming "action" at line 333:

     fn parse_container_action_definition(&mut self) -> Result<Statement, ParseError>
     where
         Self: StmtParser<'a>,
     {
-        self.bump_sync(); // Consume "action"
+        let action_token = self.bump_sync().unwrap(); // Consume "action"

         // ... rest of the function ...

         Ok(Statement::ActionDefinition {
             name,
             parameters,
             body,
             return_type,
-            line: 0,
-            column: 0,
+            line: action_token.line,
+            column: action_token.column,
         })
src/parser/mod_complete.rs (1)

231-234: Compilation error: self.cursor does not exist in this parser.

The Parser struct in this file uses self.tokens: Peekable<Iter<'a, TokenWithPosition>>, not self.cursor. Line 232 calls self.cursor.error(...) which will fail to compile.

         } else {
-            Err(self.cursor.error("Unexpected end of input".to_string()))
+            Err(ParseError::from_span(
+                "Unexpected end of input".to_string(),
+                crate::diagnostics::Span { start: 0, end: 0 },
+                0,
+                0,
+            ))
         }
src/parser/stmt/processes.rs (1)

181-191: Simplify token retrieval for "wait" statement.

The current pattern using map_or with an inline temporary TokenWithPosition is unclear and creates a reference to a short-lived default. Since the code expects a "wait" token to be present (it calls bump_sync() immediately after), use bump_sync().unwrap() instead to consume and retrieve the token directly:

-        let wait_token_pos = self.cursor.peek().map_or(
-            &TokenWithPosition {
-                token: Token::KeywordWait,
-                line: 0,
-                column: 0,
-                length: 0,
-                byte_start: 0,
-                byte_end: 0,
-            },
-            |v| v,
-        );
-
-        self.bump_sync(); // Consume "wait"
+        let wait_token_pos = self.bump_sync().unwrap(); // Consume "wait"

This simplifies the code and eliminates the problematic reference pattern seen elsewhere.

🧹 Nitpick comments (8)
src/parser/stmt/containers.rs (1)

361-384: Redundant extends_token clone and convoluted control flow.

The extends_token is cloned before peek() but the else if at line 372 can only be reached when self.cursor.peek() returned Some, making extends_token always Some at that point. The fallback to from_span at lines 378-383 is unreachable.

Consider simplifying:

-            let extends_token = self.cursor.peek().cloned();
             if let Some(token) = self.cursor.peek() {
                 if let Token::Identifier(id) = &token.token {
                     extends = Some(id.clone());
                     self.bump_sync(); // Consume the identifier
                 } else {
                     return Err(ParseError::from_token(
                         "Expected identifier after 'extends'".to_string(),
                         token,
                     ));
                 }
-            } else if let Some(ref ext_tok) = extends_token {
-                return Err(ParseError::from_token(
-                    "Expected identifier after 'extends'".to_string(),
-                    ext_tok,
-                ));
             } else {
                 return Err(ParseError::from_span(
                     "Expected identifier after 'extends'".to_string(),
                     crate::diagnostics::Span { start: 0, end: 0 },
                     0,
                     0,
                 ));
             }
src/parser/stmt/errors.rs (1)

322-326: Verify ownership vs reference for try_token.

The from_token method signature takes &TokenWithPosition, but line 324 passes try_token by value. While Rust's auto-ref will handle this, the inconsistency with other call sites (which pass &token or token directly on borrowed values) may cause confusion.

For consistency with the rest of the codebase where owned tokens are passed:

             return Err(ParseError::from_token(
                 "Try statement must have at least one 'when' or 'catch' clause".to_string(),
-                try_token,
+                &try_token,
             ));
src/parser/mod_complete.rs (1)

251-258: Inconsistent reference handling.

Line 253 passes token (borrowed from peek()) directly, while line 257 passes &token_pos. For consistency when the token is borrowed from peek():

                     return Err(ParseError::from_token(
                         format!("Expected identifier after 'as', found {:?}", token.token),
-                        token,
+                        &token,
                     ));
src/parser/expr/primary.rs (1)

89-94: Potential issue: Using cloned token after its original source.

Line 90-93 uses &token where token was cloned from peek() at line 22. After consuming the left paren at line 76 and parsing an expression, &token still references the original LeftParen token, not the current position. This is technically correct but may produce confusing error messages pointing to ( when the issue is missing ) at end of input.

Consider using the last known position:

                     } else {
-                        return Err(ParseError::from_token(
+                        return Err(ParseError::from_span(
                             "Expected closing parenthesis, found end of input".into(),
-                            &token,
+                            crate::diagnostics::Span { start: 0, end: 0 },
+                            token.line,
+                            token.column,
                         ));
                     }
src/parser/stmt/io.rs (1)

433-433: Inconsistent error construction pattern.

Line 433 uses self.cursor.error() while the rest of this function uses ParseError::from_token() for end-of-input errors. For consistency with the PR's goal and to provide better span information, consider using ParseError::from_token() with open_token.

                 } else {
-                    return Err(self.cursor.error("Unexpected end of input".to_string()));
+                    return Err(ParseError::from_token(
+                        "Unexpected end of input".to_string(),
+                        open_token,
+                    ));
                 }
src/parser/stmt/control_flow.rs (3)

268-293: Consider capturing for_token for better end-of-input error reporting.

The parse_count_loop function captures count_token at line 364 for error reporting, but parse_for_each_loop does not capture the "for" token. This causes the end-of-input error at line 287-292 to use a placeholder span {start: 0, end: 0} instead of pointing to the "for" keyword.

     fn parse_for_each_loop(&mut self) -> Result<Statement, ParseError>
     where
         Self: StmtParser<'a>,
     {
-        self.bump_sync(); // Consume "for"
+        let for_token = self.bump_sync().unwrap(); // Consume "for"
 
         self.expect_token(Token::KeywordEach, "Expected 'each' after 'for'")?;
 
         let item_name = if let Some(token) = self.cursor.peek() {
             if let Token::Identifier(id) = &token.token {
                 self.bump_sync();
                 id.clone()
             } else {
                 return Err(ParseError::from_token(
                     format!("Expected identifier after 'each', found {:?}", token.token),
                     token,
                 ));
             }
         } else {
-            return Err(ParseError::from_span(
+            return Err(ParseError::from_token(
                 "Unexpected end of input after 'each'".to_string(),
-                crate::diagnostics::Span { start: 0, end: 0 },
-                0,
-                0,
+                for_token,
             ));
         };

339-357: ForEachLoop statement uses post-loop token position.

The line and column fields are derived from peek() after consuming "end for", which points to the token after the loop rather than the loop's start. If you capture for_token as suggested above, use it here for consistent positioning:

-        let token_pos = self.cursor.peek().map_or(
-            &TokenWithPosition {
-                token: Token::KeywordFor,
-                line: 0,
-                column: 0,
-                length: 0,
-                byte_start: 0,
-                byte_end: 0,
-            },
-            |v| v,
-        );
         Ok(Statement::ForEachLoop {
             item_name,
             collection,
             reversed,
             body,
-            line: token_pos.line,
-            column: token_pos.column,
+            line: for_token.line,
+            column: for_token.column,
         })

476-496: CountLoop statement uses post-loop token position instead of count_token.

You already capture count_token at line 364. Use it for the statement's line/column instead of peeking at the token after "end count":

-        let token_pos = self.cursor.peek().map_or(
-            &TokenWithPosition {
-                token: Token::KeywordCount,
-                line: 0,
-                column: 0,
-                length: 0,
-                byte_start: 0,
-                byte_end: 0,
-            },
-            |v| v,
-        );
         Ok(Statement::CountLoop {
             start,
             end,
             step,
             downward,
             variable_name,
             body,
-            line: token_pos.line,
-            column: token_pos.column,
+            line: count_token.line,
+            column: count_token.column,
         })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83b2985 and dd0486a.

📒 Files selected for processing (12)
  • src/parser/expr/binary.rs (1 hunks)
  • src/parser/expr/primary.rs (16 hunks)
  • src/parser/mod.rs (7 hunks)
  • src/parser/mod_complete.rs (8 hunks)
  • src/parser/stmt/actions.rs (8 hunks)
  • src/parser/stmt/collections.rs (3 hunks)
  • src/parser/stmt/containers.rs (16 hunks)
  • src/parser/stmt/control_flow.rs (7 hunks)
  • src/parser/stmt/errors.rs (1 hunks)
  • src/parser/stmt/io.rs (12 hunks)
  • src/parser/stmt/patterns.rs (32 hunks)
  • src/parser/stmt/processes.rs (4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Format Rust code using cargo fmt --all (see .rustfmt.toml)
Lint clean: run cargo clippy --all-targets --all-features -- -D warnings with no warnings
Use snake_case for function and file names in Rust
Use CamelCase for types and traits in Rust
Use SCREAMING_SNAKE_CASE for constants in Rust
Review SECURITY.md; avoid logging secrets and prefer zeroization for sensitive data in Rust code

Use Rust edition 2024 for all Rust source files

Files:

  • src/parser/stmt/actions.rs
  • src/parser/stmt/errors.rs
  • src/parser/stmt/processes.rs
  • src/parser/mod_complete.rs
  • src/parser/expr/binary.rs
  • src/parser/stmt/containers.rs
  • src/parser/expr/primary.rs
  • src/parser/stmt/collections.rs
  • src/parser/stmt/patterns.rs
  • src/parser/stmt/io.rs
  • src/parser/stmt/control_flow.rs
  • src/parser/mod.rs
src/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.rs: Provide component documentation for all major modules in Rust source files
Implement comprehensive error diagnostics using codespan-reporting

Files:

  • src/parser/stmt/actions.rs
  • src/parser/stmt/errors.rs
  • src/parser/stmt/processes.rs
  • src/parser/mod_complete.rs
  • src/parser/expr/binary.rs
  • src/parser/stmt/containers.rs
  • src/parser/expr/primary.rs
  • src/parser/stmt/collections.rs
  • src/parser/stmt/patterns.rs
  • src/parser/stmt/io.rs
  • src/parser/stmt/control_flow.rs
  • src/parser/mod.rs
src/parser/**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

Update bytecode when modifying parser in Rust source code

Files:

  • src/parser/stmt/actions.rs
  • src/parser/stmt/errors.rs
  • src/parser/stmt/processes.rs
  • src/parser/mod_complete.rs
  • src/parser/expr/binary.rs
  • src/parser/stmt/containers.rs
  • src/parser/expr/primary.rs
  • src/parser/stmt/collections.rs
  • src/parser/stmt/patterns.rs
  • src/parser/stmt/io.rs
  • src/parser/stmt/control_flow.rs
  • src/parser/mod.rs
🧠 Learnings (2)
📚 Learning: 2025-12-05T10:17:06.457Z
Learnt from: CR
Repo: WebFirstLanguage/wfl PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-05T10:17:06.457Z
Learning: Applies to src/**/*.rs : Implement comprehensive error diagnostics using codespan-reporting

Applied to files:

  • src/parser/stmt/actions.rs
  • src/parser/mod_complete.rs
  • src/parser/expr/binary.rs
  • src/parser/expr/primary.rs
  • src/parser/stmt/patterns.rs
  • src/parser/stmt/control_flow.rs
  • src/parser/mod.rs
📚 Learning: 2025-12-05T10:17:06.457Z
Learnt from: CR
Repo: WebFirstLanguage/wfl PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-05T10:17:06.457Z
Learning: Applies to src/parser/**/*.rs : Update bytecode when modifying parser in Rust source code

Applied to files:

  • src/parser/stmt/actions.rs
  • src/parser/stmt/processes.rs
  • src/parser/mod_complete.rs
  • src/parser/expr/binary.rs
  • src/parser/expr/primary.rs
  • src/parser/stmt/patterns.rs
  • src/parser/mod.rs
🧬 Code graph analysis (11)
src/parser/stmt/actions.rs (1)
src/parser/ast.rs (2)
  • from_token (791-802)
  • from_span (776-788)
src/parser/stmt/processes.rs (1)
src/parser/ast.rs (1)
  • from_token (791-802)
src/parser/mod_complete.rs (1)
src/parser/ast.rs (2)
  • from_token (791-802)
  • from_span (776-788)
src/parser/expr/binary.rs (2)
src/parser/cursor.rs (1)
  • error (440-447)
src/parser/ast.rs (1)
  • from_span (776-788)
src/parser/stmt/containers.rs (1)
src/parser/ast.rs (2)
  • from_token (791-802)
  • from_span (776-788)
src/parser/expr/primary.rs (1)
src/parser/ast.rs (2)
  • from_token (791-802)
  • from_span (776-788)
src/parser/stmt/collections.rs (1)
src/parser/ast.rs (1)
  • from_token (791-802)
src/parser/stmt/patterns.rs (1)
src/parser/ast.rs (2)
  • from_token (791-802)
  • from_span (776-788)
src/parser/stmt/io.rs (1)
src/parser/ast.rs (1)
  • from_token (791-802)
src/parser/stmt/control_flow.rs (1)
src/parser/ast.rs (2)
  • from_token (791-802)
  • from_span (776-788)
src/parser/mod.rs (1)
src/parser/ast.rs (2)
  • from_token (791-802)
  • from_span (776-788)
🔇 Additional comments (27)
src/parser/stmt/containers.rs (2)

24-38: LGTM - Clippy suppression for complex return type.

The #[allow(clippy::type_complexity)] attribute is appropriate here given the 5-tuple return type. This aligns with the PR objective.


72-84: Consistent token-based error reporting.

The migration to from_token correctly provides span context from the actual token for better diagnostics.

src/parser/expr/binary.rs (1)

608-616: Appropriate use of from_span for end-of-input error.

Using from_span with call_line and call_column preserves location context from the call keyword when no token is available. The placeholder span matches prior behavior as noted in the PR description.

src/parser/stmt/processes.rs (1)

53-64: Token ownership handling is correct.

Both token_pos (from bump_sync) and var_token (from bump_sync) are owned, and Rust's auto-ref handles passing them to from_token(&TokenWithPosition).

src/parser/stmt/collections.rs (2)

31-43: Correct token-based error reporting for list creation.

The error paths correctly use from_token with the relevant token context - either the unexpected token or the create_token for end-of-input scenarios.


175-187: Good error context for add operation failures.

Using add_token for both missing "to" keyword and end-of-input provides consistent error location pointing to where the add statement began.

src/parser/mod_complete.rs (1)

93-97: Correct error construction for orphaned 'end' tokens.

Using from_token with first_token properly captures the location of the unexpected 'end' keyword.

src/parser/stmt/actions.rs (1)

49-56: Correct pattern for avoiding borrow conflicts.

Cloning the token to err_token before using it in the error message and from_token call correctly avoids borrow checker issues when the message formats err_token.token.

src/parser/expr/primary.rs (3)

59-73: Good error handling for list literal parsing.

The errors correctly capture context - using the unexpected token for separator errors and bracket_token for end-of-input to point back to where the list started.


569-576: Correct clone-before-use pattern.

The err_token = next_token.clone() at line 570 correctly avoids borrowing issues when both formatting the message and passing to from_token.


1168-1174: Consistent end-of-input handling.

Using from_span with placeholder span and zeros for line/column matches the established pattern for end-of-input scenarios where no token context is available.

src/parser/stmt/io.rs (3)

248-260: LGTM - Error construction correctly uses token context.

The error handling properly uses ParseError::from_token() with the appropriate token reference (&token for the unexpected token case, open_token for end-of-input). This provides accurate span information for diagnostics.


264-269: New HttpGetStatement variant looks good.

The new Statement::HttpGetStatement is correctly constructed with URL expression and variable name, using open_token for line/column info.


704-716: LGTM - Proper token-based error handling in parse_delete_statement.

The error construction correctly uses from_token(next_token) for unexpected tokens and from_token(token_pos) for end-of-input, providing accurate diagnostic spans.

src/parser/stmt/control_flow.rs (2)

121-143: LGTM - If statement error handling uses correct token context.

The error paths correctly use ParseError::from_token() with the appropriate token references: next_token for unexpected tokens, token for the "end" token when EOF follows, and check_token for complete end-of-input scenarios.


364-364: LGTM - count_token captured and used for error reporting.

The modification to capture count_token at function start enables proper span information in error messages for end-of-input scenarios, as noted in the PR objectives.

Also applies to: 380-398

src/parser/stmt/patterns.rs (5)

59-63: LGTM - Token clone correctly handles borrow scope.

The err_token = token.clone() pattern is necessary here because token is borrowed from the match, and we need to use it in the error return after the match arm. This is the correct approach.


185-200: LGTM - Consistent error handling in parse_extension_filter.

The error handling correctly uses from_token when a token is available (lines 187-190) and from_span with placeholder values for end-of-input (lines 194-199).


211-218: Placeholder span for empty pattern definition is acceptable.

Using Span { start: 0, end: 0 } for an empty pattern definition is reasonable since there's no token to reference. This matches the PR's documented behavior for end-of-input errors.


860-866: LGTM - Lookahead/lookbehind brace matching errors use correct token.

The unmatched brace errors correctly reference &tokens[pattern_start - 1] which is the opening brace token, providing accurate span information for the diagnostic.

Also applies to: 914-920


629-634: *Safe to approve: accessing tokens[i - 1] in error paths is protected by control flow.

The pattern in lines 629–634, 651–656, and 673–678 is safe. At each of these error sites, *i has been incremented (lines 615, 637, 659 respectively) before the bounds check, guaranteeing *i > 0 when the else branch executes and tokens[*i - 1] is accessed. The logic is sound given the code structure.

src/parser/mod.rs (6)

187-190: LGTM - Orphaned 'end' error uses from_token correctly.

The error for unexpected 'end' followed by unknown token now properly uses ParseError::from_token() with first_token, providing accurate span information.


283-286: LGTM - Variable name parsing errors use correct token context.

The error handling in parse_variable_name_list correctly uses from_token(&token) for various error cases (number as variable name, reserved keyword, etc.).

Also applies to: 295-301, 310-316


320-325: Placeholder span for end-of-input is consistent with PR approach.

Using from_span with Span { start: 0, end: 0 } for the "end of input" case in parse_variable_name_list is consistent with other end-of-input handling in this PR.


381-393: LGTM - Comprehensive error handling for parse_variable_name_simple.

The new if-else structure properly handles both cases: when a token is available (use from_token) and when at end-of-input (use from_span with placeholder). This is the correct pattern.


486-497: LGTM - Read statement errors use from_token correctly.

The error handling for unexpected 'read' statements properly uses from_token(token_pos) with the peeked token.


535-536: Consistent use of cursor.error() for top-level end-of-input.

The parse_statement function uses self.cursor.error() for the end-of-input case. This is consistent with the existing pattern in this function and provides a reasonable fallback. The cursor likely implements appropriate error construction internally.

@logbie
logbie merged commit 14f4af9 into parserrefactor Dec 8, 2025
3 of 4 checks passed
@logbie
logbie deleted the devin/1765135204-fix-clippy-warnings branch December 8, 2025 04:56
logbie added a commit that referenced this pull request Dec 8, 2025
Merge pull request #195 from WebFirstLanguage/devin/1765135204-fix-clippy-warnings
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