Skip to content

Update parser to handle generics in parameter lists#50

Merged
leynos merged 3 commits into
mainfrom
codex/update-parser-for-nested-delimiters-handling
Jul 5, 2025
Merged

Update parser to handle generics in parameter lists#50
leynos merged 3 commits into
mainfrom
codex/update-parser-for-nested-delimiters-handling

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 4, 2025

Summary

  • support nested delimiters when parsing (name: type) pairs
  • test parsing of generic types in parameters

Testing

  • make fmt
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_68684fa95bd483228e45bc9de529407d

Summary by Sourcery

Enable parsing of generic types in function parameter lists by tracking nested delimiters across parentheses, angle brackets, brackets, and braces.

New Features:

  • Support nested generic types and other delimiters in parameter type declarations.

Enhancements:

  • Replace single depth counter with a DelimDepths struct to separately track nesting of parentheses, angle brackets, brackets, and braces when parsing parameter lists.

Tests:

  • Add parameter parsing tests for various generic and nested type scenarios, including angle shift cases and array-of-generic types.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 4, 2025

Reviewer's Guide

Reworks parameter parsing to support nested generics by replacing a flat depth counter with a DelimDepths struct that tracks multiple delimiter types, updates token handling for various bracket kinds and composite depth checks, and adds comprehensive tests for generic parameter scenarios.

Class diagram for updated delimiter depth tracking in parameter parsing

classDiagram
    class DelimDepths {
        +usize paren
        +usize angle
        +usize bracket
        +usize brace
    }

    class handle_token {
        +fn handle_token(..., depth: &mut DelimDepths)
    }

    DelimDepths <.. handle_token : used by
Loading

Class diagram for updated parameter parsing logic

classDiagram
    class name_type_pairs {
        +fn name_type_pairs(...)
    }
    class handle_token {
        +fn handle_token(...)
    }
    class DelimDepths {
        +usize paren
        +usize angle
        +usize bracket
        +usize brace
    }
    name_type_pairs --> handle_token : calls
    handle_token --> DelimDepths : uses
Loading

File-Level Changes

Change Details Files
Replace flat depth counter with a DelimDepths struct
  • Add DelimDepths struct with fields for paren, angle, bracket, brace
  • Initialize and pass DelimDepths instead of usize depth
  • Adjust existing depth references to use struct fields
src/parser/ast/parse_utils.rs
Extend handle_token to track nested delimiters
  • Implement match arms for T_LT, T_GT, T_SHL, T_SHR to manage angle brackets
  • Add handlers for T_LBRACKET/T_RBRACKET and T_LBRACE/T_RBRACE
  • Ensure buf push_str is applied after depth adjustments
src/parser/ast/parse_utils.rs
Update delimiter-based termination conditions
  • Change RPAREN, COMMA and COLON guards to check all depth fields are zero
  • Adjust RPAREN logic to decrement paren only when >0
  • Consolidate zero-depth checks for proper pair finalization
src/parser/ast/parse_utils.rs
Add tests for generic and nested generic parameters
  • Introduce rstest cases for simple and nested generics in parse_utils.rs
  • Add fixtures and tests in tests/parser.rs for Vec, Map, arrays, and shifted generics
  • Validate parsing of complex parameter lists and return types
src/parser/ast/parse_utils.rs
tests/parser.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 4, 2025

Summary by CodeRabbit

  • Documentation

    • Expanded documentation to explain how parameter lists with nested delimiters are parsed, improving clarity for users reading about function parsing.
  • Bug Fixes

    • Improved parsing of function parameters with complex generic and nested types, ensuring correct handling of nested delimiters and edge cases.
  • Tests

    • Added new tests to verify correct parsing of generic and nested generic parameter types in function declarations.

Summary by CodeRabbit

  • Documentation
    • Expanded documentation to clarify how parameter lists with nested delimiters are parsed.
  • Bug Fixes
    • Improved parsing of function parameters to correctly handle nested and mixed delimiters, such as generics and arrays.
  • Tests
    • Added new tests to verify correct parsing of functions with generic, nested generic, and complex parameter types.

Walkthrough

The changes introduce a stack-based delimiter tracking system in the function parameter parsing logic, enabling correct handling of nested and mixed delimiters (parentheses, angle brackets, brackets, and braces). Documentation is updated to describe this new behaviour, and new tests are added to verify parsing of complex generic and nested parameter types.

Changes

