Skip to content

Implement function parser#40

Merged
leynos merged 11 commits intomainfrom
cu51rp-codex/implement-func-parser-for-function-definitions
Jul 4, 2025
Merged

Implement function parser#40
leynos merged 11 commits intomainfrom
cu51rp-codex/implement-func-parser-for-function-definitions

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 3, 2025

Summary

  • parse extern and regular functions
  • add span collection for function declarations
  • build CST nodes for functions
  • expose functions() and Function AST node
  • test function parsing

Testing

  • make lint
  • make test

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

Summary by Sourcery

Implement parsing support for function and extern function declarations, integrate them into the parser’s span collection, CST and AST, and add extensive tests

New Features:

  • Add span collection and CST building for function and extern function declarations
  • Expose a new Function AST node and a functions() accessor on Root with methods for name, extern flag, parameters, and return type

Enhancements:

  • Introduce generic span collector helpers (parse_span, push_line_span, skip_line) and refactor other collectors to use parse_span
  • Extract common name‐type pair parsing logic (parse_name_type_pairs and parse_type_after_colon) and reuse in relations and functions
  • Simplify Relation.columns() to delegate to the unified parsing routine

Tests:

  • Add comprehensive parser tests for function declarations and definitions, including valid cases (extern, body/no‐body, varied parameters) and error scenarios }

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 3, 2025

Reviewer's Guide

Adds comprehensive parsing support for extern function declarations and regular function definitions by collecting function spans during token traversal, integrating them into the CST, exposing a new Function AST node with accessor methods, and validating the implementation with extensive parser tests.

Sequence diagram for function span collection and CST/AST integration

sequenceDiagram
    participant Parser
    participant SpanCollector
    participant CSTBuilder
    participant ASTRoot
    Parser->>SpanCollector: collect_function_spans(tokens, src)
    SpanCollector-->>Parser: (function_spans, errors)
    Parser->>CSTBuilder: build_green_tree(..., function_spans, ...)
    CSTBuilder-->>ASTRoot: Root::from_green(green)
    ASTRoot->>ASTRoot: functions() -> Vec<Function>
Loading

Class diagram for new and updated AST nodes (Function, Root)

classDiagram
    class Root {
        +functions() Vec~Function~
        ...
    }
    class Function {
        +syntax() &SyntaxNode
        +name() Option~String~
        +is_extern() bool
        +parameters() Vec~(String, String)~
        +return_type() Option~String~
    }
    Root --> "*" Function : functions()
Loading

Class diagram for new and updated span collection utilities

classDiagram
    class SpanCollector {
        +push_line_span(start)
        +skip_line()
        +parse_span(parser, start)
        ...
    }
Loading

Class diagram for helper parsing functions

classDiagram
    class parse_name_type_pairs {
        <<function>>
    }
    class parse_type_after_colon {
        <<function>>
    }
    Function ..> parse_name_type_pairs : uses
    Function ..> parse_type_after_colon : uses
    Relation ..> parse_name_type_pairs : uses
Loading

File-Level Changes

Change Details Files
Extend span collection logic to capture function declarations
  • Introduce collect_function_spans to identify extern and regular function spans via Chumsky parsers
  • Update parse_tokens to return function_spans and merge related errors
  • Add push_line_span, skip_line, and parse_span helpers to SpanCollector
  • Refactor existing span collectors to use the new helpers for consistency
src/parser/mod.rs
src/parser/span_collector.rs
Integrate function spans into CST construction
  • Extend build_green_tree signature and assertions to include function spans
  • Update token iteration to start and finish N_FUNCTION nodes based on function spans
src/parser/mod.rs
Expose functions in the AST
  • Add functions() method on Root to collect Function nodes
  • Define Function struct and implement methods: name, is_extern, parameters, return_type
  • Extract helper functions parse_name_type_pairs and parse_type_after_colon for parameter and return-type parsing
src/parser/mod.rs
Add extensive parser tests for function parsing
  • Add fixtures covering extern declarations, bodies, no-return cases, parameter variations, and malformed inputs
  • Implement rstest tests to assert correct parsing and error detection for all scenarios
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 3, 2025

