Skip to content

Commit de1ae86

Browse files
authored
Remove Array<Self> from parsers (#1189)
* Remove self-referential parsers, xrOS -> visionOS * Make StringLiteral parser public * Fix macro tests running on iOS
1 parent ba88101 commit de1ae86

File tree

35 files changed

+709
-742
lines changed

35 files changed

+709
-742
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
5+
import CompilerPluginSupport
56

67
let package = Package(
78
name: "LiveViewNative",
@@ -26,6 +27,10 @@ let package = Package(
2627

2728
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.2"),
2829
.package(url: "https://github.com/apple/swift-markdown.git", from: "0.2.0"),
30+
31+
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.2"),
32+
33+
.package(url: "https://github.com/pointfreeco/swift-parsing", from: "0.13.0"),
2934
],
3035
targets: [
3136
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -36,7 +41,9 @@ let package = Package(
3641
"SwiftSoup",
3742
"SwiftPhoenixClient",
3843
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
39-
.product(name: "LiveViewNativeCore", package: "liveview-native-core-swift")
44+
.product(name: "LiveViewNativeCore", package: "liveview-native-core-swift"),
45+
"LiveViewNativeMacros",
46+
"LiveViewNativeStylesheet"
4047
],
4148
plugins: [
4249
.plugin(name: "BuiltinRegistryGeneratorPlugin")
@@ -51,6 +58,16 @@ let package = Package(
5158
dependencies: ["LiveViewNative"]
5259
),
5360

61+
.executableTarget(
62+
name: "ModifierGenerator",
63+
dependencies: [
64+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
65+
.product(name: "SwiftSyntax", package: "swift-syntax"),
66+
.product(name: "SwiftParser", package: "swift-syntax"),
67+
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
68+
]
69+
),
70+
5471
.executableTarget(
5572
name: "BuiltinRegistryGenerator",
5673
dependencies: [
@@ -98,15 +115,47 @@ let package = Package(
98115
.product(name: "Markdown", package: "swift-markdown"),
99116
]
100117
),
101-
// .plugin(
102-
// name: "TutorialRepoGeneratorPlugin",
103-
// capability: .command(
104-
// intent: .custom(verb: "generate-tutorial-repo", description: ""),
105-
// permissions: [
106-
// .writeToPackageDirectory(reason: "This command generates a repo for the tutorial that has a commit for each step")
107-
// ]
108-
// ),
109-
// dependencies: [.target(name: "TutorialRepoGenerator")]
110-
// )
118+
119+
.macro(
120+
name: "LiveViewNativeMacros",
121+
dependencies: [
122+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
123+
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
124+
]
125+
),
126+
.testTarget(
127+
name: "LiveViewNativeMacrosTests",
128+
dependencies: [
129+
"LiveViewNativeMacros",
130+
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
131+
]
132+
),
133+
134+
.macro(
135+
name: "LiveViewNativeStylesheetMacros",
136+
dependencies: [
137+
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
138+
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
139+
]
140+
),
141+
.target(
142+
name: "LiveViewNativeStylesheet",
143+
dependencies: [
144+
"LiveViewNativeStylesheetMacros",
145+
.product(name: "LiveViewNativeCore", package: "liveview-native-core-swift"),
146+
.product(name: "Parsing", package: "swift-parsing"),
147+
]
148+
),
149+
.testTarget(
150+
name: "LiveViewNativeStylesheetTests",
151+
dependencies: ["LiveViewNativeStylesheet"]
152+
),
153+
.testTarget(
154+
name: "LiveViewNativeStylesheetMacrosTests",
155+
dependencies: [
156+
"LiveViewNativeStylesheetMacros",
157+
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
158+
]
159+
),
111160
]
112161
)

[email protected]

Lines changed: 0 additions & 171 deletions
This file was deleted.

Sources/LiveViewNative/Stylesheets/Modifiers/Overrides/SearchCompletionModifier.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ struct _SearchCompletionModifier: ViewModifier {
1616

1717
enum Completion {
1818
case completion(String)
19-
#if os(iOS) || os(macOS) || os(xrOS)
19+
#if os(iOS) || os(macOS) || os(visionOS)
2020
case token(Token)
2121
#endif
2222
}
2323
let completion: Completion
2424

25-
#if os(iOS) || os(macOS) || os(xrOS)
25+
#if os(iOS) || os(macOS) || os(visionOS)
2626
init(_ token: AtomString) {
2727
self.completion = .token(.init(id: token.value))
2828
}
@@ -36,7 +36,7 @@ struct _SearchCompletionModifier: ViewModifier {
3636
switch completion {
3737
case .completion(let string):
3838
content.searchCompletion(string)
39-
#if os(iOS) || os(macOS) || os(xrOS)
39+
#if os(iOS) || os(macOS) || os(visionOS)
4040
case .token(let token):
4141
content.searchCompletion(token)
4242
#endif

Sources/LiveViewNative/Stylesheets/Modifiers/Overrides/SearchScopesModifier.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct _SearchScopesModifier<R: RootRegistry>: ViewModifier {
2222
@ObservedElement private var element
2323
@LiveContext<R> private var context
2424

25-
#if os(iOS) || os(macOS) || os(tvOS) || os(xrOS)
25+
#if os(iOS) || os(macOS) || os(tvOS) || os(visionOS)
2626
@available(iOS 16.4, macOS 13.3, tvOS 16.4, *)
2727
init(_ scope: ChangeTracked<String>, activation: SearchScopeActivation, scopes: ViewReference) {
2828
self._scope = scope
@@ -38,7 +38,7 @@ struct _SearchScopesModifier<R: RootRegistry>: ViewModifier {
3838
#endif
3939

4040
func body(content: Content) -> some View {
41-
#if os(iOS) || os(macOS) || os(tvOS) || os(xrOS)
41+
#if os(iOS) || os(macOS) || os(tvOS) || os(visionOS)
4242
if #available(iOS 16.4, macOS 13.3, tvOS 16.4, *) {
4343
if let activation = activation as? SearchScopeActivation {
4444
content.searchScopes($scope, activation: activation, { scopes.resolve(on: element, in: context) })

Sources/LiveViewNative/Stylesheets/ParseableTypes/AnyGesture+ParseableModifierValue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ extension AnyGesture: ParseableModifierValue where Value == Any {
144144
#endif
145145
}
146146

147-
#if os(iOS) || os(macOS) || os(xrOS)
147+
#if os(iOS) || os(macOS) || os(visionOS)
148148
@ParseableExpression
149149
struct Magnify {
150150
static let name = "MagnifyGesture"

Sources/LiveViewNative/Stylesheets/ParseableTypes/AnyTextSelectability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum AnyTextSelectability: String, CaseIterable, ParseableModifierValue {
1616
}
1717

1818
extension View {
19-
#if os(iOS) || os(macOS) || os(xrOS)
19+
#if os(iOS) || os(macOS) || os(visionOS)
2020
@_disfavoredOverload
2121
@ViewBuilder
2222
func textSelection(_ selectability: AnyTextSelectability) -> some View {

Sources/LiveViewNative/Stylesheets/ParseableTypes/Axis+Set+ParseableModifierValue.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ extension Axis.Set: ParseableModifierValue {
1515
"horizontal": Axis.Set.horizontal,
1616
"vertical": Axis.Set.vertical,
1717
])
18-
Array<Self>.parser(in: context).map(Self.init(_:))
18+
Array<Axis>.parser(in: context).map({
19+
Self.init($0.map({
20+
switch $0 {
21+
case .horizontal:
22+
return .horizontal
23+
case .vertical:
24+
return .vertical
25+
}
26+
}))
27+
})
1928
}
2029
}
2130
}

Sources/LiveViewNative/Stylesheets/ParseableTypes/Edge+ParseableModifierValue.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ extension HorizontalEdge.Set: ParseableModifierValue {
6464
"trailing": .trailing,
6565
"all": .all,
6666
])
67-
Array<Self>.parser(in: context).map({ Self.init($0) })
67+
Array<HorizontalEdge>.parser(in: context).map({ Self.init($0.map(Self.init)) })
6868
}
6969
}
7070
}
@@ -77,7 +77,7 @@ extension VerticalEdge.Set: ParseableModifierValue {
7777
"bottom": bottom,
7878
"all": all,
7979
])
80-
Array<Self>.parser(in: context).map({ Self.init($0) })
80+
Array<VerticalEdge>.parser(in: context).map({ Self.init($0.map(Self.init)) })
8181
}
8282
}
8383
}

Sources/LiveViewNative/Stylesheets/ParseableTypes/KeyEquivalent+ParseableModifierValue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99
import LiveViewNativeStylesheet
1010

11-
#if os(iOS) || os(macOS) || os(xrOS)
11+
#if os(iOS) || os(macOS) || os(visionOS)
1212
extension KeyEquivalent: ParseableModifierValue {
1313
public static func parser(in context: ParseableModifierContext) -> some Parser<Substring.UTF8View, Self> {
1414
OneOf {

0 commit comments

Comments
 (0)