File(s) Change Summary
docs/function-parsing-design.md Added a detailed section on parameter list parsing and the new stack-based delimiter handling in parsing logic.
src/parser/ast/parse_utils.rs Replaced single-depth counter with DelimStack for tracking nested delimiters; refactored helpers; added tests.
tests/parser.rs Added fixtures and tests for functions with generic, nested generic, and double angle bracket parameter types.

Sequence Diagram(s)

sequenceDiagram
    participant Parser
    participant DelimStack
    participant TokenStream

    Parser->>TokenStream: Iterate tokens
    loop For each token
        Parser->>DelimStack: Handle open/close delimiter
        DelimStack-->>Parser: Update stack state
        alt At top-level comma or colon
            Parser->>Parser: Finalise parameter pair
        end
        alt Outermost parenthesis closed
            Parser->>Parser: End parameter list parsing
        end
    end
    Parser->>Parser: Return parsed parameter pairs
Loading

Possibly related PRs

Poem

In the warren of code, with a hop and a stack,
Now brackets and braces all nest with no lack!
Generics and vectors, they parse with delight,
No comma confusion, each pair is just right.
With tests for assurance, our parsing’s robust—
A rabbit’s delight, in delimiters we trust!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Clippy (1.86.0)
Updating crates.io index

warning: failed to write cache, path: /usr/local/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/ch/um/chumsky, error: Permission denied (os error 13)
Locking 60 packages to latest Rust 1.86.0 compatible versions
Adding chumsky v0.9.3 (available: v0.10.1)
Adding logos v0.13.0 (available: v0.15.0)
Adding phf v0.11.3 (available: v0.12.1)
Adding rowan v0.15.16 (available: v0.16.1)
Downloading crates ...
Downloaded ahash v0.8.12
error: failed to create directory /usr/local/registry/cache/index.crates.io-1949cf8c6b5b557f

Caused by:
Permission denied (os error 13)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47ab9f0 and fa1d88d.

