Avatar
omochimetaru 3/24/2022 2:44 AM
Full proposal: swift-experimental-string-processing/RegexBuilderDSL.md at main · apple/swift-experimental-string-processing · GitHub Regex builder DSL Status: Pitch Implementation: apple/swift-experimental-string-processing Table of Contents Introduction Motivation Proposed solution Detailed design RegexComponent protocol Concatenati...
2:45 AM
正規表現をResultBuilder上で構成して、
2:45 AM
その式中に含まれるCapture Listの数を、
2:45 AM
静的に型パラメータとして構成するライブラリの提案があって
2:46 AM
これ前に話題に出た時、実装しようと思うと、CaptureListの合成する部分がめっちゃ大変な事になるんじゃないかなとなんとなく思ったんだけど
2:46 AM
Hi all, While working on the RegexBuilder-based DSL with strongly-typed regex captures, we’ve come across an issue with where concatenating the component types in a result builder block as a tuple would involve a factorial explosion of buildBlock overloads and unreasonably long compilation time, and it isn't something that could be trivially re...
2:47 AM
まず、ResultBuilderに対して、他引数のbuildBlockの代わりに、
2:47 AM
2引数のbuildPartialBlockの複数の呼び出しに変換するAPIを用意した上で
2:48 AM
結合する2つの正規表現式の、左側と右側のキャプチャ要素数の組み合わせに対して
2:49 AM
二乗の組み合わせ全部をオーバーロードする力技を提案しててビックリした
2:49 AM
extension RegexComponentBuilder { public static func buildPartialBlock<W0, W1, C0, R0: RegexComponent, R1: RegexComponent>( accumulated: R0, next: R1 ) -> Regex<(Substring, C0)> where R0.Output == W0, R1.Output == (W1, C0) { .init(node: accumulated.regex.root.appending(next.regex.root)) } }
2:49 AM
↑これは 左側がキャプチャ0個、右側がキャプチャ1個
2:50 AM
public static func buildPartialBlock<W0, W1, C0, C1, R0: RegexComponent, R1: RegexComponent>( accumulated: R0, next: R1 ) -> Regex<(Substring, C0, C1)> where R0.Output == W0, R1.Output == (W1, C0, C1) { .init(node: accumulated.regex.root.appending(next.regex.root)) } public static func buildPartialBlock<W0, W1, C0, C1, C2, R0: RegexComponent, R1: RegexComponent>( accumulated: R0, next: R1 ) -> Regex<(Substring, C0, C1, C2)> where R0.Output == W0, R1.Output == (W1, C0, C1, C2) { .init(node: accumulated.regex.root.appending(next.regex.root)) } ...