Skip to content

Add infrastructure for automated validation of syntax node structure #1748

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
Jun 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
6 changes: 6 additions & 0 deletions CodeGeneration/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ let package = Package(
"SyntaxSupport",
]
),
.testTarget(
name: "ValidateSyntaxNodes",
dependencies: [
"SyntaxSupport"
]
),
]
)

Expand Down
2 changes: 1 addition & 1 deletion CodeGeneration/Sources/SyntaxSupport/Child.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/// The kind of token a node can contain. Either a token of a specific kind or a
/// keyword with the given text.
public enum TokenChoice {
public enum TokenChoice: Equatable {
case keyword(text: String)
case token(tokenKind: String)

Expand Down
32 changes: 32 additions & 0 deletions CodeGeneration/Tests/ValidateSyntaxNodes/Utils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

extension Collection {
/// If the collection contains a single element, return it, otherwise `nil`.
var only: Element? {
if !isEmpty && index(after: startIndex) == endIndex {
return self.first!
} else {
return nil
}
}
}

extension String {
func dropSuffix(_ suffix: String) -> String {
if hasSuffix(suffix) {
return String(self.dropLast(suffix.count))
} else {
return self
}
}
}
Loading