diff --git a/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift b/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift index 42c60d2a65a..fb56944b477 100644 --- a/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift +++ b/CodeGeneration/Sources/generate-swiftsyntax/GenerateSwiftSyntax.swift @@ -106,7 +106,7 @@ struct GenerateSwiftSyntax: ParsableCommand { GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxVisitor.swift"], syntaxVisitorFile), GeneratedFileSpec(swiftSyntaxGeneratedDir + ["TokenKind.swift"], tokenKindFile), GeneratedFileSpec(swiftSyntaxGeneratedDir + ["Tokens.swift"], tokensFile), - GeneratedFileSpec(swiftSyntaxGeneratedDir + ["Trivia.swift"], triviaFile), + GeneratedFileSpec(swiftSyntaxGeneratedDir + ["TriviaPieces.swift"], triviaPiecesFile), // SwiftSyntaxBuilder GeneratedFileSpec(swiftSyntaxBuilderGeneratedDir + ["BuildableCollectionNodes.swift"], buildableCollectionNodesFile), diff --git a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaFile.swift b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaPiecesFile.swift similarity index 62% rename from CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaFile.swift rename to CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaPiecesFile.swift index 378c414afd3..355a54563a7 100644 --- a/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaFile.swift +++ b/CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaPiecesFile.swift @@ -15,16 +15,7 @@ import SwiftSyntaxBuilder import SyntaxSupport import Utils -let triviaFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { - DeclSyntax( - """ - public enum TriviaPosition { - case leading - case trailing - } - """ - ) - +let triviaPiecesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { try! EnumDeclSyntax( """ /// A contiguous stretch of a single kind of trivia. The constituent part of @@ -115,88 +106,11 @@ let triviaFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { } } - DeclSyntax( - """ - extension TriviaPiece { - /// Returns true if the trivia is `.newlines`, `.carriageReturns` or `.carriageReturnLineFeeds` - public var isNewline: Bool { - switch self { - case .newlines, - .carriageReturns, - .carriageReturnLineFeeds: - return true - default: - return false - } - } - } - """ - ) - - try! StructDeclSyntax( + try! ExtensionDeclSyntax( """ - /// A collection of leading or trailing trivia. This is the main data structure - /// for thinking about trivia. - public struct Trivia + extension Trivia """ ) { - DeclSyntax("public let pieces: [TriviaPiece]") - - DeclSyntax( - """ - /// Creates Trivia with the provided underlying pieces. - public init(pieces: S) where S.Element == TriviaPiece { - self.pieces = Array(pieces) - } - """ - ) - - DeclSyntax( - """ - /// Creates Trivia with no pieces. - public static var zero: Trivia { - return Trivia(pieces: []) - } - """ - ) - - DeclSyntax( - """ - /// Whether the Trivia contains no pieces. - public var isEmpty: Bool { - pieces.isEmpty - } - """ - ) - - DeclSyntax( - """ - /// Creates a new `Trivia` by appending the provided `TriviaPiece` to the end. - public func appending(_ piece: TriviaPiece) -> Trivia { - var copy = pieces - copy.append(piece) - return Trivia(pieces: copy) - } - """ - ) - - DeclSyntax( - """ - public var sourceLength: SourceLength { - return pieces.map({ $0.sourceLength }).reduce(.zero, +) - } - """ - ) - - DeclSyntax( - """ - /// Get the byteSize of this trivia - public var byteSize: Int { - return sourceLength.utf8Length - } - """ - ) - for trivia in TRIVIAS { if trivia.isCollection { let joined = trivia.characters.map { "\($0)" }.joined() @@ -231,99 +145,6 @@ let triviaFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { } } - DeclSyntax( - #""" - extension Trivia: CustomDebugStringConvertible { - public var debugDescription: String { - if count == 1, let first = first { - return first.debugDescription - } - return "[" + map(\.debugDescription).joined(separator: ", ") + "]" - } - } - """# - ) - - DeclSyntax("extension Trivia: Equatable {}") - - DeclSyntax( - """ - /// Conformance for Trivia to the Collection protocol. - extension Trivia: Collection { - public var startIndex: Int { - return pieces.startIndex - } - - public var endIndex: Int { - return pieces.endIndex - } - - public func index(after i: Int) -> Int { - return pieces.index(after: i) - } - - public subscript(_ index: Int) -> TriviaPiece { - return pieces[index] - } - } - """ - ) - - DeclSyntax( - """ - extension Trivia: ExpressibleByArrayLiteral { - /// Creates Trivia from the provided pieces. - public init(arrayLiteral elements: TriviaPiece...) { - self.pieces = elements - } - } - """ - ) - - DeclSyntax( - """ - extension Trivia: TextOutputStreamable { - /// Prints the provided trivia as they would be written in a source file. - /// - /// - Parameter stream: The stream to which to print the trivia. - public func write(to target: inout Target) - where Target: TextOutputStream { - for piece in pieces { - piece.write(to: &target) - } - } - } - """ - ) - - DeclSyntax( - """ - extension Trivia: CustomStringConvertible { - public var description: String { - var description = "" - self.write(to: &description) - return description - } - } - """ - ) - - DeclSyntax( - """ - extension Trivia { - /// Concatenates two collections of `Trivia` into one collection. - public static func +(lhs: Trivia, rhs: Trivia) -> Trivia { - return Trivia(pieces: lhs.pieces + rhs.pieces) - } - - /// Concatenates two collections of `Trivia` into the left-hand side. - public static func +=(lhs: inout Trivia, rhs: Trivia) { - lhs = lhs + rhs - } - } - """ - ) - DeclSyntax("extension TriviaPiece: Equatable {}") try! ExtensionDeclSyntax("extension TriviaPiece") { @@ -388,26 +209,6 @@ let triviaFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { } } - DeclSyntax( - """ - extension RawTriviaPiece: TextOutputStreamable { - public func write(to target: inout Target) { - TriviaPiece(raw: self).write(to: &target) - } - } - """ - ) - - DeclSyntax( - """ - extension RawTriviaPiece: CustomDebugStringConvertible { - public var debugDescription: String { - TriviaPiece(raw: self).debugDescription - } - } - """ - ) - try! ExtensionDeclSyntax("extension TriviaPiece") { try InitializerDeclSyntax("@_spi(RawSyntax) public init(raw: RawTriviaPiece)") { try SwitchExprSyntax("switch raw") { @@ -463,22 +264,4 @@ let triviaFile = SourceFileSyntax(leadingTrivia: copyrightHeader) { } } } - - DeclSyntax( - """ - extension RawTriviaPiece { - /// Returns true if the trivia is `.newlines`, `.carriageReturns` or `.carriageReturnLineFeeds` - public var isNewline: Bool { - switch self { - case .newlines, - .carriageReturns, - .carriageReturnLineFeeds: - return true - default: - return false - } - } - } - """ - ) } diff --git a/Sources/SwiftParserDiagnostics/DiagnosticExtensions.swift b/Sources/SwiftParserDiagnostics/DiagnosticExtensions.swift index 9d3d0b58f3e..97f3a118172 100644 --- a/Sources/SwiftParserDiagnostics/DiagnosticExtensions.swift +++ b/Sources/SwiftParserDiagnostics/DiagnosticExtensions.swift @@ -142,9 +142,9 @@ extension FixIt.Changes { /// where it makes sense and refusing to add e.g. a space after punctuation, /// where it usually doesn't make sense. static func transferTriviaAtSides(from nodes: [SyntaxType]) -> Self { - let removedTriviaAtSides = Trivia.merged(nodes.first?.leadingTrivia ?? [], nodes.last?.trailingTrivia ?? []) + let removedTriviaAtSides = (nodes.first?.leadingTrivia ?? []).merging(nodes.last?.trailingTrivia ?? []) if !removedTriviaAtSides.isEmpty, let previousToken = nodes.first?.previousToken(viewMode: .sourceAccurate) { - let mergedTrivia = Trivia.merged(previousToken.trailingTrivia, removedTriviaAtSides) + let mergedTrivia = previousToken.trailingTrivia.merging(removedTriviaAtSides) if previousToken.tokenKind.isPunctuation, mergedTrivia.allSatisfy({ $0.isSpaceOrTab }) { // Punctuation is generally not followed by spaces in Swift. // If this action would only add spaces to the punctuation, drop it. @@ -158,49 +158,6 @@ extension FixIt.Changes { } } -extension Trivia { - /// Decomposes the trivia into pieces that all have count 1 - var decomposed: Trivia { - let pieces = self.flatMap({ (piece: TriviaPiece) -> [TriviaPiece] in - switch piece { - case .spaces(let count): - return Array(repeating: TriviaPiece.spaces(1), count: count) - case .tabs(let count): - return Array(repeating: TriviaPiece.tabs(1), count: count) - case .verticalTabs(let count): - return Array(repeating: TriviaPiece.verticalTabs(1), count: count) - case .formfeeds(let count): - return Array(repeating: TriviaPiece.formfeeds(1), count: count) - case .newlines(let count): - return Array(repeating: TriviaPiece.newlines(1), count: count) - case .backslashes(let count): - return Array(repeating: TriviaPiece.backslashes(1), count: count) - case .pounds(let count): - return Array(repeating: TriviaPiece.pounds(1), count: count) - case .carriageReturns(let count): - return Array(repeating: TriviaPiece.carriageReturns(1), count: count) - case .carriageReturnLineFeeds(let count): - return Array(repeating: TriviaPiece.carriageReturnLineFeeds(1), count: count) - case .lineComment, .blockComment, .docLineComment, .docBlockComment, .unexpectedText, .shebang: - return [piece] - } - }) - return Trivia(pieces: pieces) - } - - /// Concatenate `lhs` and `rhs`, merging an infix that is shared between both trivia pieces. - static func merged(_ lhs: Trivia, _ rhs: Trivia) -> Self { - let lhs = lhs.decomposed - let rhs = rhs.decomposed - for infixLength in (0...Swift.min(lhs.count, rhs.count)).reversed() { - if lhs.suffix(infixLength) == rhs.suffix(infixLength) { - return lhs + Trivia(pieces: Array(rhs.dropFirst(infixLength))) - } - } - return lhs + rhs - } -} - extension TriviaPiece { var isSpaceOrTab: Bool { switch self { diff --git a/Sources/SwiftParserDiagnostics/MultiLineStringLiteralDiagnosticsGenerator.swift b/Sources/SwiftParserDiagnostics/MultiLineStringLiteralDiagnosticsGenerator.swift index b7dfcf42dee..4cd3f2368f3 100644 --- a/Sources/SwiftParserDiagnostics/MultiLineStringLiteralDiagnosticsGenerator.swift +++ b/Sources/SwiftParserDiagnostics/MultiLineStringLiteralDiagnosticsGenerator.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// import SwiftDiagnostics -import SwiftSyntax +@_spi(RawSyntax) import SwiftSyntax /// A diagnostic that `MultiLineStringLiteralIndentatinDiagnosticsGenerator` is building. /// As indentation errors are found on more lines, this diagnostic is modified diff --git a/Sources/SwiftSyntax/CMakeLists.txt b/Sources/SwiftSyntax/CMakeLists.txt index 0428a718549..394a31593f9 100644 --- a/Sources/SwiftSyntax/CMakeLists.txt +++ b/Sources/SwiftSyntax/CMakeLists.txt @@ -12,6 +12,7 @@ add_swift_host_library(SwiftSyntax BumpPtrAllocator.swift CommonAncestor.swift IncrementalParseTransition.swift + Trivia.swift SourceLength.swift SourceLocation.swift SourcePresence.swift @@ -46,7 +47,7 @@ add_swift_host_library(SwiftSyntax generated/SyntaxVisitor.swift generated/TokenKind.swift generated/Tokens.swift - generated/Trivia.swift + generated/TriviaPieces.swift generated/syntaxNodes/SyntaxDeclNodes.swift generated/syntaxNodes/SyntaxExprNodes.swift diff --git a/Sources/SwiftSyntax/Trivia.swift b/Sources/SwiftSyntax/Trivia.swift new file mode 100644 index 00000000000..a2b0e0a42a2 --- /dev/null +++ b/Sources/SwiftSyntax/Trivia.swift @@ -0,0 +1,213 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public enum TriviaPosition { + case leading + case trailing +} + +/// A collection of leading or trailing trivia. This is the main data structure +/// for thinking about trivia. +public struct Trivia { + public let pieces: [TriviaPiece] + + /// Creates Trivia with the provided underlying pieces. + public init(pieces: S) where S.Element == TriviaPiece { + self.pieces = Array(pieces) + } + + /// Whether the Trivia contains no pieces. + public var isEmpty: Bool { + pieces.isEmpty + } + + public var sourceLength: SourceLength { + return pieces.map({ $0.sourceLength }).reduce(.zero, +) + } + + /// Get the byteSize of this trivia + public var byteSize: Int { + return sourceLength.utf8Length + } + + /// Creates a new `Trivia` by appending the provided `TriviaPiece` to the end. + public func appending(_ piece: TriviaPiece) -> Trivia { + var copy = pieces + copy.append(piece) + return Trivia(pieces: copy) + } + + /// Creates a new `Trivia` by appending the given trivia to the end. + public func appending(_ trivia: Trivia) -> Trivia { + var copy = pieces + copy.append(contentsOf: trivia.pieces) + return Trivia(pieces: copy) + } + + /// Creates a new `Trivia` by merging in the given trivia. Only includes one + /// copy of a common prefix of `self` and `trivia`. + public func merging(_ trivia: Trivia) -> Trivia { + let lhs = self.decomposed + let rhs = trivia.decomposed + for infixLength in (0...Swift.min(lhs.count, rhs.count)).reversed() { + if lhs.suffix(infixLength) == rhs.suffix(infixLength) { + return lhs.appending(Trivia(pieces: Array(rhs.dropFirst(infixLength)))) + } + } + return lhs.appending(rhs) + } + + /// Creates a new `Trivia` by merging the leading and trailing `Trivia` + /// of `triviaOf` into the end of `self`. Only includes one copy of any + /// common prefixes. + public func merging(triviaOf node: T) -> Trivia { + return merging(node.leadingTrivia).merging(node.trailingTrivia) + } + + /// Concatenates two collections of `Trivia` into one collection. + public static func + (lhs: Trivia, rhs: Trivia) -> Trivia { + return lhs.appending(rhs) + } + + /// Concatenates two collections of `Trivia` into the left-hand side. + public static func += (lhs: inout Trivia, rhs: Trivia) { + lhs = lhs.appending(rhs) + } +} + +extension Trivia: Equatable {} + +extension Trivia: Collection { + public var startIndex: Int { + return pieces.startIndex + } + + public var endIndex: Int { + return pieces.endIndex + } + + public func index(after i: Int) -> Int { + return pieces.index(after: i) + } + + public subscript(_ index: Int) -> TriviaPiece { + return pieces[index] + } +} + +extension Trivia: ExpressibleByArrayLiteral { + /// Creates Trivia from the provided pieces. + public init(arrayLiteral elements: TriviaPiece...) { + self.pieces = elements + } +} + +extension Trivia: TextOutputStreamable { + /// Prints the provided trivia as they would be written in a source file. + /// + /// - Parameter stream: The stream to which to print the trivia. + public func write(to target: inout Target) + where Target: TextOutputStream { + for piece in pieces { + piece.write(to: &target) + } + } +} + +extension Trivia: CustomStringConvertible { + public var description: String { + var description = "" + self.write(to: &description) + return description + } +} + +extension Trivia: CustomDebugStringConvertible { + public var debugDescription: String { + if count == 1, let first = first { + return first.debugDescription + } + return "[" + map(\.debugDescription).joined(separator: ", ") + "]" + } +} + +extension Trivia { + /// Decomposes the trivia into pieces that all have count 1 + @_spi(RawSyntax) + public var decomposed: Trivia { + let pieces = self.flatMap({ (piece: TriviaPiece) -> [TriviaPiece] in + switch piece { + case .spaces(let count): + return Array(repeating: TriviaPiece.spaces(1), count: count) + case .tabs(let count): + return Array(repeating: TriviaPiece.tabs(1), count: count) + case .verticalTabs(let count): + return Array(repeating: TriviaPiece.verticalTabs(1), count: count) + case .formfeeds(let count): + return Array(repeating: TriviaPiece.formfeeds(1), count: count) + case .newlines(let count): + return Array(repeating: TriviaPiece.newlines(1), count: count) + case .backslashes(let count): + return Array(repeating: TriviaPiece.backslashes(1), count: count) + case .pounds(let count): + return Array(repeating: TriviaPiece.pounds(1), count: count) + case .carriageReturns(let count): + return Array(repeating: TriviaPiece.carriageReturns(1), count: count) + case .carriageReturnLineFeeds(let count): + return Array(repeating: TriviaPiece.carriageReturnLineFeeds(1), count: count) + case .lineComment, .blockComment, .docLineComment, .docBlockComment, .unexpectedText, .shebang: + return [piece] + } + }) + return Trivia(pieces: pieces) + } +} + +extension TriviaPiece { + /// Returns true if the trivia is `.newlines`, `.carriageReturns` or `.carriageReturnLineFeeds` + public var isNewline: Bool { + switch self { + case .newlines, + .carriageReturns, + .carriageReturnLineFeeds: + return true + default: + return false + } + } +} + +extension RawTriviaPiece { + /// Returns true if the trivia is `.newlines`, `.carriageReturns` or `.carriageReturnLineFeeds` + public var isNewline: Bool { + switch self { + case .newlines, + .carriageReturns, + .carriageReturnLineFeeds: + return true + default: + return false + } + } +} + +extension RawTriviaPiece: TextOutputStreamable { + public func write(to target: inout Target) { + TriviaPiece(raw: self).write(to: &target) + } +} + +extension RawTriviaPiece: CustomDebugStringConvertible { + public var debugDescription: String { + TriviaPiece(raw: self).debugDescription + } +} diff --git a/Sources/SwiftSyntax/generated/Trivia.swift b/Sources/SwiftSyntax/generated/TriviaPieces.swift similarity index 79% rename from Sources/SwiftSyntax/generated/Trivia.swift rename to Sources/SwiftSyntax/generated/TriviaPieces.swift index 304e4496141..8a9925e4925 100644 --- a/Sources/SwiftSyntax/generated/Trivia.swift +++ b/Sources/SwiftSyntax/generated/TriviaPieces.swift @@ -12,11 +12,6 @@ // //===----------------------------------------------------------------------===// -public enum TriviaPosition { - case leading - case trailing -} - /// A contiguous stretch of a single kind of trivia. The constituent part of /// a `Trivia` collection. /// @@ -141,53 +136,7 @@ extension TriviaPiece: CustomDebugStringConvertible { } } -extension TriviaPiece { - /// Returns true if the trivia is `.newlines`, `.carriageReturns` or `.carriageReturnLineFeeds` - public var isNewline: Bool { - switch self { - case .newlines, - .carriageReturns, - .carriageReturnLineFeeds: - return true - default: - return false - } - } -} - -/// A collection of leading or trailing trivia. This is the main data structure -/// for thinking about trivia. -public struct Trivia { - public let pieces: [TriviaPiece] - - /// Creates Trivia with the provided underlying pieces. - public init(pieces: S) where S.Element == TriviaPiece { - self.pieces = Array(pieces) - } - - /// Whether the Trivia contains no pieces. - public var isEmpty: Bool { - pieces.isEmpty - } - - /// Creates a new `Trivia` by appending the provided `TriviaPiece` to the end. - public func appending(_ piece: TriviaPiece) -> Trivia { - var copy = pieces - copy.append(piece) - return Trivia(pieces: copy) - } - - public var sourceLength: SourceLength { - return pieces.map({ - $0.sourceLength - }).reduce(.zero, + ) - } - - /// Get the byteSize of this trivia - public var byteSize: Int { - return sourceLength.utf8Length - } - +extension Trivia { /// Returns a piece of trivia for some number of #"\"# characters. public static func backslashes(_ count: Int) -> Trivia { return [.backslashes(count)] @@ -309,79 +258,6 @@ public struct Trivia { } } -extension Trivia: CustomDebugStringConvertible { - public var debugDescription: String { - if count == 1, let first = first { - return first.debugDescription - } - return "[" + map(\.debugDescription).joined(separator: ", ") + "]" - } -} - -extension Trivia: Equatable {} - -/// Conformance for Trivia to the Collection protocol. -extension Trivia: Collection { - public var startIndex: Int { - return pieces.startIndex - } - - - public var endIndex: Int { - return pieces.endIndex - } - - - public func index(after i: Int) -> Int { - return pieces.index(after: i) - } - - - public subscript (_ index: Int) -> TriviaPiece { - return pieces[index] - } -} - -extension Trivia: ExpressibleByArrayLiteral { - /// Creates Trivia from the provided pieces. - public init(arrayLiteral elements: TriviaPiece...) { - self.pieces = elements - } -} - -extension Trivia: TextOutputStreamable { - /// Prints the provided trivia as they would be written in a source file. - /// - /// - Parameter stream: The stream to which to print the trivia. - public func write(to target: inout Target) - where Target: TextOutputStream { - for piece in pieces { - piece.write(to: &target) - } - } -} - -extension Trivia: CustomStringConvertible { - public var description: String { - var description = "" - self.write(to: &description) - return description - } -} - -extension Trivia { - /// Concatenates two collections of `Trivia` into one collection. - public static func + (lhs: Trivia, rhs: Trivia) -> Trivia { - return Trivia(pieces: lhs.pieces + rhs.pieces) - } - - - /// Concatenates two collections of `Trivia` into the left-hand side. - public static func += (lhs: inout Trivia, rhs: Trivia) { - lhs = lhs + rhs - } -} - extension TriviaPiece: Equatable {} extension TriviaPiece { @@ -479,18 +355,6 @@ public enum RawTriviaPiece: Equatable { } } -extension RawTriviaPiece: TextOutputStreamable { - public func write(to target: inout Target) { - TriviaPiece(raw: self).write(to: &target) - } -} - -extension RawTriviaPiece: CustomDebugStringConvertible { - public var debugDescription: String { - TriviaPiece(raw: self).debugDescription - } -} - extension TriviaPiece { @_spi(RawSyntax) public init(raw: RawTriviaPiece) { switch raw { @@ -599,17 +463,3 @@ extension RawTriviaPiece { } } } - -extension RawTriviaPiece { - /// Returns true if the trivia is `.newlines`, `.carriageReturns` or `.carriageReturnLineFeeds` - public var isNewline: Bool { - switch self { - case .newlines, - .carriageReturns, - .carriageReturnLineFeeds: - return true - default: - return false - } - } -} diff --git a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift index f0e336ccb8e..fec2e780aa6 100644 --- a/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift +++ b/Sources/SwiftSyntax/generated/raw/RawSyntaxValidation.swift @@ -227,7 +227,12 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .accessPathComponent: assert(layout.count == 5) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.identifier)])) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [ + .tokenKind(.identifier), + .tokenKind(.binaryOperator), + .tokenKind(.prefixOperator), + .tokenKind(.postfixOperator) + ])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.period)])) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) @@ -830,7 +835,13 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .declName: assert(layout.count == 5) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.identifier), .tokenKind(.prefixOperator), .keyword("init")])) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [ + .tokenKind(.identifier), + .tokenKind(.binaryOperator), + .keyword("init"), + .keyword("self"), + .keyword("Self") + ])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawDeclNameArgumentsSyntax?.self)) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) @@ -951,7 +962,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .differentiableAttributeArguments: assert(layout.count == 11) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax?.self, tokenChoices: [.keyword("forward"), .keyword("reverse"), .keyword("linear")])) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax?.self, tokenChoices: [.keyword("_forward"), .keyword("reverse"), .keyword("_linear")])) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.comma)])) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) @@ -1547,14 +1558,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .labeledSpecializeEntry: assert(layout.count == 9) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [ - .tokenKind(.identifier), - .keyword("available"), - .keyword("exported"), - .keyword("kind"), - .keyword("spi"), - .keyword("spiModule") - ])) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self)) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.colon)])) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) @@ -1778,7 +1782,7 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { case .objCSelectorPiece: assert(layout.count == 5) assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self)) - assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.identifier)])) + assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax?.self)) assertNoError(kind, 2, verify(layout[2], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 3, verify(layout[3], as: RawTokenSyntax?.self, tokenChoices: [.tokenKind(.colon)])) assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) @@ -2069,9 +2073,10 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) { assertNoError(kind, 4, verify(layout[4], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 5, verify(layout[5], as: RawTokenSyntax.self, tokenChoices: [ .tokenKind(.identifier), - .tokenKind(.binaryOperator), - .tokenKind(.prefixOperator), - .tokenKind(.postfixOperator) + .keyword("self"), + .keyword("Self"), + .keyword("init"), + .tokenKind(.binaryOperator) ])) assertNoError(kind, 6, verify(layout[6], as: RawUnexpectedNodesSyntax?.self)) assertNoError(kind, 7, verify(layout[7], as: RawDeclNameArgumentsSyntax?.self)) diff --git a/utils/group.json b/utils/group.json index 46687e23de2..40f539a8c18 100644 --- a/utils/group.json +++ b/utils/group.json @@ -18,6 +18,7 @@ "TokenKind.swift", "SyntaxTreeViewMode.swift", "Trivia.swift", + "TriviaPieces.swift", "Tokens.swift", ], "Syntax nodes": [