@@ -7,8 +7,8 @@ extension HTMLKitUtilities {
77 public static func expandHTMLMacro( context: HTMLExpansionContext ) throws -> ExprSyntax {
88 var context = context
99 let ( string, encoding) = expandMacro ( context: & context)
10- let encodingResult = encodingResult ( context: context, node: context. expansion, string: string, for : encoding )
11- let expandedResult = representationResult ( encoding: encoding, encodedResult: encodingResult, resultType : context . resultType )
10+ let encodingResult = encoding . result ( context: context, node: context. expansion, string: string)
11+ let expandedResult = context . resultType . result ( encoding: encoding, encodedResult: encodingResult)
1212 return " \( raw: expandedResult) "
1313 }
1414
@@ -24,14 +24,13 @@ extension HTMLKitUtilities {
2424}
2525
2626// MARK: Encoding result
27- extension HTMLKitUtilities {
28- static func encodingResult (
27+ extension HTMLEncoding {
28+ public func result (
2929 context: HTMLExpansionContext ,
3030 node: MacroExpansionExprSyntax ,
31- string: String ,
32- for encoding: HTMLEncoding
31+ string: String
3332 ) -> String {
34- switch encoding {
33+ switch self {
3534 case . utf8Bytes:
3635 guard hasNoInterpolation ( context, node, string) else { return " " }
3736 return bytes ( [ UInt8] ( string. utf8) )
@@ -56,15 +55,15 @@ extension HTMLKitUtilities {
5655 return encoded. replacingOccurrences ( of: " $0 " , with: string)
5756 }
5857 }
59- private static func bytes< T: FixedWidthInteger > ( _ bytes: [ T ] ) -> String {
58+ private func bytes< T: FixedWidthInteger > ( _ bytes: [ T ] ) -> String {
6059 var string = " [ "
6160 for b in bytes {
6261 string += " \( b) , "
6362 }
6463 string. removeLast ( )
6564 return string. isEmpty ? " [] " : string + " ] "
6665 }
67- private static func hasNoInterpolation( _ context: HTMLExpansionContext , _ node: MacroExpansionExprSyntax , _ string: String ) -> Bool {
66+ private func hasNoInterpolation( _ context: HTMLExpansionContext , _ node: MacroExpansionExprSyntax , _ string: String ) -> Bool {
6867 guard string. firstRange ( of: try ! Regex ( " \\ ((.*) \\ ) " ) ) == nil else {
6968 if !context. ignoresCompilerWarnings {
7069 context. diagnose ( Diagnostic ( node: node, message: DiagnosticMsg ( id: " interpolationNotAllowedForDataType " , message: " String Interpolation is not allowed for this data type. Runtime values get converted to raw text, which is not the intended result. " ) ) )
@@ -76,13 +75,12 @@ extension HTMLKitUtilities {
7675}
7776
7877// MARK: Representation results
79- extension HTMLKitUtilities {
80- static func representationResult (
78+ extension HTMLExpansionResultTypeAST {
79+ public func result (
8180 encoding: HTMLEncoding ,
82- encodedResult: String ,
83- resultType: HTMLExpansionResultTypeAST
81+ encodedResult: String
8482 ) -> String {
85- switch resultType {
83+ switch self {
8684 case . literal:
8785 if encoding == . string {
8886 return literal ( encodedResult: encodedResult)
@@ -94,12 +92,13 @@ extension HTMLKitUtilities {
9492 // TODO: show compiler diagnostic
9593 }*/
9694 case . chunks( let optimized, let chunkSize) :
97- return " [ " + chunks( encoding: encoding, encodedResult: encodedResult, async : false , optimized: optimized, chunkSize: chunkSize) . joined ( separator: " , " ) + " ] "
95+ let slices = chunks ( encoding: encoding, encodedResult: encodedResult, async : false , optimized: optimized, chunkSize: chunkSize) . joined ( separator: " , \n " )
96+ return " [ " + ( slices. isEmpty ? " " : " \n \( slices) \n " ) + " ] "
9897 #if compiler(>=6.2)
9998 case . chunksInline( let optimized, let chunkSize) :
10099 let typeAnnotation : String = " String " // TODO: fix
101- let chunks = chunks ( encoding: encoding, encodedResult: encodedResult, async : false , optimized: optimized, chunkSize: chunkSize) . joined ( separator: " , " )
102- return " InlineArray< \( chunks. count) , \( typeAnnotation) >([ \( chunks ) ]) "
100+ let slices = chunks ( encoding: encoding, encodedResult: encodedResult, async : false , optimized: optimized, chunkSize: chunkSize) . joined ( separator: " , \n " )
101+ return " InlineArray< \( chunks. count) , \( typeAnnotation) >([ " + ( slices . isEmpty ? " " : " \n \( slices ) \n " ) + " ]) "
103102 #endif
104103 case . stream( let optimized, let chunkSize) :
105104 return streamed (
@@ -129,11 +128,11 @@ extension HTMLKitUtilities {
129128}
130129
131130// MARK: Literal
132- extension HTMLKitUtilities {
133- static var interpolationRegex : Regex < AnyRegexOutput > {
131+ extension HTMLExpansionResultTypeAST {
132+ public var interpolationRegex : Regex < AnyRegexOutput > {
134133 try ! Regex . init ( #"( \+ String\(describing: [\x00-\x2A\x2C-\xFF]+\) \+ )"# )
135134 }
136- static func literal( encodedResult: String ) -> String {
135+ public func literal( encodedResult: String ) -> String {
137136 var interpolation = encodedResult. matches ( of: interpolationRegex)
138137 guard !interpolation. isEmpty else {
139138 return encodedResult
@@ -170,8 +169,8 @@ extension HTMLKitUtilities {
170169}
171170
172171// MARK: Optimized literal
173- extension HTMLKitUtilities {
174- static func optimizedLiteral( encodedResult: String ) -> String {
172+ extension HTMLExpansionResultTypeAST {
173+ public func optimizedLiteral( encodedResult: String ) -> String {
175174 var interpolation = encodedResult. matches ( of: interpolationRegex)
176175 guard !interpolation. isEmpty else {
177176 return encodedResult
@@ -195,7 +194,7 @@ extension HTMLKitUtilities {
195194 }
196195 return " HTMLOptimizedLiteral(reserveCapacity: \( reserveCapacity) ).render(( \n \( values. joined ( separator: " , \n " ) ) \n )) "
197196 }
198- static func normalizeInterpolation( _ value: Substring , withQuotationMarks: Bool ) -> String {
197+ public func normalizeInterpolation( _ value: Substring , withQuotationMarks: Bool ) -> String {
199198 var value = value
200199 value. removeFirst ( 22 ) // ` + String(describing: `.count
201200 value. removeLast ( 3 ) // ` + `.count
@@ -209,8 +208,8 @@ extension HTMLKitUtilities {
209208}
210209
211210// MARK: Chunks
212- extension HTMLKitUtilities {
213- static func chunks(
211+ extension HTMLExpansionResultTypeAST {
212+ public func chunks(
214213 encoding: HTMLEncoding ,
215214 encodedResult: String ,
216215 async : Bool ,
@@ -279,8 +278,8 @@ extension HTMLKitUtilities {
279278}
280279
281280// MARK: Streamed
282- extension HTMLKitUtilities {
283- static func streamed(
281+ extension HTMLExpansionResultTypeAST {
282+ public func streamed(
284283 encoding: HTMLEncoding ,
285284 encodedResult: String ,
286285 async : Bool ,
0 commit comments