Skip to content

Add SyntaxKind and language wrapper#6

Merged
leynos merged 2 commits intomainfrom
codex/define-syntaxkind-enum-and-implement-language-for-ddloglangu
Jun 24, 2025
Merged

Add SyntaxKind and language wrapper#6
leynos merged 2 commits intomainfrom
codex/define-syntaxkind-enum-and-implement-language-for-ddloglangu

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 24, 2025

Summary

  • add rowan, num-derive and num-traits dependencies
  • define SyntaxKind enum for tokens and nodes
  • implement DdlogLanguage for rowan integration

Testing

  • make fmt
  • make lint
  • make test
  • make markdownlint

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

Summary by Sourcery

Add rowan-based syntax tree support by defining a comprehensive SyntaxKind enum for DDlog tokens and nodes, wrapping it in a DdlogLanguage type that implements rowan::Language, and expose these in the library crate.

New Features:

  • Define a SyntaxKind enum covering all DDlog tokens and nonterminal nodes
  • Introduce DdlogLanguage newtype implementing rowan::Language for syntax tree tagging

Enhancements:

  • Re-export DdlogLanguage and SyntaxKind from the crate root

Build:

  • Add rowan, num-derive, and num-traits dependencies for enum conversion and syntax integration

Summary by CodeRabbit

  • New Features
    • Introduced a new library exposing parser language definitions for DDlog, including a comprehensive set of syntax kinds and integration with syntax tree tooling.
    • Added a public module for language support, enabling typed syntax tree construction and manipulation.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 24, 2025

Reviewer's Guide

Integrate rowan-based parsing by adding necessary dependencies, defining a comprehensive SyntaxKind enum, implementing the DdlogLanguage wrapper for rowan’s Language trait, and exposing the language module in lib.rs.

Class diagram for SyntaxKind enum and DdlogLanguage wrapper

classDiagram
    class SyntaxKind {
        <<enum>>
        +T_COMMENT
        +T_WHITESPACE
        +T_IDENT
        +T_STRING
        +T_NUMBER
        +T_LPAREN
        +T_RPAREN
        +T_LBRACE
        +T_RBRACE
        +T_LBRACKET
        +T_RBRACKET
        +T_SEMI
        +T_COMMA
        +T_DOT
        +T_COLON
        +T_COLON_COLON
        +T_PIPE
        +T_AMP
        +T_EQEQ
        +T_EQ
        +T_IMPLIES
        +T_PERCENT
        +T_STAR
        +T_SLASH
        +T_PLUS
        +T_MINUS
        +T_ARROW
        +T_FAT_ARROW
        +T_LTE
        +T_SPACESHIP
        +T_GTE
        +T_LT
        +T_GT
        +T_NEQ
        +T_SHR
        +T_SHL
        +T_TILDE
        +T_AT
        +T_HASH
        +T_APOSTROPHE
        +K_ABSTRACT
        +K_AGGREGATE
        +K_AND
        +K_APPLY
        +K_AS
        +K_ASYNC
        +K_AWAIT
        +K_BECOME
        +K_BIGINT
        +K_BIT
        +K_BOOL
        +K_BOX
        +K_BREAK
        +K_CONST
        +K_CONTINUE
        +K_CRATE
        +K_DO
        +K_DOUBLE
        +K_DYN
        +K_ELSE
        +K_EXTERN
        +K_FALSE
        +K_FINAL
        +K_FN
        +K_FLATMAP
        +K_FLOAT
        +K_FOR
        +K_FUNCTION
        +K_IF
        +K_IMPL
        +K_IMPORT
        +K_IN
        +K_INPUT
        +K_INSPECT
        +K_LET
        +K_LOOP
        +K_MACRO
        +K_MATCH
        +K_MOD
        +K_MOVE
        +K_MULTISET
        +K_MUT
        +K_NOT
        +K_OR
        +K_OVERRIDE
        +K_OUTPUT
        +K_PRIV
        +K_PUB
        +K_REF
        +K_RELATION
        +K_RETURN
        +K_SELF
        +K_SELF_TYPE
        +K_SIGNED
        +K_SKIP
        +K_STATIC
        +K_STREAM
        +K_STRUCT
        +K_SUPER
        +K_TRAIT
        +K_TRANSFORMER
        +K_TRY
        +K_TRUE
        +K_TYPE
        +K_TYPEDEF
        +K_TYPEOF
        +K_UNDERSCORE
        +K_UNSAFE
        +K_UNSIZED
        +K_USE
        +K_VAR
        +K_VIRTUAL
        +K_WHERE
        +K_WHILE
        +K_YIELD
        +N_ATTRIBUTE
        +N_FIELD
        +N_ARG_TYPE
        +N_IDENTIFIER_WITH_POS
        +N_TYPE
        +N_TYPE_DEF
        +N_CONSTRUCTOR
        +N_KEY_EXPR
        +N_RELATION_ROLE
        +N_RELATION_SEMANTICS
        +N_RELATION
        +N_INDEX
        +N_DELAY
        +N_ATOM
        +N_RULE_LHS
        +N_RULE_RHS
        +N_RULE
        +N_EXPR_NODE
        +N_CLOSURE_EXPR_ARG
        +N_FUNC_ARG
        +N_FUNCTION
        +N_MODULE_NAME
        +N_HO_TYPE
        +N_HO_FIELD
        +N_TRANSFORMER
        +N_APPLY
        +N_IMPORT
        +N_DATALOG_PROGRAM
        +N_ERROR
    }
    class DdlogLanguage {
        +kind_from_raw(raw: RowanSyntaxKind) SyntaxKind
        +kind_to_raw(kind: SyntaxKind) RowanSyntaxKind
    }
    DdlogLanguage ..> SyntaxKind : uses
