Skip to content

refactor(kotlin-wasm): read WIT with the shared AST parser instead of regexes - #76

Merged
walterjgsp merged 1 commit into
kotlinfrom
fix/kotlin-wasm-wit-ast
Oct 4, 2026
Merged

walterjgsp merged 1 commit into
kotlinfrom
fix/kotlin-wasm-wit-ast

Conversation

@walterjgsp

Copy link
Copy Markdown
Contributor

Item 3 of #66 (Kotlin wasm side). Uses the shared parser from #73 and the static fix from #75, both synced here.

please_kotlin_wasm.ParseWit scanned lines with funcRegex, ifaceRegex, packageRegex. That missed functions over several lines, versioned packages, and put resource methods in the interface. Now:

  • ParseWit uses ast.ParseFileLenient (skips use/variant/flags, as the line scanner effectively did), keeping its old output (WitInterface, package as a.b).
  • MapTypeToKotlin(*ast.TypeRef) replaces MapWitTypeToKotlin(string), which split result<...> on commas and so broke on nested generics. Same mapping for everything it handled; tuple is now an error naming the function and parameter instead of a bogus generated name.
  • Interfaces in a file without package take the package of another file in the directory (a WIT package spans its directory); before they got none.
  • Resource methods are no longer emitted as interface functions.
  • A file that does not parse is an error naming the file; before, an unreadable file was skipped.

Not touched: DetectPackage/hasClassInSources also use regexes, but on Kotlin source, not WIT (separate item).

Tests: the old mapping test, rewritten over parsed types plus nested generics; a structure test (comments, multi-line function, versioned package, use/variant/flags, a resource, a second file without package, a non-.wit file); tuple and syntax errors. plz test //tools/please_kotlin_wasm/...: 13 passed.

🤖 Generated with Claude Code

… regexes

ParseWit scanned lines with funcRegex, ifaceRegex and packageRegex, which broke on multi-line functions, comments and versioned packages, and listed resource methods as interface functions. It now uses the lenient AST parser from tools/common/wit/ast, and MapTypeToKotlin maps the parsed type structurally instead of splitting strings on commas. Item 3 of #66.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@walterjgsp
walterjgsp merged commit 8a91e40 into kotlin Oct 4, 2026
2 checks passed
@walterjgsp
walterjgsp deleted the fix/kotlin-wasm-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