Summary by CodeRabbit

  • New Features
    • Added support for parsing function declarations and definitions, including extern functions, parameter lists, and return types.
    • Introduced an API to access parsed functions, their names, parameters, extern status, and return types.
  • Bug Fixes
    • Improved error handling for malformed function syntax, such as missing colons or unclosed blocks.
  • Documentation
    • Added detailed design and parser flow documentation with diagrams explaining function parsing.
  • Tests
    • Introduced comprehensive tests for various function declaration forms, parameter lists, error cases, and API behaviour.

Summary by CodeRabbit

  • New Features

    • Added support for parsing and handling function declarations and definitions, including both extern and regular functions with parameters and optional return types.
    • Introduced new methods to access parsed function information, such as name, parameters, return type, and extern status.
    • Enhanced the ability to collect and process functions within the parsed syntax tree.
  • Bug Fixes

    • Improved robustness in parsing by refining iterator handling for better token navigation.
  • Tests

    • Added comprehensive tests for various function declaration scenarios to ensure correct parsing and pretty-printing.
  • Chores

    • Extended internal utilities for improved span collection and parsing capabilities.

Walkthrough

The parser has been extended to support function declarations and definitions. This includes scanning tokens for function spans, integrating these spans into the syntax tree, and adding a typed AST node for functions with accessor methods. Corresponding tests and fixtures were also introduced to verify parsing and AST extraction of various function forms.

Changes

File(s) Change Summary
src/parser/mod.rs Added function span collection, updated parse and green tree logic, introduced Function AST node and methods.
src/parser/span_collector.rs Added methods for line-based span recording and sub-parsing within the token stream.
src/parser/token_stream.rs Added peek_after_ws_inline method to peek next non-whitespace/comment token on the same line without advancing.
tests/parser.rs Added test fixtures and tests for extern and regular function parsing, including pretty-print checks.
tests/function_api.rs Added unit tests for the function AST API verifying parsing and property extraction of functions.
docs/function-parsing-design.md Added design document describing function parsing approach and helper functions with a Mermaid class diagram.
docs/parser-plan.md Added Mermaid sequence diagram illustrating parser flow from span collection to AST root and function extraction.

Sequence Diagram(s)

sequenceDiagram
    participant Source as Source Code
    participant Parser as Parser
    participant CST as Concrete Syntax Tree
    participant AST as Typed AST

    Source->>Parser: parse(src)
    Parser->>Parser: collect_function_spans(tokens)
    Parser->>CST: build_green_tree(tokens, spans including functions)
    CST->>AST: Construct Root node
    AST->>AST: Root.functions() returns Function nodes
Loading

Possibly related PRs

  • Encapsulate token utilities in TokenStream #30: The main PR builds upon the TokenStream abstraction introduced and integrated into the parser and SpanCollector in the retrieved PR by adding function parsing support and extending the parser to handle function spans using the TokenStream-based infrastructure.
  • Refactor span collectors #26: Builds on the SpanCollector framework by adding new methods and using it to implement function span collection, extending the span collection capabilities.

Poem

In the warren of code, a new path appears,
Functions now parsed, with names in our ears.
Extern or not, parameters in tow,
The AST grows strong, as syntax seeds sow.
With tests to ensure each rabbit can see—
The parser now hops with new function glee!
🐇✨


📜 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 b4253f4 and 9702a59.

📒 Files selected for processing (2)
  • docs/function-parsing-design.md (1 hunks)
  • docs/parser-plan.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.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
  • docs/parser-plan.md
🔇 Additional comments (2)
docs/function-parsing-design.md (1)

1-19: Document complies with style and content guidelines

The heading, prose and Mermaid block respect the 80-column prose and 120-column code
limits, avoid personal pronouns, and follow en-GB spelling. No corrective action
required.

docs/parser-plan.md (1)

70-81: Sequence diagram addition looks correct and guideline-compliant

The new Mermaid diagram sits inside a fenced code block, line lengths are well
under 120 columns and wording remains impersonal. No issues spotted.

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment
  • Commit Unit Tests in branch cu51rp-codex/implement-func-parser-for-function-definitions

