Skip to content
Draft
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
9 changes: 8 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ let package = Package(
],
swiftSettings: swiftSettings
),
.testTarget(name: "WITTests", dependencies: ["WIT"], swiftSettings: swiftSettings),
.testTarget(
name: "WITTests",
dependencies: [
"WIT",
.target(name: "WasmTools", condition: .when(traits: ["ComponentModel"])),
],
swiftSettings: swiftSettings
),

.target(
name: "WAVE",
Expand Down
6 changes: 3 additions & 3 deletions Sources/WIT/AST.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public enum HandleSyntax: Equatable, Hashable, Sendable {
case own(resource: Identifier)
case borrow(resource: Identifier)

var id: Identifier {
public var id: Identifier {
switch self {
case .own(let resource): return resource
case .borrow(let resource): return resource
Expand All @@ -182,7 +182,7 @@ public enum HandleSyntax: Equatable, Hashable, Sendable {
}

public struct ResourceSyntax: Equatable, Hashable, Sendable {
var functions: [ResourceFunctionSyntax]
public var functions: [ResourceFunctionSyntax]
}

public enum ResourceFunctionSyntax: Equatable, Hashable, Sendable {
Expand Down Expand Up @@ -312,7 +312,7 @@ public struct UseNameSyntax: Equatable, Hashable, Sendable {

public struct IncludeSyntax: Equatable, Hashable, Sendable {
var attributes: [AttributeSyntax]
var from: UsePathSyntax
public var from: UsePathSyntax
var names: [IncludeNameSyntax]
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/WIT/TextParser/ParseFunctionDecl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ extension FunctionSyntax {
}

extension NamedFunctionSyntax {
static func parse(lexer: inout Lexer, documents: DocumentsSyntax) throws -> SyntaxNode<NamedFunctionSyntax> {
static func parse(lexer: inout Lexer, documents: DocumentsSyntax, attributes: [AttributeSyntax] = []) throws -> SyntaxNode<NamedFunctionSyntax> {
let name = try Identifier.parse(lexer: &lexer)
try lexer.expect(.colon)
let function = try FunctionSyntax.parse(lexer: &lexer)
try lexer.expectSemicolon()
return .init(syntax: NamedFunctionSyntax(documents: documents, attributes: [], name: name, function: function))
return .init(syntax: NamedFunctionSyntax(documents: documents, attributes: attributes, name: name, function: function))
}
}
4 changes: 2 additions & 2 deletions Sources/WIT/TextParser/ParseInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ extension InterfaceItemSyntax {
case .union:
return try .typeDef(.init(syntax: .parseUnion(lexer: &lexer, documents: documents, attributes: attributes)))
case .id, .explicitId:
return try .function(NamedFunctionSyntax.parse(lexer: &lexer, documents: documents))
return try .function(NamedFunctionSyntax.parse(lexer: &lexer, documents: documents, attributes: attributes))
case .use:
return try .use(UseSyntax.parse(lexer: &lexer))
return try .use(UseSyntax.parse(lexer: &lexer, attributes: attributes))
default:
throw ParseError(description: "`import`, `export`, `include`, `use`, or type definition")
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/WIT/TextParser/ParseTop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ extension TopLevelUseSyntax {
}

extension UseSyntax {
static func parse(lexer: inout Lexer) throws -> SyntaxNode<UseSyntax> {
static func parse(lexer: inout Lexer, attributes: [AttributeSyntax] = []) throws -> SyntaxNode<UseSyntax> {
try lexer.expect(.use)
let from = try UsePathSyntax.parse(lexer: &lexer)
try lexer.expect(.period)
Expand All @@ -197,7 +197,7 @@ extension UseSyntax {
}
}
try lexer.expectSemicolon()
return .init(syntax: UseSyntax(attributes: [], from: from, names: names))
return .init(syntax: UseSyntax(attributes: attributes, from: from, names: names))
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/WIT/TextParser/ParseTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ extension TypeDefSyntax {
if lexer.eat(.leftBrace) {
while !lexer.eat(.rightBrace) {
let docs = try DocumentsSyntax.parse(lexer: &lexer)
functions.append(try ResourceFunctionSyntax.parse(lexer: &lexer, documents: docs, attributes: []))
let attributes = try AttributeSyntax.parseItems(lexer: &lexer)
functions.append(try ResourceFunctionSyntax.parse(lexer: &lexer, documents: docs, attributes: attributes))
}
} else {
try lexer.expectSemicolon()
Expand Down
2 changes: 1 addition & 1 deletion Sources/WIT/TextParser/ParseWorld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension WorldItemSyntax {
case .export:
return try .export(.parse(lexer: &lexer, documents: documents, attributes: attributes))
case .use:
return try .use(UseSyntax.parse(lexer: &lexer))
return try .use(UseSyntax.parse(lexer: &lexer, attributes: attributes))
case .type:
return try .type(.init(syntax: .parse(lexer: &lexer, documents: documents, attributes: attributes)))
case .flags:
Expand Down
Loading
Loading