apple / swift-experimental-string-processing

An early experimental general-purpose pattern matching engine for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SE-0351 was accepted with `mapOutput`, but it's not implemented

tevelee opened this issue · comments

The proposal for SE-0351 defines a way to map the output of a regex component to reorder captures, flatten nested optionals, or create instances of a custom type. See https://github.com/apple/swift-evolution/blob/main/proposals/0351-regex-builder.md#mapping-output
The proposal was accepted and its status is declared as Implemented (Swift 5.7), but this feature was left out from the compiler.

This is a crucial feature, and I miss it a lot whenever I deal with regexes in Swift. It's not possible to implement it as an extension by external users of the API, because it should have been a builtin component in the DSL tree.

I only found traces of it in the codebase, the PR #455 that implemented it was closed and the follow-up #466 is still in draft.

This pretty much flattens out all regexes to a single level and limits how much composition can be done into custom types. Hope this gets some attention for the next release of Swift

Want this also. Nested tuples to support nested Captures would be better than nothing but a way to capture and return custom types to group multiple captures into structs would be better.