Skip to content

feat(common): move the WIT ast parser to tools/common and add a lenient mode - #73

Merged
walterjgsp merged 1 commit into
mainfrom
feat/common-wit-ast
Oct 4, 2026
Merged

walterjgsp merged 1 commit into
mainfrom
feat/common-wit-ast

Conversation

@walterjgsp

Copy link
Copy Markdown
Contributor

Item 3 of #66, step 1: the shared parser.

please_wit (wit branch) and please_kotlin_wasm (kotlin branch) both read WIT with regexes (worldRegex, packageRegex, funcRegex, ifaceRegex...), which break on comments, package a:b@1.0;, multi-line functions, or two declarations on one line. The wit branch already has a real lexer and parser (ast); this moves it to tools/common/wit/ast unchanged, so both branches can use it (follow-up PRs).

Additions:

  • ParseContentLenient / ParseFileLenient: skip declarations the parser does not model (use, variant, flags, include), for callers that only need names, like world and package discovery. Without it, a file with a use statement would make discovery fail where the regex used to work.
  • Strict mode (generators) now fails with line N: "use" declarations are not supported instead of expected token type 2, so a generator never silently drops a variant.
  • Worlds skip a whole use x.{y}/type/record declaration so its braces cannot end the world early.

27 existing tests unchanged and passing, 3 new (30 total).

🤖 Generated with Claude Code

…nt mode

The WIT parser lived on the wit branch while the Kotlin wasm rules and please_wit both parsed WIT with regexes. Moving it to main lets every branch share it. Lenient mode skips declarations it does not model (use, variant, flags, include) for callers that only need names; the strict mode now reports them by name instead of a token-type error. Item 3 of #66.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@walterjgsp
walterjgsp merged commit e5b7da3 into main Oct 4, 2026
3 checks passed
@walterjgsp
walterjgsp deleted the feat/common-wit-ast branch October 9, 2026 22:28
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.

1 participant