Pattern matching to replace regular expressions #153
Jeehut
started this conversation in
Show and tell
Replies: 1 comment
-
Thanks for opening the discussion @Jeehut! This is indeed something I mused with a long time ago, but I didn't push it very far. I don't know how it would fit with regards to printing and the advances in the I wonder if:
In some sense, this is splitting your idea into two components and creating a bridge between regexes and |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Since version 0.5.0 which added a result builder syntax for the parsers, I'm considering to not only use this lib for parsing data (= structuring unstructured data), but also to replace
NSRegularExpression
in my code with parsers to make my regexes more readable, so for pattern matching (= checking if unstructured data matches a specific structure).The
matches
functionality of regexes was relatively easy to create by just adding this extension to my project:With this, I could for example replace this regex
with this parser:
I find this much more readable than regexes, and so far I could convert all my regexes I had that I only used for matching. I have not had a chance to explore if also template replacing regexes with capture groups could be somehow replaced with this library (I don't have an immediate idea how that could look like). Maybe after PointFree has explored the printing story in the current series, I'll have a look at that as well. But from the "Problem" episode I'm not sure if it's going to be even relevant.
I'd love to see swift-parsing replace Regexes in the long run (even if it's a separate library based on swift-parsing). The related Declarative String Processing discussion on the Swift Evolution thread could profit a lot from the experiences of this.
I'm curious if anyone (especially the library authors) would be interested in exploring this area for swift-parsing. :)
Beta Was this translation helpful? Give feedback.
All reactions