diff --git a/.periphery.yml b/.periphery.yml new file mode 100644 index 0000000..85b884a --- /dev/null +++ b/.periphery.yml @@ -0,0 +1 @@ +retain_public: true diff --git a/Package.swift b/Package.swift index 1eac097..42c9345 100644 --- a/Package.swift +++ b/Package.swift @@ -4,46 +4,43 @@ import PackageDescription let package = Package( - name: "SyntaxKit", - platforms: [ - .macOS(.v13), - .iOS(.v13), - .watchOS(.v6), - .tvOS(.v13), - .visionOS(.v1) - ], - products: [ - // Products define the executables and libraries a package produces, making them visible to other packages. - .library( - name: "SyntaxKit", - targets: ["SyntaxKit"] - ), - .executable( - name: "skit", - targets: ["skit"] - ), - ], - dependencies: [ - .package(url: "https://github.com/apple/swift-syntax.git", from: "601.0.1") - ], - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - .target( - name: "SyntaxKit", - dependencies: [ - .product(name: "SwiftSyntax", package: "swift-syntax"), - .product(name: "SwiftOperators", package: "swift-syntax"), - .product(name: "SwiftParser", package: "swift-syntax") - ] - ), - .executableTarget( - name: "skit", - dependencies: ["SyntaxKit"] - ), - .testTarget( - name: "SyntaxKitTests", - dependencies: ["SyntaxKit"] - ), - ] + name: "SyntaxKit", + platforms: [ + .macOS(.v13), + .iOS(.v13), + .watchOS(.v6), + .tvOS(.v13), + .visionOS(.v1) + ], + products: [ + .library( + name: "SyntaxKit", + targets: ["SyntaxKit"] + ), + .executable( + name: "skit", + targets: ["skit"] + ), + ], + dependencies: [ + .package(url: "https://github.com/apple/swift-syntax.git", from: "601.0.1") + ], + targets: [ + .target( + name: "SyntaxKit", + dependencies: [ + .product(name: "SwiftSyntax", package: "swift-syntax"), + .product(name: "SwiftOperators", package: "swift-syntax"), + .product(name: "SwiftParser", package: "swift-syntax") + ] + ), + .executableTarget( + name: "skit", + dependencies: ["SyntaxKit"] + ), + .testTarget( + name: "SyntaxKitTests", + dependencies: ["SyntaxKit"] + ), + ] ) diff --git a/Scripts/lint.sh b/Scripts/lint.sh index 533a00a..e0e82f6 100755 --- a/Scripts/lint.sh +++ b/Scripts/lint.sh @@ -75,6 +75,8 @@ $PACKAGE_DIR/Scripts/header.sh -d $PACKAGE_DIR/Sources -c "Leo Dion" -o "Bright run_command $MINT_RUN swiftlint lint $SWIFTLINT_OPTIONS run_command $MINT_RUN swift-format lint --recursive --parallel $SWIFTFORMAT_OPTIONS Sources Tests -#$MINT_RUN periphery scan $PERIPHERY_OPTIONS --disable-update-check +if [ -z "$CI" ]; then + run_command $MINT_RUN periphery scan $PERIPHERY_OPTIONS --disable-update-check +fi popd diff --git a/Sources/SyntaxKit/CodeBlock.swift b/Sources/SyntaxKit/CodeBlock.swift index 2da3ecc..086e2a1 100644 --- a/Sources/SyntaxKit/CodeBlock.swift +++ b/Sources/SyntaxKit/CodeBlock.swift @@ -46,7 +46,7 @@ public protocol CodeBlockBuilder { /// A result builder for creating arrays of ``CodeBlock``s. @resultBuilder -public struct CodeBlockBuilderResult { +public enum CodeBlockBuilderResult { /// Builds a block of ``CodeBlock``s. public static func buildBlock(_ components: CodeBlock...) -> [CodeBlock] { components diff --git a/Sources/SyntaxKit/ParameterBuilderResult.swift b/Sources/SyntaxKit/ParameterBuilderResult.swift index 3e3bad6..43c641e 100644 --- a/Sources/SyntaxKit/ParameterBuilderResult.swift +++ b/Sources/SyntaxKit/ParameterBuilderResult.swift @@ -31,7 +31,7 @@ import Foundation /// A result builder for creating arrays of ``Parameter``s. @resultBuilder -public struct ParameterBuilderResult { +public enum ParameterBuilderResult { /// Builds a block of ``Parameter``s. public static func buildBlock(_ components: Parameter...) -> [Parameter] { components diff --git a/Sources/SyntaxKit/ParameterExpBuilderResult.swift b/Sources/SyntaxKit/ParameterExpBuilderResult.swift index 4cf937a..ef98f12 100644 --- a/Sources/SyntaxKit/ParameterExpBuilderResult.swift +++ b/Sources/SyntaxKit/ParameterExpBuilderResult.swift @@ -31,7 +31,7 @@ import Foundation /// A result builder for creating arrays of ``ParameterExp``s. @resultBuilder -public struct ParameterExpBuilderResult { +public enum ParameterExpBuilderResult { /// Builds a block of ``ParameterExp``s. public static func buildBlock(_ components: ParameterExp...) -> [ParameterExp] { components diff --git a/Sources/SyntaxKit/parser/SyntaxParser.swift b/Sources/SyntaxKit/parser/SyntaxParser.swift index a58afdb..f4f38e5 100644 --- a/Sources/SyntaxKit/parser/SyntaxParser.swift +++ b/Sources/SyntaxKit/parser/SyntaxParser.swift @@ -32,7 +32,7 @@ import SwiftOperators import SwiftParser import SwiftSyntax -package struct SyntaxParser { +package enum SyntaxParser { package static func parse(code: String, options: [String] = []) throws -> SyntaxResponse { let sourceFile = Parser.parse(source: code) @@ -53,6 +53,6 @@ package struct SyntaxParser { let encoder = JSONEncoder() let json = String(decoding: try encoder.encode(tree), as: UTF8.self) - return SyntaxResponse(syntaxJSON: json, swiftVersion: version) + return SyntaxResponse(syntaxJSON: json) } } diff --git a/Sources/SyntaxKit/parser/SyntaxResponse.swift b/Sources/SyntaxKit/parser/SyntaxResponse.swift index 1774a1a..7dbb636 100644 --- a/Sources/SyntaxKit/parser/SyntaxResponse.swift +++ b/Sources/SyntaxKit/parser/SyntaxResponse.swift @@ -30,7 +30,5 @@ import Foundation package struct SyntaxResponse: Codable { - // package let syntaxHTML: String package let syntaxJSON: String - package let swiftVersion: String } diff --git a/Sources/SyntaxKit/parser/TokenVisitor.swift b/Sources/SyntaxKit/parser/TokenVisitor.swift index 88ab4ed..aad7ca5 100644 --- a/Sources/SyntaxKit/parser/TokenVisitor.swift +++ b/Sources/SyntaxKit/parser/TokenVisitor.swift @@ -97,10 +97,8 @@ final class TokenVisitor: SyntaxRewriter { range: Range( startRow: start.line, startColumn: start.column, - graphemeStartColumn: graphemeStartColumn, endRow: end.line, - endColumn: end.column, - graphemeEndColumn: graphemeEndColumn + endColumn: end.column ), type: syntaxType ) @@ -185,9 +183,7 @@ final class TokenVisitor: SyntaxRewriter { .escapeHTML() .replaceInvisiblesWithHTML() .replaceHTMLWhitespacesWithSymbols() - if token.presence == .missing { - current.class = "\(token.presence)" - } + current.token = Token(kind: "\(token.tokenKind)", leadingTrivia: "", trailingTrivia: "") token.leadingTrivia.forEach { piece in diff --git a/Sources/SyntaxKit/parser/TreeNode.swift b/Sources/SyntaxKit/parser/TreeNode.swift index cb6b808..4c35089 100644 --- a/Sources/SyntaxKit/parser/TreeNode.swift +++ b/Sources/SyntaxKit/parser/TreeNode.swift @@ -35,12 +35,10 @@ final class TreeNode: Codable { var text: String var range = Range( - startRow: 0, startColumn: 0, graphemeStartColumn: 0, endRow: 0, endColumn: 0, - graphemeEndColumn: 0) + startRow: 0, startColumn: 0, endRow: 0, endColumn: 0) var structure = [StructureProperty]() var type: SyntaxType var token: Token? - var `class`: String? init(id: Int, text: String, range: Range, type: SyntaxType) { self.id = id @@ -76,10 +74,8 @@ extension TreeNode: CustomStringConvertible { struct Range: Codable, Equatable { let startRow: Int let startColumn: Int - let graphemeStartColumn: Int let endRow: Int let endColumn: Int - let graphemeEndColumn: Int } extension Range: CustomStringConvertible { diff --git a/Sources/SyntaxKit/parser/Version.swift b/Sources/SyntaxKit/parser/Version.swift deleted file mode 100644 index 3a5f2ac..0000000 --- a/Sources/SyntaxKit/parser/Version.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// Version.swift -// SyntaxKit -// -// Created by Leo Dion. -// Copyright © 2025 BrightDigit. -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the “Software”), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// - -import Foundation - -let version = "6.01.0"