Skip to content

Implement relation parser#35

Merged
leynos merged 3 commits intomainfrom
codex/implement-relation-parser-for-declarations
Jun 29, 2025
Merged

Implement relation parser#35
leynos merged 3 commits intomainfrom
codex/implement-relation-parser-for-declarations

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 29, 2025

Summary

  • parse relation declarations
  • handle input, output and internal relation spans
  • build CST N_RELATION_DECL nodes
  • expose typed Relation wrappers with helpers
  • test relation parsing for various cases

Testing

  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-targets --all-features

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

Summary by Sourcery

Implement parsing of relation declarations and expose them in the CST and AST with helpers.

New Features:

  • Extend token parsing to collect spans for input, output, and internal relation declarations
  • Update CST builder to include N_RELATION_DECL nodes for relation spans
  • Introduce Relation AST type with helpers for name, input/output flags, columns, and primary key extraction

Tests:

  • Add fixtures and tests for parsing input, output, and internal relations, including primary key handling

Implement parser support for relation declarations.\nThe parser now collects relation spans, constructs\nN_RELATION_DECL nodes, and provides a typed Relation\nwrapper with helpers to inspect name, role, columns\nand primary key. Tests cover input, output and internal\nrelations.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 29, 2025

Reviewer's Guide

Implements relation declaration parsing by extending the parser to collect relation spans, injecting N_RELATION_DECL nodes in the CST, providing a typed Relation AST wrapper with helper methods, and covering input/output/internal relations in new tests.

Class diagram for new and updated AST node wrappers (Relation, Root)

classDiagram
    class Root {
        +Vec<Relation> relations()
    }
    class Relation {
        +syntax() SyntaxNode
        +name() Option<String>
        +is_input() bool
        +is_output() bool
        +columns() Vec<(String, String)>
        +primary_key() Option<Vec<String>>
    }
    Root --> "*" Relation : contains
Loading

File-Level Changes

Change Details Files
Extend parser pipeline to handle relation spans
  • Unpack relation_spans in parse() and adjust build_green_tree call
  • Update parse_tokens signature to return relation_spans alongside imports and typedefs
  • In build_green_tree, assert and iterate over relation_spans, and start/finish N_RELATION_DECL nodes
src/parser/mod.rs
Implement relation span collection
  • Add collect_relation_spans to scan tokens for input, output, and bare relation declarations
  • Use token_dispatch! to route SyntaxKind::K_INPUT, K_OUTPUT, K_RELATION to handlers
  • Record spans from declaration start to end of line
src/parser/mod.rs
Extend AST with Relation nodes and helpers
  • Add Root::relations() to collect N_RELATION_DECL children
  • Introduce Relation struct with methods: syntax(), name(), is_input(), is_output(), columns(), primary_key()
src/parser/mod.rs
Update syntax kinds for relation declarations
  • Add N_RELATION_DECL variant to SyntaxKind enum
src/language.rs
Add tests covering relation parsing
  • Define fixtures for input/output/internal relation declarations
  • Implement rstest functions to assert parsing of relation name, role flags, columns, and primary keys
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 Jun 29, 2025

Summary by CodeRabbit

  • New Features

    • Added support for parsing and recognising relation declarations, including input, output, and internal relations with primary key specifications.
    • Enhanced the ability to extract relation names, columns, and primary keys from parsed content.
  • Tests

    • Introduced new tests to validate parsing of various relation declaration formats, including multi-line and compound primary key scenarios.

Summary by CodeRabbit

  • New Features

    • Added support for parsing and recognising relation declarations, including input, output, and internal relations, with extraction of names, columns, and primary keys.
  • Tests

    • Introduced new tests to verify correct parsing of various relation declaration types and their attributes.

Walkthrough

This update introduces support for relation declarations in the parser, CST, and typed AST. It adds a new syntax kind for relation declarations, updates parsing logic to recognise and extract relation spans, and provides typed wrappers and methods to inspect relation properties. New tests verify correct parsing of various relation forms.

Changes

File(s) Change Summary
src/language.rs Added N_RELATION_DECL variant to SyntaxKind enum.
src/parser/mod.rs Extended parser to handle relation declarations: new span collection, CST integration, typed AST struct and methods for relations, and updated function signatures.
tests/parser.rs Added fixtures and tests for input, output, and internal relation declarations, checking parsing and AST extraction.

Sequence Diagram(s)

sequenceDiagram
    participant Source as Source Code
    participant Parser as Parser
    participant CST as CST Builder
    participant AST as Typed AST

    Source->>Parser: parse(src)
    Parser->>Parser: Tokenise input
    Parser->>Parser: collect_relation_spans()
    Parser->>CST: build_green_tree(tokens, imports, typedefs, relations)
    CST->>AST: Construct typed nodes (including Relation)
    AST->>AST: Provide methods (name, columns, pk, etc.)
    AST->>Parser: Return Parsed object with relations