📒 Files selected for processing (1)
  • src/parser/ast/parse_utils.rs (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.rs`: Comment why, not what. Explain assumptions, edge cases, trade-offs, o...

**/*.rs: Comment why, not what. Explain assumptions, edge cases, trade-offs, or complexity. Don't echo the obvious.
Comments must use en-GB-oxendict spelling and grammar.
Function documentation must include clear examples.
Name things precisely. Use clear, descriptive variable and function names. For booleans, prefer names with is, has, or should.
Each file should encapsulate a coherent module. Group related code (e.g., models + utilities + fixtures) close together.
Group by feature, not layer. Colocate views, logic, fixtures, and helpers related to a domain concept rather than splitting by type.
Every module must begin with a module level (//! ) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Place function attributes after doc comments.
Do not use return in single-line functions.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Clippy warnings MUST be disallowed.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Prefer expect over allow.
Use predicate functions for conditional criteria with more than two branches.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Prefer .expect() over .unwrap().

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • src/parser/ast/parse_utils.rs
`**/*.rs`: * Seek to keep the cyclomatic complexity of functions no more than 12...

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments must use en-GB-oxendict spelling and grammar.

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • src/parser/ast/parse_utils.rs
🔇 Additional comments (4)
src/parser/ast/parse_utils.rs (4)

11-55: Well-designed delimiter tracking system.

The stack-based approach with the Delim enum and DelimStack struct provides a robust solution for tracking nested delimiters. The close() method's design to return the count of successfully closed delimiters enables proper error detection whilst preventing stack underflow.


104-119: Correct separation of delimiter tracking concerns.

The dual tracking approach with DelimStack for type delimiters and outer_parens for the parameter list boundary is well-designed. The initialisation of outer_parens = 1 correctly accounts for the opening parenthesis consumed in the skip loop.


168-174: Correct handling of top-level separators.

The conditions depth.is_empty() && *outer_parens == 1 ensure that commas and colons only act as parameter separators at the top level, preventing incorrect parsing of nested generic types.


281-288: Excellent test coverage for generic types.

The new test cases comprehensively cover the generic type parsing scenarios mentioned in the PR objectives, including complex nested generics and edge cases with unusual angle bracket usage.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment
  • Commit Unit Tests in branch codex/update-parser-for-nested-delimiters-handling

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes - here's some feedback:

  • Explicitly track the outer parameter-list paren separately from nested type parens, so the end-of-list check only needs to inspect that single counter instead of all delim depths.
  • Consider refactoring DelimDepths into a stack-based or map-based structure to simplify adding new delimiters and ensure correct nesting without specialized fields for each delimiter type.
  • Extract the repeated "push_str(token.text()) + depth adjustment" patterns in handle_token into small helper functions to reduce duplication and improve readability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Explicitly track the outer parameter-list paren separately from nested type parens, so the end-of-list check only needs to inspect that single counter instead of all delim depths.
- Consider refactoring DelimDepths into a stack-based or map-based structure to simplify adding new delimiters and ensure correct nesting without specialized fields for each delimiter type.
- Extract the repeated "push_str(token.text()) + depth adjustment" patterns in handle_token into small helper functions to reduce duplication and improve readability.

## Individual Comments

### Comment 1
<location> `src/parser/ast/parse_utils.rs:89` </location>
<code_context>
+            }
+            buf.push_str(token.text());
+        }
+        SyntaxKind::T_SHL => {
+            depth.angle += 2;
+            buf.push_str(token.text());
+        }
+        SyntaxKind::T_SHR => {
</code_context>

<issue_to_address>
Double increment for T_SHL may not always match the intended nesting logic.

Check if incrementing by 2 for `T_SHL` is appropriate for all cases, as `<<` may not always indicate two levels of nesting depending on the grammar.
</issue_to_address>

### Comment 2
<location> `src/parser/ast/parse_utils.rs:93` </location>
<code_context>
+            depth.angle += 2;
+            buf.push_str(token.text());
+        }
+        SyntaxKind::T_SHR => {
+            let dec = 2.min(depth.angle);
+            depth.angle -= dec;
+            buf.push_str(token.text());
+        }
+        SyntaxKind::T_LBRACKET => {
</code_context>

<issue_to_address>
Decrementing by min(2, depth.angle) for T_SHR could mask unbalanced delimiters.

This approach avoids underflow but may hide unbalanced '>>' tokens. Consider raising an explicit error or warning if depth would become negative to catch malformed input early.
</issue_to_address>

### Comment 3
<location> `src/parser/ast/parse_utils.rs:69` </location>
<code_context>
+            depth.paren += 1;
             buf.push_str(token.text());
         }
         SyntaxKind::T_RPAREN => {
-            if *depth == 0 {
+            if depth.paren == 0 && depth.angle == 0 && depth.bracket == 0 && depth.brace == 0 {
                 finalize_pair(name, buf, pairs);
                 return true; // end of list
             }
-            *depth -= 1;
+            if depth.paren > 0 {
+                depth.paren -= 1;
+            }
+            buf.push_str(token.text());
+        }
+        SyntaxKind::T_LT => {
</code_context>

<issue_to_address>
Unmatched closing delimiters are not explicitly handled.

Currently, encountering an unmatched closing delimiter finalizes the pair without error, which may allow malformed input. Please clarify if this is intentional or add error handling for this case.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/parser/ast/parse_utils.rs Outdated
SyntaxKind::T_LPAREN => {
*depth += 1;
depth.paren += 1;
buf.push_str(token.text());
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.

question: Double increment for T_SHL may not always match the intended nesting logic.

Check if incrementing by 2 for T_SHL is appropriate for all cases, as << may not always indicate two levels of nesting depending on the grammar.

Comment thread src/parser/ast/parse_utils.rs Outdated
SyntaxKind::T_LPAREN => {
*depth += 1;
depth.paren += 1;
buf.push_str(token.text());
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.

issue (bug_risk): Decrementing by min(2, depth.angle) for T_SHR could mask unbalanced delimiters.

This approach avoids underflow but may hide unbalanced '>>' tokens. Consider raising an explicit error or warning if depth would become negative to catch malformed input early.

Comment thread src/parser/ast/parse_utils.rs Outdated
SyntaxKind::T_LPAREN => {
*depth += 1;
depth.paren += 1;
buf.push_str(token.text());
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.

question: Unmatched closing delimiters are not explicitly handled.

Currently, encountering an unmatched closing delimiter finalizes the pair without error, which may allow malformed input. Please clarify if this is intentional or add error handling for this case.

Use a stack to track nested delimiters and keep the outer parameter list count separate. Added helper functions and updated docs.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/parser/ast/parse_utils.rs (1)

160-167: Consider consistent error handling for unmatched closing delimiters.

While unmatched >> has a TODO, other unmatched closing delimiters (], }, >) are silently ignored. For consistency and better error reporting, consider adding similar mismatch detection for all delimiter types.

Example pattern for consistent handling:

 SyntaxKind::T_RBRACKET => {
-    close_and_push(token, buf, depth, Delim::Bracket, 1);
+    let closed = close_and_push(token, buf, depth, Delim::Bracket, 1);
+    if closed == 0 {
+        // TODO: report unmatched ']'
+    }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ff9f54 and 47ab9f0.

📒 Files selected for processing (3)
  • docs/function-parsing-design.md (1 hunks)
  • src/parser/ast/parse_utils.rs (4 hunks)
  • tests/parser.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
`docs/**/*.md`: Documentation must use en-GB-oxendict spelling and grammar (with the exception of 'license' which is to be left unchanged for community consistency).

docs/**/*.md: Documentation must use en-GB-oxendict spelling and grammar (with the exception of 'license' which is to be left unchanged for community consistency).

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • docs/function-parsing-design.md
`**/*.md`: Markdown paragraphs and bullet points must be wrapped at 80 columns. Code blocks must be wrapped at 120 columns. Tables and headings must not be wrapped.

**/*.md: Markdown paragraphs and bullet points must be wrapped at 80 columns.
Code blocks must be wrapped at 120 columns.
Tables and headings must not be wrapped.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • docs/function-parsing-design.md
`**/*.md`: * Avoid 2nd person or 1st person pronouns ("I", "you", "we") * Use en...

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-oxendic spelling and grammar.
  • Paragraphs and bullets must be wrapped to 80 columns, except where a long URL would prevent this (in which case, silence MD013 for that line)
  • Code blocks should be wrapped to 120 columns.
  • Headings must not be wrapped.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • docs/function-parsing-design.md
`**/*.rs`: Comment why, not what. Explain assumptions, edge cases, trade-offs, o...

**/*.rs: Comment why, not what. Explain assumptions, edge cases, trade-offs, or complexity. Don't echo the obvious.
Comments must use en-GB-oxendict spelling and grammar.
Function documentation must include clear examples.
Name things precisely. Use clear, descriptive variable and function names. For booleans, prefer names with is, has, or should.
Each file should encapsulate a coherent module. Group related code (e.g., models + utilities + fixtures) close together.
Group by feature, not layer. Colocate views, logic, fixtures, and helpers related to a domain concept rather than splitting by type.
Every module must begin with a module level (//! ) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Place function attributes after doc comments.
Do not use return in single-line functions.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Clippy warnings MUST be disallowed.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Prefer expect over allow.
Use predicate functions for conditional criteria with more than two branches.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Prefer .expect() over .unwrap().

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • tests/parser.rs
  • src/parser/ast/parse_utils.rs
`**/*.rs`: * Seek to keep the cyclomatic complexity of functions no more than 12...

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments must use en-GB-oxendict spelling and grammar.

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • tests/parser.rs
  • src/parser/ast/parse_utils.rs
🧬 Code Graph Analysis (1)
tests/parser.rs (1)
src/parser/mod.rs (8)
  • parse (223-252)
  • errors (212-214)
  • name (1216-1222)
  • name (1296-1307)
  • name (1432-1443)
  • name (1612-1623)
  • parameters (1635-1637)
  • return_type (1641-1659)
🪛 LanguageTool
docs/function-parsing-design.md

[style] ~30-~30: Would you like to use the Oxford spelling “recognized”? The spelling ‘recognised’ is also correct.
Context: ...parately so that the closing ) can be recognised without scanning the stack.

(OXFORD_SPELLING_Z_NOT_S)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test
🔇 Additional comments (5)
docs/function-parsing-design.md (1)

22-30: Documentation accurately describes the new delimiter tracking implementation.

The new section clearly explains the stack-based approach for handling nested delimiters. The use of "recognised" is correct for en-GB-oxendict spelling.

tests/parser.rs (1)

804-869: Comprehensive test coverage for generic and nested parameter types.

The new tests thoroughly validate the enhanced delimiter handling, including edge cases like double angle brackets. Good use of rstest fixtures and proper error messaging with expect.

src/parser/ast/parse_utils.rs (3)

11-56: Well-designed stack-based delimiter tracking.

The DelimStack implementation correctly ensures delimiters close in the proper order and gracefully handles mismatches by returning the count of successfully closed delimiters. Good use of dedicated types and clear documentation.


57-83: Good abstraction with helper functions.

These helpers effectively reduce code duplication and provide a consistent interface for delimiter operations. The return value from close_and_push enables proper mismatch detection.


281-288: Excellent test coverage for the enhanced delimiter handling.

The new test cases thoroughly exercise the stack-based delimiter tracking with various generic types, nested structures, and edge cases.

Comment thread src/parser/ast/parse_utils.rs
@leynos leynos merged commit 031ced9 into main Jul 5, 2025
2 checks passed
@leynos leynos deleted the codex/update-parser-for-nested-delimiters-handling branch July 5, 2025 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant