Skip to content

rust: parse attributes on struct pattern fields - #319

Open
ssmith-synaptixs wants to merge 1 commit into
tree-sitter:masterfrom
ssmith-synaptixs:codex/field-pattern-attributes
Open

ssmith-synaptixs wants to merge 1 commit into
tree-sitter:masterfrom
ssmith-synaptixs:codex/field-pattern-attributes

Conversation

@ssmith-synaptixs

Copy link
Copy Markdown

Summary

Allow outer attributes before fields in a struct pattern. Rust permits constructs such as:

let JSONOutput {
    syntax_grammar,
    #[cfg(feature = "load")]
    node_types_json,
    str_pool,
} = output;

The current grammar produces an ERROR node over the attributed field. This occurs in the pinned Synaptreesitter master source at crates/generate/src/generate.rs (commit 867aa6d14418163560bf89f12c48107098b1ec8f).

Change

Add repeat($.attribute_item) to field_pattern, regenerate the parser and node types with the repository's Tree-sitter CLI 0.26.7, and add a corpus regression case.

Validation

  • tree-sitter test: 152/152 corpus cases pass, including the new case.
  • A Python binding built from this grammar parses all 109 Rust files in the pinned Synaptreesitter checkout with 0 ERROR files and 0 error lines (63,981 source lines).
  • The same binding parses all 5 Rust files in pinned itoa 1577ed901354d0d7448ac162328f9dbf5183124c with 0 error lines (630 source lines).

@wetneb

wetneb commented Oct 5, 2026

Copy link
Copy Markdown

Hi @ssmith-synaptixs,

Since external pull requests are rarely integrated in this repository, we have been maintaining a community-owned fork of this repository, tree-sitter-rust-orchard. I have been porting there all contributions made to this GitHub repository for the past few years.

Your contribution doesn't need porting because we already support such attributes. We also bundle them together with the syntactic element they annotate, making the AST structure more useful for downstream users.

If you encounter any issue switching to this grammar (as a user or contributor), let me know.
I encourage you to leave this PR open to make the unmaintained status of this repo clearer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants