Skip to content

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

Open
avasich wants to merge 1 commit into
bytecodealliance:mainfrom
avasich:feature-gates-on-nested-items
Open

feat(grammar): support feature gates on nested items#31
avasich wants to merge 1 commit into
bytecodealliance:mainfrom
avasich:feature-gates-on-nested-items

Conversation

@avasich

@avasich avasich commented Jul 22, 2026

Copy link
Copy Markdown

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