-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Currently the extern-type
rule in the WIT grammar is:
extern-type ::= func-type ';' | 'interface' '{' interface-items* '}'
This means that both the import-item
and export-item
rules in a world may only have named function or inlined interface items.
For example:
world foo {
import a: func();
export b: interface {
bar: func();
}
}
However, it may be desirable to have a single interface definition that is imported or exported under different names in a world or to simply import or export a "known" interface with a different kebab name.
The former is currently not possible in the grammar, but it is possible with copy-and-paste:
world foo {
import a: interface {
bar: func();
}
import b: interface {
bar: func();
}
}
This obviously duplicates the type information on every inline interface definition.
What I propose with this issue is to add use-path
as a case to the extern-type
rule.
This would allow for the following:
interface bar {
bar: func();
}
world foo {
import a: bar;
import b: bar;
}
and also for:
world foo {
import my-http-handler: wasi:http/incoming-handler;
}
Note: there may be ambiguity introduced by extending the extern-type
rule in the current wit-parser
implementation as right now it allows lexing foo: bar
as a package name made up of three tokens (<id>
, ':'
, <id>
); a hypothetical import foo: bar:baz/qux
in a world might be difficult for it to parse as it will likely see that as an import of a package path with nested namespaces. The wac
parser lexes package paths as individual tokens and therefore prohibits whitespace in the path, so that would lex as <import-keyword>
, <id>
, :
, <package-path>
rather than <import-keyword>
, <package-path>
.