Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions WIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ keywords is still in flux at this time but the current set is:
keyword ::= 'use'
| 'type'
| 'resource'
| 'function'
| 'func'
| 'u8' | 'u16' | 'u32' | 'u64'
| 's8' | 's16' | 's32' | 's64'
| 'float32' | 'float64'
Expand Down Expand Up @@ -375,9 +375,9 @@ parameters, and results. Functions can optionally also be declared as `async`
functions.

```wit
thunk: function()
fibonacci: function(n: u32) -> u32
sleep: async function(ms: u64)
thunk: func()
fibonacci: func(n: u32) -> u32
sleep: async func(ms: u64)
```

Specifically functions have the structure:
Expand Down Expand Up @@ -410,10 +410,10 @@ of the including resource, unless the function is flagged as `static`.
resource file-descriptor

resource request {
static new: function() -> request
static new: func() -> request

body: async function() -> list<u8>
headers: function() -> list<string>
body: async func() -> list<u8>
headers: func() -> list<string>
}
```

Expand Down Expand Up @@ -506,22 +506,22 @@ by '-'s starts with a `XID_Start` scalar value with a zero Canonical Combining
Class:

```wit
foo: function(bar: u32)
foo: func(bar: u32)

red-green-blue: function(r: u32, g: u32, b: u32)
red-green-blue: func(r: u32, g: u32, b: u32)
```

This form can't name identifiers which have the same name as wit keywords, so
the second form is the same syntax with the same restrictions as the first, but
prefixed with '%':

```wit
%foo: function(%bar: u32)
%foo: func(%bar: u32)

%red-green-blue: function(%r: u32, %g: u32, %b: u32)
%red-green-blue: func(%r: u32, %g: u32, %b: u32)

// This form also supports identifiers that would otherwise be keywords.
%variant: function(%enum: s32)
%variant: func(%enum: s32)
```

[kebab-case]: https://en.wikipedia.org/wiki/Letter_case#Kebab_case
Expand Down
18 changes: 9 additions & 9 deletions crates/gen-wasmtime/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod imports {
mod async_tests {
mod not_async {
wit_bindgen_wasmtime::export!({
src["x"]: "foo: function()",
src["x"]: "foo: func()",
async: ["bar"],
});

Expand All @@ -54,8 +54,8 @@ mod async_tests {
mod one_async {
wit_bindgen_wasmtime::export!({
src["x"]: "
foo: function() -> list<u8>
bar: function()
foo: func() -> list<u8>
bar: func()
",
async: ["bar"],
});
Expand All @@ -74,8 +74,8 @@ mod async_tests {
mod one_async_export {
wit_bindgen_wasmtime::import!({
src["x"]: "
foo: function(x: list<string>)
bar: function()
foo: func(x: list<string>)
bar: func()
",
async: ["bar"],
});
Expand All @@ -84,7 +84,7 @@ mod async_tests {
wit_bindgen_wasmtime::export!({
src["x"]: "
resource y {
z: function() -> string
z: func() -> string
}
",
async: [],
Expand All @@ -95,13 +95,13 @@ mod async_tests {
mod custom_errors {
wit_bindgen_wasmtime::export!({
src["x"]: "
foo: function()
bar: function() -> expected<unit, u32>
foo: func()
bar: func() -> expected<unit, u32>
enum errno {
bad1,
bad2,
}
baz: function() -> expected<u32, errno>
baz: func() -> expected<u32, errno>
",
custom_error: true,
});
Expand Down
4 changes: 2 additions & 2 deletions crates/parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ impl<'a> Value<'a> {
let name = parse_id(tokens)?;
tokens.expect(Token::Colon)?;

let kind = if tokens.eat(Token::Function)? {
let kind = if tokens.eat(Token::Func)? {
parse_func(tokens, false)?
} else if tokens.eat(Token::Async)? {
tokens.expect(Token::Function)?;
tokens.expect(Token::Func)?;
parse_func(tokens, true)?
} else {
ValueKind::Global(Type::parse(tokens)?)
Expand Down
18 changes: 15 additions & 3 deletions crates/parser/src/ast/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub enum Token {
Use,
Type,
Resource,
Function,
Func,
U8,
U16,
U32,
Expand Down Expand Up @@ -237,7 +237,7 @@ impl<'a> Tokenizer<'a> {
"use" => Use,
"type" => Type,
"resource" => Resource,
"function" => Function,
"func" => Func,
"u8" => U8,
"u16" => U16,
"u32" => U32,
Expand Down Expand Up @@ -499,7 +499,7 @@ impl Token {
Use => "keyword `use`",
Type => "keyword `type`",
Resource => "keyword `resource`",
Function => "keyword `function`",
Func => "keyword `func`",
U8 => "keyword `u8`",
U16 => "keyword `u16`",
U32 => "keyword `u32`",
Expand Down Expand Up @@ -675,6 +675,18 @@ fn test_tokenizer() {
assert_eq!(collect("%bool").unwrap(), vec![Token::ExplicitId]);
assert_eq!(collect("%").unwrap(), vec![Token::ExplicitId]);

assert_eq!(collect("func").unwrap(), vec![Token::Func]);
assert_eq!(
collect("a: func()").unwrap(),
vec![
Token::Id,
Token::Colon,
Token::Func,
Token::LeftParen,
Token::RightParen
]
);

assert!(collect("\u{149}").is_err(), "strongly discouraged");
assert!(collect("\u{673}").is_err(), "strongly discouraged");
assert!(collect("\u{17a3}").is_err(), "strongly discouraged");
Expand Down
12 changes: 6 additions & 6 deletions crates/parser/tests/ui/async.wit
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
a: async function()
b: async function(x: s32)
c: async function() -> u32
a: async func()
b: async func(x: s32)
c: async func() -> u32

resource y {
a: async function()
b: async function(x: s32)
c: async function() -> u32
a: async func()
b: async func(x: s32)
c: async func() -> u32
}
6 changes: 3 additions & 3 deletions crates/parser/tests/ui/embedded.wit.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
containing stuff, and also some code blocks, wit and other.

```wit
x: function()
x: func()
```

Intervening content, including a non-wit codeblock:
Expand All @@ -12,13 +12,13 @@ function func() {}
```

