File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,20 @@ extension KvEnvironmentScope {
5858 /// A property having no default value.
5959 var c : C
6060 }
61+ }
62+ /// Specify access modifiers (e.g. public, private, etc.) for the extensions
63+ /// to manage visibility of produced environment properties.
64+ private extension KvEnvironmentScope {
6165 /// Constant declarations are transformed to computed properties having getters only.
6266 #kvEnvironment { let a_ee : A = . init( a: 0xEE ) , a_ff : A ? = . init( a: 0xFF ) }
6367}
68+ /// Below is an example of explicit declaration of an environment property.
69+ private extension KvEnvironmentScope {
70+ private struct aZeroKey : KvEnvironmentKey {
71+ static var defaultValue : A { . init( a: 0 ) }
72+ }
73+ var zeroA : A {
74+ get { self [ aZeroKey. self] }
75+ set { self [ aZeroKey. self] = newValue }
76+ }
77+ }
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ public struct KvEnvironmentScopeEntryMacro: DeclarationMacro {
3333 ) throws -> [ DeclSyntax ] {
3434 let closure : ClosureExprSyntax
3535
36+ try ( node as? WithModifiersSyntax ) ? . modifiers. forEach {
37+ guard Constants . accessModifiers. contains ( $0. name)
38+ else { throw ExpansionError ( " unexpected access modifier ` \( $0. trimmedDescription) `. Apply access modifiers to the entire extension " ) }
39+ }
40+
3641 switch node. argumentList. last {
3742 case . none:
3843 guard let trailingClosure = node. trailingClosure
@@ -113,6 +118,19 @@ public struct KvEnvironmentScopeEntryMacro: DeclarationMacro {
113118 }
114119 }
115120
121+ // MARK: .Constants
122+
123+ private enum Constants {
124+ static var accessModifiers : Set < TokenSyntax > { [
125+ . keyword( . fileprivate) ,
126+ . keyword( . internal) ,
127+ . keyword( . open) ,
128+ . keyword( . package ) ,
129+ . keyword( . private) ,
130+ . keyword( . public) ,
131+ ] }
132+ }
133+
116134 // MARK: .EntryDescription
117135
118136 private struct EntryDescription {
You can’t perform that action at this time.
0 commit comments