No, it would return a custom pattern type which conforms to ExpressibleByStringInterpolation.
The idea is that you would have 2 ways to build a pattern - either using the compact string syntax:
let p: PathPattern = "/books/id_\(\d+)/info/\(.*)"
or some kind of result-builder DSL syntax if you have something which has outgrown that shorthand:
PathPattern {
"books"
Segment {
"id_"
Regex { /(\d+)/ }.capture()
}
"info"
Regex { /(.*)/ }.capture()
}
In neither case would we be parsing regexes at runtime. That's something path-to-regexp does because it's in JavaScript and can assume a JIT, but hardly anybody actually cares what the path DSL parses down to - they just want a convenient way to match a path against a pattern.
The Swift version would be more like "path-to-opaque-pattern-object", I would think.