Loading

Possibly related PRs

Poem

In a meadow of syntax, relations now bloom,
With inputs and outputs, new types in the room.
The parser hops nimbly, through columns and keys—
Each table declared brings the rabbit much ease.
🐇✨
Relations are parsed, so let’s all rejoice,
For structure and order now have a clear voice!


📜 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 18ddefe and 557342c.

📒 Files selected for processing (1)
  • src/parser/mod.rs (8 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.rs`: Document public APIs using Rustdoc comments (`///`) so documentation ...

**/*.rs: Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
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.
Prefer .expect() over .unwrap().
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.
Use explicit version ranges in Cargo.toml and keep dependencies up-to-date.
Use rstest fixtures for shared setup.
Replace duplicated tests with #[rstest(...)] parameterised cases.
Prefer mockall for mocks/stubs.
Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
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.
Write unit and behavioural tests for new functionality. Run both before and after making any change.

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

94-105: LGTM! Clean integration of relation parsing.

The changes follow the established pattern for handling imports and typedefs, maintaining consistency in the codebase.


107-127: Documentation and implementation align well.

The function signature and documentation clearly indicate the addition of relation span collection, maintaining consistency with the existing pattern for imports and typedefs.


418-468: Consistent integration of relation node construction.

The changes properly extend the CST builder to handle relation declarations, maintaining the established pattern for imports and typedefs.


613-621: Clean API addition following established patterns.

The relations() method maintains consistency with the existing imports() and type_defs() methods.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch codex/implement-relation-parser-for-declarations

🪧 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_relation_spans implementation only grabs until the end of the current line, so multi‐line relation declarations (e.g. wrapping columns on multiple lines) won’t be detected correctly—consider extending span capture to handle declarations spanning multiple lines.
  • handle_input and handle_output in collect_relation_spans are identical; you can factor them into a single helper to reduce duplication.
  • Parsing columns() and primary_key() by string-splitting the raw syntax text is fragile (e.g. comments, nested types, or extra whitespace); consider traversing the syntax node’s children/tokens to build these structures more robustly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `collect_relation_spans` implementation only grabs until the end of the current line, so multi‐line relation declarations (e.g. wrapping columns on multiple lines) won’t be detected correctly—consider extending span capture to handle declarations spanning multiple lines.
- `handle_input` and `handle_output` in `collect_relation_spans` are identical; you can factor them into a single helper to reduce duplication.
- Parsing `columns()` and `primary_key()` by string-splitting the raw syntax text is fragile (e.g. comments, nested types, or extra whitespace); consider traversing the syntax node’s children/tokens to build these structures more robustly.

## Individual Comments

### Comment 1
<location> `src/parser/mod.rs:716` </location>
<code_context>
+                .any(|e| e.kind() == SyntaxKind::K_OUTPUT)
+        }
+
+        /// Columns declared for the relation.
+        #[must_use]
+        pub fn columns(&self) -> Vec<(String, String)> {
+            let text = self.syntax.text().to_string();
+            let inner = text
</code_context>

<issue_to_address>
The columns() method uses string splitting, which may be fragile for complex column types.

String splitting may fail for column types containing commas, colons, or parentheses. Using the syntax tree for parsing would provide more reliable column extraction.
</issue_to_address>

### Comment 2
<location> `src/parser/mod.rs:735` </location>
<code_context>
+                .collect()
+        }
+
+        /// Primary key column names if specified.
+        #[must_use]
+        pub fn primary_key(&self) -> Option<Vec<String>> {
+            let text = self.syntax.text().to_string();
+            let inner = text
</code_context>

<issue_to_address>
primary_key() parsing is brittle and may misbehave with unusual formatting.

Parsing with string splitting is fragile; using the syntax tree to extract primary key columns would be more reliable and handle varied formatting.
</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
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e1439e1 and b807091.

📒 Files selected for processing (3)
  • src/language.rs (1 hunks)
  • src/parser/mod.rs (7 hunks)
  • tests/parser.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.rs`: Document public APIs using Rustdoc comments (`///`) so documentation ...

**/*.rs: Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
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.
Prefer .expect() over .unwrap().
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.
Use explicit version ranges in Cargo.toml and keep dependencies up-to-date.
Use rstest fixtures for shared setup.
Replace duplicated tests with #[rstest(...)] parameterised cases.
Prefer mockall for mocks/stubs.
Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
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.
Write unit and behavioural tests for new functionality. Run both before and after making any change.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • src/language.rs
  • 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:

  • src/language.rs
  • tests/parser.rs
  • src/parser/mod.rs
🧬 Code Graph Analysis (1)
tests/parser.rs (1)
src/parser/mod.rs (8)
  • parse (93-105)
  • relations (549-555)
  • is_input (702-706)
  • is_output (710-714)
  • name (622-628)
  • name (687-698)
  • columns (718-733)
  • primary_key (737-750)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test
🔇 Additional comments (3)
src/language.rs (1)

145-145: LGTM!

The addition of N_RELATION_DECL follows the established naming convention and is appropriately placed with other declaration node types.

tests/parser.rs (1)

55-68: Well-structured test coverage!

The test fixtures and corresponding tests provide comprehensive coverage for relation parsing, including:

  • Different relation types (input, output, internal)
  • Primary key variations (single column, compound, none)
  • Proper verification of all relation properties

The tests follow the established patterns in the file and use rstest fixtures appropriately.

Also applies to: 299-367

src/parser/mod.rs (1)

737-750: Our sandbox environment can’t be reached without cloning the repo first. To confirm how columns() is implemented and whether it also uses string slicing, let’s search for its definition.

Could you run this in your local checkout?

rg -n "fn columns" -n src/parser/mod.rs

That will show if columns() uses similar fragile string parsing.
If it does, we should recommend replacing both methods with AST traversal rather than text splits; otherwise, we only need to update primary_key().

Let me know what you find.

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

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

775-830: Column parsing implementation is more robust than previous feedback suggested.

The current implementation properly traverses the syntax tree and handles nested parentheses with depth tracking, which addresses the concerns raised in past reviews about string splitting. This approach is much more reliable for complex column types.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b807091 and 18ddefe.

📒 Files selected for processing (2)
  • src/parser/mod.rs (7 hunks)
  • tests/parser.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.rs`: Document public APIs using Rustdoc comments (`///`) so documentation ...

**/*.rs: Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
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.
Prefer .expect() over .unwrap().
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.
Use explicit version ranges in Cargo.toml and keep dependencies up-to-date.
Use rstest fixtures for shared setup.
Replace duplicated tests with #[rstest(...)] parameterised cases.
Prefer mockall for mocks/stubs.
Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
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.
Write unit and behavioural tests for new functionality. Run both before and after making any change.

📄 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
🧬 Code Graph Analysis (2)
tests/parser.rs (1)
src/parser/mod.rs (14)
  • parse (93-105)
  • relations (606-612)
  • is_input (759-763)
  • is_output (767-771)
  • name (679-685)
  • name (744-755)
  • columns (775-830)
  • primary_key (834-930)
  • errors (82-84)
  • syntax (554-556)
  • syntax (624-626)
  • syntax (631-645)
  • syntax (673-675)
  • syntax (738-740)
src/parser/mod.rs (3)
src/parser/token_stream.rs (4)
  • tokens (105-107)
  • src (118-120)
  • peek (76-78)
  • new (41-47)
src/parser/span_collector.rs (1)
  • new (44-50)
src/language.rs (1)
  • kind_to_raw (183-188)
🔇 Additional comments (9)
tests/parser.rs (5)

55-73: Test fixtures are well-structured and comprehensive.

The fixtures cover all the essential relation declaration scenarios: input relations with primary keys, output relations without primary keys, internal relations with compound primary keys, and multiline formatting. This provides good test coverage for the new relation parsing functionality.


304-324: Input relation test is thorough and correct.

The test properly validates all aspects of the parsed input relation including the input/output flags, name extraction, column parsing, and primary key identification.


326-346: Output relation test correctly validates the parsing.

The test appropriately checks that output relations are identified correctly and validates the expected behaviour when no primary key is specified.


348-372: Internal relation test validates compound primary keys well.

The test effectively verifies parsing of relations that are neither input nor output, and correctly handles compound primary keys with multiple columns.


374-394: Multiline relation test with round-trip validation is excellent.

The test not only verifies correct parsing of multiline declarations but also ensures that the CST preserves the original formatting through the round-trip test. This is crucial for tools that need to maintain source formatting.

src/parser/mod.rs (4)

94-97: Parsing pipeline updates are consistent and well-integrated.

The changes to include relation spans in the parsing pipeline follow the established patterns for imports and typedefs. The documentation has been appropriately updated to reflect the new functionality.

Also applies to: 107-127


414-418: CST construction updates follow established patterns.

The changes to build_green_tree correctly integrate relation spans into the CST construction process, maintaining consistency with how imports and typedefs are handled.

Also applies to: 424-454


604-612: Root::relations() method is well-implemented.

The method follows the established pattern of other collection methods and provides typed access to relation declarations.


335-340: Rust nightly channel in use – Let chains supported

The rust-toolchain file pins the project to nightly-2025-06-10, which fully supports let chains. No changes required.

Comment thread src/parser/mod.rs Outdated
Comment thread src/parser/mod.rs Outdated
@leynos leynos merged commit c5dccb5 into main Jun 29, 2025
2 checks passed
@leynos leynos deleted the codex/implement-relation-parser-for-declarations branch June 29, 2025 16:54
This was referenced Jun 29, 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