🪧 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:

  • The collect_function_spans code repeats the same span‐collection pattern used in other collectors—consider extracting a shared helper to reduce duplication and improve readability.
  • The handle_function logic only tracks braces to find the function body’s end and could mis-handle nested blocks or comments; you might reuse the existing CST parser to robustly locate definition boundaries.
  • Parsing parameters and return types by manually iterating children_with_tokens is brittle—consider extracting or reusing a small grammar‐driven helper to simplify the Function AST methods.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The collect_function_spans code repeats the same span‐collection pattern used in other collectors—consider extracting a shared helper to reduce duplication and improve readability.
- The handle_function logic only tracks braces to find the function body’s end and could mis-handle nested blocks or comments; you might reuse the existing CST parser to robustly locate definition boundaries.
- Parsing parameters and return types by manually iterating children_with_tokens is brittle—consider extracting or reusing a small grammar‐driven helper to simplify the Function AST methods.

## Individual Comments

### Comment 1
<location> `tests/parser.rs:635` </location>
<code_context>
+    "function log_message(msg: string) {\n}\n"
+}
+
+#[rstest]
+fn extern_function_parsed(extern_function: &str) {
+    let parsed = parse(extern_function);
+    assert!(parsed.errors().is_empty());
+    let funcs = parsed.root().functions();
+    assert_eq!(funcs.len(), 1);
+    let func = funcs.first().unwrap_or_else(|| panic!("function missing"));
+    assert_eq!(func.name(), Some("hash".into()));
+    assert!(func.is_extern());
+    assert_eq!(func.parameters(), vec![("data".into(), "string".into())]);
+    assert_eq!(func.return_type(), Some("u64".into()));
+    assert_eq!(pretty_print(func.syntax()), extern_function);
+}
+
</code_context>

<issue_to_address>
Missing tests for edge cases in function parsing.

Please add tests for functions with no parameters, multiple or complex parameters, nested parentheses in types, malformed declarations, and variations in comments or whitespace to improve parser robustness.
</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 tests/parser.rs
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: 2

🔭 Outside diff range comments (1)
tests/parser.rs (1)

635-676: Add negative-case tests for functions