```wit
y: function()
y: func()
```

## A new section

In which, another wit code block!

```wit
z: function()
z: func()
```
14 changes: 7 additions & 7 deletions crates/parser/tests/ui/functions.wit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
f1: function()
f2: function(a: u32)
f3: function(a: u32,)
f4: function() -> u32
f6: function() -> tuple<u32, u32>
f7: function(a: float32, b: float32) -> tuple<u32, u32>
f8: function(a: option<u32>) -> expected<u32, float32>
f1: func()
f2: func(a: u32)
f3: func(a: u32,)
f4: func() -> u32
f6: func() -> tuple<u32, u32>
f7: func(a: float32, b: float32) -> tuple<u32, u32>
f8: func(a: option<u32>) -> expected<u32, float32>
2 changes: 1 addition & 1 deletion crates/parser/tests/ui/parse-fail/async.wit.result
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
expected keyword `function`, found eof
expected keyword `func`, found eof
--> tests/ui/parse-fail/async.wit:3:1
|
3 |
Expand Down
2 changes: 1 addition & 1 deletion crates/parser/tests/ui/parse-fail/async1.wit.result
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
expected keyword `function`, found '('
expected keyword `func`, found '('
--> tests/ui/parse-fail/async1.wit:2:9
|
2 | a: async()
Expand Down
4 changes: 2 additions & 2 deletions crates/parser/tests/ui/parse-fail/bad-resource2.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// parse-fail

resource x {
x: function()
x: function()
x: func()
x: func()
}
2 changes: 1 addition & 1 deletion crates/parser/tests/ui/parse-fail/bad-resource2.wit.result
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"x" defined twice in this resource
--> tests/ui/parse-fail/bad-resource2.wit:5:3
|
5 | x: function()
5 | x: func()
| ^
4 changes: 2 additions & 2 deletions crates/parser/tests/ui/parse-fail/duplicate-functions.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// parse-fail

foo: function()
foo: function()
foo: func()
foo: func()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"foo" defined twice
--> tests/ui/parse-fail/duplicate-functions.wit:4:1
|
4 | foo: function()
4 | foo: func()
| ^--
6 changes: 3 additions & 3 deletions crates/parser/tests/ui/resource.wit
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ resource b
resource c
resource d {}
resource e {
x: function()
x: func()
}
resource f {
x: function()
y: function()
x: func()
y: func()
}
2 changes: 1 addition & 1 deletion crates/parser/tests/ui/type-then-eof.wit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
foo: function() -> string
foo: func() -> string
4 changes: 2 additions & 2 deletions crates/parser/tests/ui/wasi-clock.wit
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use { clockid, timestamp, errno } from wasi
// Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
// return `errno::inval`.
// Note: This is similar to `clock-getres` in POSIX.
res-get: function(id: clockid) -> expected<timestamp, errno>
res-get: func(id: clockid) -> expected<timestamp, errno>

// Return the time value of a clock.
// Note: This is similar to `clock-gettime` in POSIX.
time-get: function(id: clockid, precision: timestamp) -> expected<timestamp, errno>
time-get: func(id: clockid, precision: timestamp) -> expected<timestamp, errno>
Loading