Loading

File-Level Changes

Change Details Files
Add rowan and numerical-derive dependencies
  • Add rowan with default-features=false
  • Add num-derive and num-traits with std feature
  • Update Cargo.toml dependencies section
Cargo.toml
Define SyntaxKind enum covering all tokens, keywords, and nodes
  • Derive FromPrimitive/ToPrimitive and set repr(u16)
  • Enumerate all token and keyword variants
  • Enumerate all non-terminal node variants
src/language.rs
Implement DdlogLanguage wrapper for rowan integration
  • Define DdlogLanguage newtype
  • Implement Language trait’s kind_to_raw and kind_from_raw
src/language.rs
Expose language module and types in library root
  • Add pub mod language in lib.rs
  • Re-export SyntaxKind and DdlogLanguage
  • Forbid unsafe code at crate level
src/lib.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 24, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c165383 and 439ddf2.

📒 Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • src/language.rs (1 hunks)
  • src/lib.rs (1 hunks)

Walkthrough

A new library crate for ddlint has been created, introducing a language module that defines the SyntaxKind enum and the DdlogLanguage struct for integration with the rowan parsing library. The Cargo.toml file was updated to include the required dependencies for parsing and numeric trait derivation.

Changes

File(s) Change Summary
Cargo.toml Added dependencies: rowan (0.15), num-derive (0.4), num-traits (0.2).
src/language.rs Introduced SyntaxKind enum for DDlog grammar and DdlogLanguage struct with rowan integration.
src/lib.rs Created crate root, added public language module, and provided crate-level documentation.

Poem

In ddlint's warren, new roots do sprout,
With syntax kinds and tokens all mapped out.
Rowan trees sway as parsing begins,
Enums and traits, where structure wins.
A hop, a skip, new code to see—
Hooray for ddlint’s library!
🐇🌱

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch codex/define-syntaxkind-enum-and-implement-language-for-ddloglangu

🪧 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 and they look great!


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.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 24, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 24, 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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4811ce5 and c165383.

📒 Files selected for processing (3)
  • Cargo.toml (1 hunks)
  • src/language.rs (1 hunks)
  • src/lib.rs (1 hunks)
🔇 Additional comments (2)
Cargo.toml (1)

4-4: edition = "2024" ties the crate to nightly; confirm this is intentional
The 2024 edition is currently only available on nightly toolchains. This will break builds for contributors or CI pipelines that default to stable Rust.
Consider sticking to 2021 until 2024 is stabilised, or document the nightly requirement in README.md/CI config.

src/language.rs (1)

14-18: #[expect(..., reason = "...")] is still a nightly-only feature
The reason field behind lint_reasons requires nightly (mirroring the 2024 edition choice). Make sure CI uses nightly and that downstream crates are aware of this requirement.

Comment thread Cargo.toml Outdated
Comment thread src/lib.rs
Comment thread src/language.rs Outdated
Comment thread src/language.rs
Comment on lines +176 to +182
fn kind_from_raw(raw: RowanSyntaxKind) -> Self::Kind {
SyntaxKind::from_u16(raw.0).unwrap_or(SyntaxKind::N_ERROR)
}

fn kind_to_raw(kind: Self::Kind) -> RowanSyntaxKind {
RowanSyntaxKind(kind.to_u16().unwrap_or(SyntaxKind::N_ERROR as u16))
}
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.

🧹 Nitpick (assertive)

unwrap_or branch is unreachable; prefer explicit expect for clarity
to_u16() is infallible for an enum with #[repr(u16)]. Using unwrap_or hides logic errors. Consider:

-RowanSyntaxKind(kind.to_u16().unwrap_or(SyntaxKind::N_ERROR as u16))
+RowanSyntaxKind(kind.to_u16().expect("all SyntaxKind variants map to u16"))

This makes accidental future misuse obvious in debug builds.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn kind_from_raw(raw: RowanSyntaxKind) -> Self::Kind {
SyntaxKind::from_u16(raw.0).unwrap_or(SyntaxKind::N_ERROR)
}
fn kind_to_raw(kind: Self::Kind) -> RowanSyntaxKind {
RowanSyntaxKind(kind.to_u16().unwrap_or(SyntaxKind::N_ERROR as u16))
}
fn kind_from_raw(raw: RowanSyntaxKind) -> Self::Kind {
SyntaxKind::from_u16(raw.0).unwrap_or(SyntaxKind::N_ERROR)
}
fn kind_to_raw(kind: Self::Kind) -> RowanSyntaxKind {
RowanSyntaxKind(kind.to_u16().expect("all SyntaxKind variants map to u16"))
}
🤖 Prompt for AI Agents
In src/language.rs around lines 176 to 182, replace the use of unwrap_or in
kind_to_raw with an explicit expect call, since to_u16() is infallible for the
enum and the unwrap_or branch is unreachable. This change will make any
accidental misuse clear by panicking with a descriptive message instead of
silently defaulting.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 24, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 24, 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
Copy link
Copy Markdown
Owner Author

leynos commented Jun 24, 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 and they look great!


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.

@leynos leynos merged commit d03b852 into main Jun 24, 2025
1 check passed
@leynos leynos deleted the codex/define-syntaxkind-enum-and-implement-language-for-ddloglangu branch June 24, 2025 16:10
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