Skip to content

improve implementation of without operator #1559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2023
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
2 changes: 1 addition & 1 deletion CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ public let DECL_NODES: [Node] = [
/// indicate the suppression of implicit conformance to this type.
/// This child stores the token representing the 'without' operator.
Child(
name: "HasWithout",
name: "WithoutTilde",
kind: .token(choices: [.token(tokenKind: "PrefixOperatorToken")]),
isOptional: true
),
Expand Down
6 changes: 2 additions & 4 deletions Sources/SwiftParser/Nominals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,14 @@ extension Parser {
)
)
} else {
if self.currentToken.starts(with: "~") {
withoutToken = self.consumePrefix("~", as: .prefixOperator)
}
withoutToken = self.consumeIfContextualPunctuator("~", remapping: .prefixOperator)
type = self.parseType()
}

keepGoing = self.consume(if: .comma)
elements.append(
RawInheritedTypeSyntax(
hasWithout: withoutToken,
withoutTilde: withoutToken,
typeName: type,
trailingComma: keepGoing,
arena: self.arena
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1712,12 +1712,12 @@ internal func childName(_ keyPath: AnyKeyPath) -> String? {
return "rightOperand"
case \InfixOperatorExprSyntax.unexpectedAfterRightOperand:
return "unexpectedAfterRightOperand"
case \InheritedTypeSyntax.unexpectedBeforeHasWithout:
return "unexpectedBeforeHasWithout"
case \InheritedTypeSyntax.hasWithout:
return "hasWithout"
case \InheritedTypeSyntax.unexpectedBetweenHasWithoutAndTypeName:
return "unexpectedBetweenHasWithoutAndTypeName"
case \InheritedTypeSyntax.unexpectedBeforeWithoutTilde:
return "unexpectedBeforeWithoutTilde"
case \InheritedTypeSyntax.withoutTilde:
return "withoutTilde"
case \InheritedTypeSyntax.unexpectedBetweenWithoutTildeAndTypeName:
return "unexpectedBetweenWithoutTildeAndTypeName"
case \InheritedTypeSyntax.typeName:
return "typeName"
case \InheritedTypeSyntax.unexpectedBetweenTypeNameAndTrailingComma:
Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftSyntax/generated/raw/RawSyntaxNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11708,9 +11708,9 @@ public struct RawInheritedTypeSyntax: RawSyntaxNodeProtocol {
}

public init(
_ unexpectedBeforeHasWithout: RawUnexpectedNodesSyntax? = nil,
hasWithout: RawTokenSyntax?,
_ unexpectedBetweenHasWithoutAndTypeName: RawUnexpectedNodesSyntax? = nil,
_ unexpectedBeforeWithoutTilde: RawUnexpectedNodesSyntax? = nil,
withoutTilde: RawTokenSyntax?,
_ unexpectedBetweenWithoutTildeAndTypeName: RawUnexpectedNodesSyntax? = nil,
typeName: RawTypeSyntax,
_ unexpectedBetweenTypeNameAndTrailingComma: RawUnexpectedNodesSyntax? = nil,
trailingComma: RawTokenSyntax?,
Expand All @@ -11720,9 +11720,9 @@ public struct RawInheritedTypeSyntax: RawSyntaxNodeProtocol {
let raw = RawSyntax.makeLayout(
kind: .inheritedType, uninitializedCount: 7, arena: arena) { layout in
layout.initialize(repeating: nil)
layout[0] = unexpectedBeforeHasWithout?.raw
layout[1] = hasWithout?.raw
layout[2] = unexpectedBetweenHasWithoutAndTypeName?.raw
layout[0] = unexpectedBeforeWithoutTilde?.raw
layout[1] = withoutTilde?.raw
layout[2] = unexpectedBetweenWithoutTildeAndTypeName?.raw
layout[3] = typeName.raw
layout[4] = unexpectedBetweenTypeNameAndTrailingComma?.raw
layout[5] = trailingComma?.raw
Expand All @@ -11731,15 +11731,15 @@ public struct RawInheritedTypeSyntax: RawSyntaxNodeProtocol {
self.init(unchecked: raw)
}

public var unexpectedBeforeHasWithout: RawUnexpectedNodesSyntax? {
public var unexpectedBeforeWithoutTilde: RawUnexpectedNodesSyntax? {
layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:))
}

public var hasWithout: RawTokenSyntax? {
public var withoutTilde: RawTokenSyntax? {
layoutView.children[1].map(RawTokenSyntax.init(raw:))
}

public var unexpectedBetweenHasWithoutAndTypeName: RawUnexpectedNodesSyntax? {
public var unexpectedBetweenWithoutTildeAndTypeName: RawUnexpectedNodesSyntax? {
layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:))
}

Expand Down
30 changes: 15 additions & 15 deletions Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10504,9 +10504,9 @@ public struct InheritedTypeSyntax: SyntaxProtocol, SyntaxHashable {

public init<T: TypeSyntaxProtocol>(
leadingTrivia: Trivia? = nil,
_ unexpectedBeforeHasWithout: UnexpectedNodesSyntax? = nil,
hasWithout: TokenSyntax? = nil,
_ unexpectedBetweenHasWithoutAndTypeName: UnexpectedNodesSyntax? = nil,
_ unexpectedBeforeWithoutTilde: UnexpectedNodesSyntax? = nil,
withoutTilde: TokenSyntax? = nil,
_ unexpectedBetweenWithoutTildeAndTypeName: UnexpectedNodesSyntax? = nil,
typeName: T,
_ unexpectedBetweenTypeNameAndTrailingComma: UnexpectedNodesSyntax? = nil,
trailingComma: TokenSyntax? = nil,
Expand All @@ -10517,18 +10517,18 @@ public struct InheritedTypeSyntax: SyntaxProtocol, SyntaxHashable {
// Extend the lifetime of all parameters so their arenas don't get destroyed
// before they can be added as children of the new arena.
let data: SyntaxData = withExtendedLifetime((SyntaxArena(), (
unexpectedBeforeHasWithout,
hasWithout,
unexpectedBetweenHasWithoutAndTypeName,
unexpectedBeforeWithoutTilde,
withoutTilde,
unexpectedBetweenWithoutTildeAndTypeName,
typeName,
unexpectedBetweenTypeNameAndTrailingComma,
trailingComma,
unexpectedAfterTrailingComma
))) {(arena, _) in
let layout: [RawSyntax?] = [
unexpectedBeforeHasWithout?.raw,
hasWithout?.raw,
unexpectedBetweenHasWithoutAndTypeName?.raw,
unexpectedBeforeWithoutTilde?.raw,
withoutTilde?.raw,
unexpectedBetweenWithoutTildeAndTypeName?.raw,
typeName.raw,
unexpectedBetweenTypeNameAndTrailingComma?.raw,
trailingComma?.raw,
Expand All @@ -10546,7 +10546,7 @@ public struct InheritedTypeSyntax: SyntaxProtocol, SyntaxHashable {
self.init(data)
}

public var unexpectedBeforeHasWithout: UnexpectedNodesSyntax? {
public var unexpectedBeforeWithoutTilde: UnexpectedNodesSyntax? {
get {
return data.child(at: 0, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)
}
Expand All @@ -10555,7 +10555,7 @@ public struct InheritedTypeSyntax: SyntaxProtocol, SyntaxHashable {
}
}

public var hasWithout: TokenSyntax? {
public var withoutTilde: TokenSyntax? {
get {
return data.child(at: 1, parent: Syntax(self)).map(TokenSyntax.init)
}
Expand All @@ -10564,7 +10564,7 @@ public struct InheritedTypeSyntax: SyntaxProtocol, SyntaxHashable {
}
}

public var unexpectedBetweenHasWithoutAndTypeName: UnexpectedNodesSyntax? {
public var unexpectedBetweenWithoutTildeAndTypeName: UnexpectedNodesSyntax? {
get {
return data.child(at: 2, parent: Syntax(self)).map(UnexpectedNodesSyntax.init)
}
Expand Down Expand Up @@ -10611,9 +10611,9 @@ public struct InheritedTypeSyntax: SyntaxProtocol, SyntaxHashable {

public static var structure: SyntaxNodeStructure {
return .layout([
\Self.unexpectedBeforeHasWithout,
\Self.hasWithout,
\Self.unexpectedBetweenHasWithoutAndTypeName,
\Self.unexpectedBeforeWithoutTilde,
\Self.withoutTilde,
\Self.unexpectedBetweenWithoutTildeAndTypeName,
\Self.typeName,
\Self.unexpectedBetweenTypeNameAndTrailingComma,
\Self.trailingComma,
Expand Down
30 changes: 29 additions & 1 deletion Tests/SwiftParserTest/DeclarationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1577,9 +1577,37 @@ final class DeclarationTests: XCTestCase {
assertParse(
"""
struct Hello: ~Copyable {}
""",
substructure: Syntax(
InheritedTypeSyntax(
withoutTilde: .prefixOperator("~"),
typeName: TypeSyntax(stringLiteral: "Copyable")
)
)
)

enum Whatever: Int, ~ Hashable, Equatable {}
assertParse(
"""
enum Whatever: Int, ~ Hashable, Equatable {}
""",
substructure:
Syntax(
TypeInheritanceClauseSyntax(
colon: .colonToken(),
inheritedTypeCollection: InheritedTypeListSyntax([
InheritedTypeSyntax(
typeName: TypeSyntax(stringLiteral: "Int"),
trailingComma: .commaToken()
),
InheritedTypeSyntax(
withoutTilde: .prefixOperator("~"),
typeName: TypeSyntax(stringLiteral: "Hashable"),
trailingComma: .commaToken()
),
InheritedTypeSyntax(typeName: TypeSyntax(stringLiteral: "Equatable")),
])
)
)
)
}
}
Expand Down