The new fixtures cover happy paths only. Including cases such as
extern function missing_colon u32 and function foo() { (unterminated body) would assert error recovery and keep the parser robust under regression.

You already have similar negative suites for rules and indexes; mirroring that style here keeps test coverage consistent.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bac8511 and 4fb8c85.

📒 Files selected for processing (2)
  • src/parser/mod.rs (13 hunks)
  • tests/parser.rs (1 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:

  • tests/parser.rs
  • src/parser/mod.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/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test

Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs
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: 3

🔭 Outside diff range comments (1)
src/parser/mod.rs (1)

4-5: Update the module documentation to reflect implemented functionality.

The comment states "The grammar rules are not implemented yet" but this PR implements function parsing rules.

-//! The grammar rules are not implemented yet. The parser currently tokenises
-//! the input and wraps the tokens into a `rowan::GreenNode`. It lays down the
+//! The parser tokenises the input and wraps tokens into a `rowan::GreenNode`,
+//! with support for parsing imports, typedefs, relations, indexes, functions, and rules. It lays down the
♻️ Duplicate comments (1)
src/parser/mod.rs (1)

1287-1298: Return-type scanner may consume trailing trivia

The function continues appending tokens including whitespace until it encounters { or ;, which means trailing newlines get included in the type string.

                 NodeOrToken::Token(t)
                     if matches!(t.kind(), SyntaxKind::T_LBRACE | SyntaxKind::T_SEMI) =>
                 {
                     break;
                 }
-                NodeOrToken::Token(t) => buf.push_str(t.text()),
+                NodeOrToken::Token(t) => {
+                    if t.kind() == SyntaxKind::T_WHITESPACE && t.text().contains('\n') {
+                        break;
+                    }
+                    buf.push_str(t.text());
+                }
                 NodeOrToken::Node(n) => buf.push_str(&n.text().to_string()),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4fb8c85 and 12cf296.

📒 Files selected for processing (2)
  • src/parser/mod.rs (20 hunks)
  • src/parser/span_collector.rs (1 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/span_collector.rs
  • src/parser/mod.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/span_collector.rs
  • src/parser/mod.rs
🧬 Code Graph Analysis (1)
src/parser/mod.rs (2)
src/parser/token_stream.rs (4)
  • tokens (105-107)
  • src (118-120)
  • new (41-47)
  • peek (76-78)
src/parser/span_collector.rs (1)
  • new (44-50)
🔇 Additional comments (4)
src/parser/span_collector.rs (3)

58-63: LGTM!

The method correctly records a line span and advances the cursor.


65-69: LGTM!

The method correctly skips to line end without recording a span.


71-89: LGTM!

The method correctly creates a sub-stream and delegates parsing to the provided parser with error recovery.

src/parser/mod.rs (1)

1066-1074: LGTM!

The functions() method correctly collects function nodes following the established pattern.

Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 3, 2025

@sourcery-ai review

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:

  • The collect_function_spans implementation is quite long—consider factoring out the depth‐tracking parenthesis/brace matching logic into reusable helper parsers to cut down on duplication between params, body_block, and similar functions.
  • handle_extern and handle_function share most of their parsing flow; extracting the common parts into a single handler (with an is_extern flag) would simplify maintenance and reduce boilerplate.
  • Utility functions like parse_name_type_pairs and parse_type_after_colon appear in multiple AST nodes—moving them into a shared parsing‐utility module (and reusing them for relations as well as functions) would DRY up your AST code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `collect_function_spans` implementation is quite long—consider factoring out the depth‐tracking parenthesis/brace matching logic into reusable helper parsers to cut down on duplication between `params`, `body_block`, and similar functions.
- `handle_extern` and `handle_function` share most of their parsing flow; extracting the common parts into a single handler (with an `is_extern` flag) would simplify maintenance and reduce boilerplate.
- Utility functions like `parse_name_type_pairs` and `parse_type_after_colon` appear in multiple AST nodes—moving them into a shared parsing‐utility module (and reusing them for relations as well as functions) would DRY up your AST code.

## Individual Comments

### Comment 1
<location> `src/parser/mod.rs:1244` </location>
<code_context>
+    fn parse_name_type_pairs<I>(mut iter: I) -> Vec<(String, String)>
</code_context>

<issue_to_address>
The parse_name_type_pairs function may not handle all edge cases for nested types.

If the language supports complex type expressions like tuples or generics, this logic may not cover all valid cases. Please review the type grammar to ensure comprehensive handling.
</issue_to_address>

### Comment 2
<location> `src/parser/mod.rs:1662` </location>
<code_context>
+
+    /// Typed wrapper for a function declaration or definition.
+    #[derive(Debug, Clone)]
+    pub struct Function {
+        pub(crate) syntax: SyntaxNode<DdlogLanguage>,
+    }
</code_context>

<issue_to_address>
Add unit tests for the new ast::Function API to verify name, parameters, and return_type methods.

The new ast::Function struct and its methods (name, parameters, return_type, is_extern) should be covered by unit tests to ensure correct behavior for various function declaration forms.
</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/mod.rs
Comment thread src/parser/mod.rs
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 3, 2025

@coderabbitai Please create new GitHub issues for the following:

  • Utility functions like parse_name_type_pairs and parse_type_after_colon appear in multiple AST nodes—moving them into a shared parsing‐utility module (and reusing them for relations as well as functions) would DRY up your AST code.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 3, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@leynos I've created a GitHub issue for refactoring the parsing utility functions into a shared module. This will help reduce code duplication between the Function and Relation AST nodes by moving parse_name_type_pairs and parse_type_after_colon into a dedicated parsing-utility module.


🏁 Script executed:

#!/bin/bash
# Create GitHub issue for refactoring utility functions into shared module
gh issue create \
  --title "Refactor parsing utility functions into shared module" \
  --body "The utility functions \`parse_name_type_pairs\` and \`parse_type_after_colon\` are currently used by multiple AST nodes (Function and Relation). Moving these functions into a shared parsing-utility module would reduce code duplication and improve maintainability.

**Background:**
These functions were extracted during the implementation of function parsing and are now used by both Function and Relation AST nodes. Creating a shared module for parsing utilities would follow the DRY principle and make the codebase more maintainable.

**Reference:**
- PR: https://github.com/leynos/ddlint/pull/40
- Comment: https://github.com/leynos/ddlint/pull/40#issuecomment-[comment_id]
- Requested by: @leynos" \
  --assignee leynos

Length of output: 847


Perfect! I've successfully created GitHub issue #41 for refactoring the parsing utility functions into a shared module. The issue has been assigned to you and includes:

  • A clear description of the code duplication problem
  • The proposed solution to move parse_name_type_pairs and parse_type_after_colon into a shared parsing-utility module
  • References back to this PR and your request

You can view the issue at: #41

This refactoring will help maintain the DRY principle and make the AST code more maintainable by centralising the parsing utility functions that are used by both Function and Relation AST nodes.

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: 2

♻️ Duplicate comments (2)
src/parser/mod.rs (2)

1240-1253: Handle missing opening parenthesis in parse_name_type_pairs.

The function skips to the first '(' but doesn't handle the case where no parenthesis is found, potentially processing the entire iterator unnecessarily.


1656-1719: Add unit tests for the Function AST methods.

The new ast::Function struct and its methods (name, parameters, return_type, is_extern) should be covered by unit tests to ensure correct behavior for various function declaration forms.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c1439af and b20d914.

📒 Files selected for processing (1)
  • src/parser/mod.rs (23 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/mod.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/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test
🔇 Additional comments (2)
src/parser/mod.rs (2)

4-7: Documentation update looks good.

The module documentation correctly reflects the addition of function parsing support.


224-232: Function span integration looks complete and consistent.

The integration of function spans throughout the parser follows the established patterns for other statement types. All necessary updates to data structures, iterations, and assertions have been made correctly.

Also applies to: 283-288, 295-296, 857-865, 873-874, 881-882, 908-913, 922-923, 1093-1101

Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 3, 2025

@coderabbitai Please create new GitHub issues for the following:

  • Utility functions like parse_name_type_pairs and parse_type_after_colon appear in multiple AST nodes—moving them into a shared parsing‐utility module (and reusing them for relations as well as functions) would DRY up your AST code.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 3, 2025

Tip

For best results, initiate chat on the files or code changes.

@leynos I can see that this issue has already been created! GitHub issue #41 titled "Refactor parsing utility functions into shared module" was created earlier and assigned to you.

The issue covers exactly what you requested:

  • Moving parse_name_type_pairs and parse_type_after_colon into a shared parsing-utility module
  • Reducing code duplication between Function and Relation AST nodes
  • Following the DRY principle for better maintainability

You can view the issue at: #41

If you'd like me to modify the existing issue or create additional related issues, please let me know!

🐰✨

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 (4)
src/parser/mod.rs (4)

116-186: Consider reducing code duplication between balanced block parsers.

The balanced_block and balanced_block_nonempty functions are nearly identical. Consider refactoring to avoid duplication as previously suggested.


694-712: Simplify token navigation in handle_func.

The manual index manipulation for checking the next non-whitespace token is complex and could be simplified using existing stream methods.


1247-1304: The parse_name_type_pairs function may not handle all edge cases for nested types.

If the language supports complex type expressions like tuples or generics, this logic may not cover all valid cases. This concern has been tracked in issue #42.


1663-1726: Add unit tests for the new ast::Function API.

The new ast::Function struct and its methods (name, parameters, return_type, is_extern) should be covered by unit tests to ensure correct behaviour for various function declaration forms.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b20d914 and 8c62ac3.

📒 Files selected for processing (1)
  • src/parser/mod.rs (23 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/mod.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/mod.rs
🔇 Additional comments (3)
src/parser/mod.rs (3)

648-674: Good use of balanced block parsers.

The abstraction of parameter lists and function bodies using the balanced block parsers is clean and well-structured.


1306-1345: Well-implemented type parsing logic.

The parse_type_after_colon function correctly handles edge cases including breaking on newlines within whitespace tokens, preventing trailing formatting from being included in the type string.


1394-1394: Good refactoring to reuse parsing logic.

The delegation to parse_name_type_pairs eliminates code duplication and improves maintainability. This aligns with the DRY principle.

Comment thread src/parser/mod.rs
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: 5

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8c62ac3 and 5f6b7e1.

📒 Files selected for processing (1)
  • tests/function_api.rs (1 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:

  • tests/function_api.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/function_api.rs
🧬 Code Graph Analysis (1)
tests/function_api.rs (1)
src/parser/mod.rs (4)
  • parse (222-251)
  • errors (211-213)
  • parameters (1701-1703)
  • return_type (1707-1725)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test
🔇 Additional comments (1)
tests/function_api.rs (1)

3-38: Excellent test coverage for the function API.

The tests comprehensively cover the key scenarios: extern functions, regular functions with return types, and functions without return types. The test structure clearly validates the Function AST node's API methods.

Comment thread tests/function_api.rs Outdated
Comment thread tests/function_api.rs Outdated
Comment thread tests/function_api.rs Outdated
Comment thread tests/function_api.rs Outdated
Comment thread tests/function_api.rs Outdated
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: 2

♻️ Duplicate comments (2)
src/parser/mod.rs (2)

1218-1275: Complex type handling may need enhancement.

The function handles basic cases well, but as previously noted, complex type expressions like generics or tuples might not be fully covered. An issue (#42) has already been created to address this.


1634-1697: Function AST node implementation is correct.

The Function AST node properly implements all required methods following established patterns. As previously noted, unit tests for these methods would be beneficial.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6b26684 and b33f4c8.

📒 Files selected for processing (1)
  • src/parser/mod.rs (23 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/mod.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/mod.rs
🧬 Code Graph Analysis (1)
src/parser/mod.rs (2)
src/parser/token_stream.rs (5)
  • new (41-47)
  • tokens (105-107)
  • src (118-120)
  • peek_after_ws_inline (214-229)
  • peek (76-78)
src/parser/span_collector.rs (1)
  • new (44-50)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test
🔇 Additional comments (11)
src/parser/mod.rs (11)

4-7: Documentation update looks good.

The module documentation accurately reflects the new function parsing support.


156-169: Good abstraction with wrapper functions.

The wrapper functions balanced_block and balanced_block_nonempty effectively reuse balanced_block_with_min, following DRY principles.


207-215: Function span integration is well-implemented.

The changes properly integrate function span collection following the established pattern for other span types, with correct error aggregation.

Also applies to: 248-260, 265-265, 270-270, 278-279


342-342: Good use of SpanCollector helper methods.

The code now uses the new parse_span, push_line_span, and skip_line helper methods, improving consistency and readability.

Also applies to: 397-397, 422-422, 424-424, 598-598


619-725: Function span collection is well-implemented.

The implementation correctly handles both extern function declarations and regular function definitions. The parser combinators are well-composed, and error recovery is properly implemented.


824-827: Function span integration in green tree builder is correct.

The changes properly integrate function spans into the CST construction, following the established pattern. The use of expect with a clear reason is appropriate.

Also applies to: 835-836, 842-843, 851-852, 859-860, 886-891, 900-900


1277-1316: Return type parsing correctly handles edge cases.

The implementation properly extracts return types and correctly stops at newlines within whitespace tokens, addressing the previous concern about trailing newlines.


1365-1365: Good refactoring to eliminate duplication.

The columns() method now delegates to the shared parse_name_type_pairs function, following DRY principles.


1071-1079: Functions collection method follows established pattern.

The functions() method correctly collects Function nodes from the AST, maintaining consistency with other collection methods.


1157-1157: Iterator improvements enhance parsing robustness.

Converting iterators to peekable improves token navigation capabilities, allowing for necessary lookahead operations.

Also applies to: 1506-1506


788-795: Consistent error handling in rule parsing.

The update to use parse_span maintains consistency with other span collectors and properly collects parsing errors.

Comment thread src/parser/mod.rs
Comment thread src/parser/mod.rs Outdated
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 4, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 4, 2025

✅ 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.

@leynos leynos merged commit 61186b1 into main Jul 4, 2025
2 checks passed
@leynos leynos deleted the cu51rp-codex/implement-func-parser-for-function-definitions branch July 4, 2025 00:26
@sourcery-ai sourcery-ai Bot mentioned this pull request Jul 20, 2025
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