Skip to content

feat(grammar): support feature gates on nested items - #31

Merged
mkatychev merged 3 commits into
bytecodealliance:mainfrom
ArcellaTeam:feature-gates-on-nested-items
Aug 1, 2026
Merged

feat(grammar): support feature gates on nested items#31
mkatychev merged 3 commits into
bytecodealliance:mainfrom
ArcellaTeam:feature-gates-on-nested-items

Conversation

@avasich

@avasich avasich commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes a parse error where nested feature gates were not recognized by the grammar, and does a minor refactor to align item bodies closer to the spec.

1. Nested Feature Gates

Currently, tree-sitter parse fails on valid code with gates inside resources:

interface poll {
    resource pollable {
        @since(version = 0.2.0)
        ready: func() -> bool;
    }
}

This patch adds optional($._gate) to _resource_body.

Furthermore, I added optional($._gate) to _record_fields, _flags_fields, _variant_cases, and _enum_cases. Given the precedent of prioritizing practicality over strict spec adherence (e.g. #30), supporting these seems appropriate.

2. Grammar Shape Refactoring

Refactored _world_body and _interface_body to hoist the gate parsing out of the specific item choices. This aligns the grammar structure with the spec:

world-items ::= gate world-definition

matching the existing implementation for _resource_body.

…arsing with spec

- Allows feature gates (`@since`, etc.) on resource methods, record fields, variant cases, and enum cases. Official Wasm repos utilize these nested gates despite them lacking explicit definitions in the spec:
https://github.com/WebAssembly/wasi-http/blob/7c678c4c10238a4bf4db91a0e27023d680ff65fe/wit/deps/io/poll.wit

- Refactors `_world_body` and `_interface_body` to hoist `optional($._gate)` out of the item definitions, mirroring the spec's `world-items ::= gate world-definition` structure.
@mkatychev

Copy link
Copy Markdown
Member

Hi @avasich thanks for the submission. I will get to this later this week, was preoccupied with other projects.

@mkatychev
mkatychev self-requested a review July 29, 2026 17:16
@mkatychev

Copy link
Copy Markdown
Member

@avasich thank you for the addition, could you please add a test case for this change?

@mkatychev mkatychev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM
EDIT: though we'll need to get the CI tests to pass first

@mkatychev
mkatychev self-requested a review August 1, 2026 16:03
@avasich

avasich commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

My bad, I was using the wrong tree-sitter-cli version. Maybe it's worth updating the version in package.json?

You added the --incompatible flag to cargo upgrade in justfile when bumping tree-sitter in Cargo.toml from 0.25.6 to 0.26.11. How about adding the --latest flag to pnpm update as well?

update:
    pnpm outdated --format json | jq  'keys[]' | xargs pnpm update --latest
    cargo upgrade --incompatible && cargo update

@mkatychev

Copy link
Copy Markdown
Member

Good point!

My bad, I was using the wrong tree-sitter-cli version. Maybe it's worth updating the version in package.json?

You added the --incompatible flag to cargo upgrade in justfile when bumping tree-sitter in Cargo.toml from 0.25.6 to 0.26.11. How about adding the --latest flag to pnpm update as well?

update:
    pnpm outdated --format json | jq  'keys[]' | xargs pnpm update --latest
    cargo upgrade --incompatible && cargo update

@mkatychev
mkatychev merged commit cdf0726 into bytecodealliance:main Aug 1, 2026
4 checks passed
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.

2 participants