Skip to content

Bumping to SwiftSyntax 600.0.1 #56

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 2 commits into from
Oct 20, 2024
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 .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
os: [macos-13]
swift: ["5.9", "5.8", "5.7"]
swift: ["5.9", "5.8"]
runs-on: ${{ matrix.os }}
steps:
- uses: swift-actions/setup-swift@v1
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "510.0.1"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.1"),
],
targets: [
.target(
Expand Down
48 changes: 0 additions & 48 deletions Package@swift-5.7.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Package@swift-5.8.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "510.0.1"),
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.1"),
],
targets: [
.target(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SyntaxChildren+InOut.swift
//
//
// Created by Michael O'Brien on 20/10/2024.
//

import SwiftSyntax

extension SyntaxChildren {

/// Will assess the children in the current collection and search for inout token kinds with a shallow strategy.
/// Shallow referring to the child being a direct `TokenSyntax` type or a `TypeSpecifierListSyntax` containing a
/// child that is a `SimpleTypeSpecifierSyntax` whose token kind is an `inout`
/// - Returns: `Bool`
func resolveIsInOut() -> Bool {
contains(where: {
// Ignoring experimental `LifetimeTypeSpecifierSyntax` type for now.
if let specifierListType = $0.as(TypeSpecifierListSyntax.self) {
let nodes = specifierListType.compactMap { $0.as(SimpleTypeSpecifierSyntax.self) }
let tokens = nodes.flatMap { $0.tokens(viewMode: .fixedUp) }
return tokens.contains(where: { $0.tokenKind == TokenKind.keyword(.inout) })
}
// returning expected syntax type (if valid)
return $0.as(TokenSyntax.self)?.tokenKind == TokenKind.keyword(.inout)
})
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ struct FunctionSemanticsResolver: SemanticsResolving {
node.funcKeyword.text.trimmed
}

func resolveKeywordIsPresent() -> Bool {
node.funcKeyword.presence == .present
}

func resolveModifiers() -> [Modifier] {
node.modifiers.map { Modifier(node: $0) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct InitializerSemanticsResolver: SemanticsResolving {
}

func resolveThrowsOrRethrowsKeyword() -> String? {
node.signature.effectSpecifiers?.throwsSpecifier?.text.trimmed
node.signature.effectSpecifiers?.throwsClause?.throwsSpecifier.text.trimmed
}

func resolveEffectSpecifiers() -> EffectSpecifiers? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ struct EnumCaseParameterSemanticsResolver: ParameterNodeSemanticsResolving {
}

func resolveIsInOut() -> Bool {
let tokens = node.type.children(viewMode: .fixedUp).compactMap { $0.as(TokenSyntax.self) }
return tokens.contains(where: { $0.tokenKind == TokenKind.keyword(.inout) })
node.type.children(viewMode: .fixedUp).resolveIsInOut()
}

func resolveDescription() -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ struct FunctionParameterSemanticsResolver: ParameterNodeSemanticsResolving {
}

func resolveIsInOut() -> Bool {
let tokens = node.type.children(viewMode: .fixedUp).compactMap { $0.as(TokenSyntax.self) }
return tokens.contains(where: { $0.tokenKind == TokenKind.keyword(.inout) })
node.type.children(viewMode: .fixedUp).resolveIsInOut()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ struct TupleParameterSemanticsResolver: ParameterNodeSemanticsResolving {
guard let attributedType = node.children(viewMode: .fixedUp).first?.as(AttributedTypeSyntax.self) else {
return false
}
let tokens = attributedType.children(viewMode: .fixedUp).compactMap { $0.as(TokenSyntax.self) }
return tokens.contains(where: { $0.tokenKind == TokenKind.keyword(.inout) })
return attributedType.children(viewMode: .fixedUp).resolveIsInOut()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public protocol SyntaxChildCollecting {
/// The collected ``Variable`` declarations.
var variables: [Variable] { get }

/// The collected switch expression declarations.
// var switches: [SwitchExpression] { get }

/// Will reset the collected child instances and re-assess the represented node to collect any supported child declarations.
/// - Parameter viewMode: The view mode to use when parsing.
func collectChildren(viewMode: SyntaxTreeViewMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public struct EffectSpecifiers: Hashable, Equatable, CustomStringConvertible {
/// Creates a new ``SyntaxSparrow/EffectSpecifiers`` instance from an `AccessorEffectSpecifiersSyntax` node.
public init(node: AccessorEffectSpecifiersSyntax) {
self.node = node
throwsSpecifier = node.throwsSpecifier?.text.trimmed
throwsSpecifier = node.throwsClause?.throwsSpecifier.text.trimmed
asyncSpecifier = node.asyncSpecifier?.text.trimmed
}

/// Creates a new ``SyntaxSparrow/EffectSpecifiers`` instance from an `TypeEffectSpecifiersSyntax` node.
public init(node: TypeEffectSpecifiersSyntax) {
self.node = node
throwsSpecifier = node.throwsSpecifier?.text.trimmed
throwsSpecifier = node.throwsClause?.throwsSpecifier.text.trimmed
asyncSpecifier = node.asyncSpecifier?.text.trimmed
}

/// Creates a new ``SyntaxSparrow/EffectSpecifiers`` instance from an `FunctionEffectSpecifiersSyntax` node.
public init(node: FunctionEffectSpecifiersSyntax) {
self.node = node
throwsSpecifier = node.throwsSpecifier?.text.trimmed
throwsSpecifier = node.throwsClause?.throwsSpecifier.text.trimmed
asyncSpecifier = node.asyncSpecifier?.text.trimmed
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public struct Function: Declaration, SyntaxChildCollecting {
/// i.e: `"func"` for function declarations.
public var keyword: String { resolver.resolveKeyword() }

/// Will return `false` when the `SourcePresence` type for the underlying node's function keyword is `missing`.
/// This is for scenarios where a function type is recognized, but is not an inherent declaration
public var isKeywordPresent: Bool { resolver.resolveKeywordIsPresent() }

/// The function identifier (similar to name).
///
/// For example, in the following declaration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,18 @@ final class SyntaxChildCollectingConvenienceTests: XCTestCase {
XCTAssertEqual(aliases.map(\.name), [
"NestedTypeAliasOne", "NestedTypeAliasTwo", "NestedTypeAliasThree", "NestedTypeAliasFour", "NestedTypeAliasFive", "NestedTypeAliasSix"
])
// Functions
let functions = instanceUnderTest.recursivelyCollectDeclarations(of: Function.self)
XCTAssertEqual(functions.count, 6)
// Functions (explicitly ignoring print as they are function closure types
let functions = instanceUnderTest.recursivelyCollectDeclarations(of: Function.self).filter { $0.keyword == "func" }
XCTAssertEqual(functions.count, 8)
XCTAssertEqual(functions.map(\.identifier), [
"executeOrder66", "executeOrder66Two", "nestedFunctionOne", "executeOrder66Three", "nestedFunctionTwo", "nestedFunctionThree"
"executeOrder66", "executeOrder66Two", "nestedFunctionOne", "executeOrder66Three", "nestedFunctionTwo", "nestedFunctionThree", "print", "print"
])
for i in 0..<5 {
XCTAssertTrue(functions[i].isKeywordPresent)
}
XCTAssertFalse(functions[6].isKeywordPresent)
XCTAssertFalse(functions[7].isKeywordPresent)

// Structs
let structures = instanceUnderTest.recursivelyCollectDeclarations(of: Structure.self)
XCTAssertEqual(structures.count, 3)
Expand Down
Loading