feat(grammar): support feature gates on nested items - #31
Conversation
…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.
|
Hi @avasich thanks for the submission. I will get to this later this week, was preoccupied with other projects. |
|
@avasich thank you for the addition, could you please add a test case for this change? |
|
My bad, I was using the wrong tree-sitter-cli version. Maybe it's worth updating the version in package.json? You added the update:
pnpm outdated --format json | jq 'keys[]' | xargs pnpm update --latest
cargo upgrade --incompatible && cargo update |
|
Good point!
|
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 parsefails on valid code with gates inside resources: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_bodyand_interface_bodyto hoist the gate parsing out of the specific item choices. This aligns the grammar structure with the spec:matching the existing implementation for
_resource_body.