Skip to content

Commit b991ab0

Browse files
Swift 5.8 parser process
1 parent d2ac5f4 commit b991ab0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+583
-504
lines changed

.github/workflows/spm.yml

+4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ jobs:
1919
- name: Update Swift Package
2020
run: |
2121
set -ex
22+
2223
export TOOLCHAINS=swift
24+
2325
swift package update --package-path ./
26+
27+
swift package update --package-path Resources/parsers/50800
2428
swift package update --package-path Resources/parsers/50900
2529
swift package update --package-path Resources/parsers/trunk
2630
- name: Create Pull Request

.github/workflows/test.yml

+3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ jobs:
1515
- name: Test
1616
run: |
1717
set -ex
18+
1819
swift test
20+
21+
(cd Resources/parsers/50800 && swift test)
1922
(cd Resources/parsers/50900 && swift test)
2023
(cd Resources/parsers/trunk && swift test)
2124
- name: Build

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RUN swift package resolve
2727
COPY . .
2828
RUN swift build -c release --static-swift-stdlib
2929

30+
RUN cd Resources/parsers/50800 && swift build -c release -Xswiftc -static-executable
3031
RUN cd Resources/parsers/50900 && swift build -c release -Xswiftc -static-executable
3132
RUN cd Resources/parsers/trunk && swift build -c release -Xswiftc -static-executable
3233

Package.resolved

-9
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,6 @@
180180
"version" : "1.0.2"
181181
}
182182
},
183-
{
184-
"identity" : "swift-syntax",
185-
"kind" : "remoteSourceControl",
186-
"location" : "https://github.com/apple/swift-syntax",
187-
"state" : {
188-
"revision" : "2c49d66d34dfd6f8130afdba889de77504b58ec0",
189-
"version" : "508.0.1"
190-
}
191-
},
192183
{
193184
"identity" : "swift-system",
194185
"kind" : "remoteSourceControl",

Package.swift

+3-8
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,17 @@ let package = Package(
77
.macOS(.v13)
88
],
99
dependencies: [
10-
.package(url: "https://github.com/apple/swift-syntax", from: "508.0.1"),
11-
.package(url: "https://github.com/apple/swift-tools-support-core", from: "0.5.2"),
1210
.package(url: "https://github.com/vapor/vapor.git", from: "4.78.0"),
1311
.package(url: "https://github.com/vapor/leaf.git", from: "4.2.4"),
12+
.package(url: "https://github.com/apple/swift-tools-support-core", from: "0.5.2"),
1413
],
1514
targets: [
1615
.executableTarget(
1716
name: "App",
1817
dependencies: [
19-
.product(name: "SwiftSyntax", package: "swift-syntax"),
20-
.product(name: "SwiftOperators", package: "swift-syntax"),
21-
.product(name: "SwiftParser", package: "swift-syntax"),
22-
.product(name: "TSCBasic", package: "swift-tools-support-core"),
2318
.product(name: "Vapor", package: "vapor"),
2419
.product(name: "Leaf", package: "leaf"),
20+
.product(name: "TSCBasic", package: "swift-tools-support-core"),
2521
],
2622
swiftSettings: [
2723
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
@@ -32,8 +28,7 @@ let package = Package(
3228
dependencies: [
3329
.target(name: "App"),
3430
.product(name: "XCTVapor", package: "vapor"),
35-
],
36-
resources: [.process("Fixtures")]
31+
]
3732
)
3833
]
3934
)

Resources/parsers/50800/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "swift-syntax",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/apple/swift-syntax",
7+
"state" : {
8+
"revision" : "2c49d66d34dfd6f8130afdba889de77504b58ec0",
9+
"version" : "508.0.1"
10+
}
11+
}
12+
],
13+
"version" : 2
14+
}

Resources/parsers/50800/Package.swift

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// swift-tools-version:5.8
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "parser",
6+
platforms: [
7+
.macOS(.v13)
8+
],
9+
dependencies: [
10+
.package(url: "https://github.com/apple/swift-syntax", from: "508.0.1"),
11+
],
12+
targets: [
13+
.executableTarget(
14+
name: "parser",
15+
dependencies: [
16+
.product(name: "SwiftSyntax", package: "swift-syntax"),
17+
.product(name: "SwiftOperators", package: "swift-syntax"),
18+
.product(name: "SwiftParser", package: "swift-syntax"),
19+
],
20+
swiftSettings: [
21+
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
22+
]
23+
),
24+
.testTarget(
25+
name: "Tests",
26+
dependencies: [
27+
.target(name: "parser"),
28+
],
29+
resources: [.process("Fixtures")]
30+
)
31+
]
32+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Foundation
2+
3+
@main
4+
struct Main {
5+
static func main() throws {
6+
do {
7+
let code = String(decoding: FileHandle.standardInput.availableData, as: UTF8.self)
8+
let options = Array(CommandLine.arguments.dropFirst(1))
9+
10+
let response = try SyntaxParser.parse(code: code, options: options)
11+
12+
let data = try JSONEncoder().encode(response)
13+
print(String(decoding: data, as: UTF8.self))
14+
} catch {
15+
var standardError = FileHandle.standardError
16+
print("\(error)", to:&standardError)
17+
}
18+
}
19+
}
20+
21+
extension FileHandle : TextOutputStream {
22+
public func write(_ string: String) {
23+
self.write(Data(string.utf8))
24+
}
25+
}

Sources/App/Controllers/SyntaxParser.swift Resources/parsers/50800/Sources/parser/SyntaxParser.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SwiftParser
66
struct SyntaxParser {
77
static func parse(code: String, options: [String] = []) throws -> SyntaxResponse {
88
let sourceFile = Parser.parse(source: code)
9-
9+
1010
let syntax: Syntax
1111
if options.contains("fold") {
1212
syntax = OperatorTable.standardOperators.foldAll(sourceFile, errorHandler: { _ in })
@@ -26,6 +26,6 @@ struct SyntaxParser {
2626
let encoder = JSONEncoder()
2727
let json = String(decoding: try encoder.encode(tree), as: UTF8.self)
2828

29-
return SyntaxResponse(syntaxHTML: html, syntaxJSON: json, swiftVersion: swiftVersion)
29+
return SyntaxResponse(syntaxHTML: html, syntaxJSON: json, swiftVersion: version)
3030
}
3131
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../Sources/App/Models/SyntaxResponse.swift

Sources/App/Controllers/TokenVisitor.swift Resources/parsers/50800/Sources/parser/TokenVisitor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ final class TokenVisitor: SyntaxRewriter {
8484
),
8585
type: syntaxType
8686
)
87-
87+
8888
tree.append(treeNode)
8989
index += 1
9090

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Foundation
2+
let version = "5.8.1"

0 commit comments

Comments
 (0)