Unlock This Episode
Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.
So we now have the basic infrastructure in place to start seeing what parser builders give us over the take/skip fluent style of parsing that we developed previously, and so far it’s pretty promising.
However, on Point-Free we like to frequently ask the question “What’s the point?” so that we can bring things back down to earth and make sure that what we are doing is really worth it. In the case of result builders there is a strong inclination to use this new Swift feature to tackle problems that don’t really need a comprehensive DSL or builder syntax. Do parsers really meet the requirements necessary to justify using result builders?
And we think definitely, yes. So far we have only parsed a simple textual format, but the dividends really start to pay when we tackle more complex problems. This gives us more opportunities to clean up noise and have the parsers tell a more concise story, and gives us a chance to create new parsing tools that leverage builder syntax.
So, Let’s start flexing those muscles by taking a look at some of the parser demos that come with the library to see what other cool things there are to discover.
If you didn’t know this already, the library comes with a large collection of parsers and benchmarks. If we expand the swift-parsing-benchmark directory we will find 16 different benchmarks that test a variety of things. There are a lot of fun things in these benchmarks, including and arithmetic expression parser, a binary data parser, an HTTP parser, a router, and a lot more.
Parsing is a surprisingly ubiquitous problem in programming. Every time we construct an integer or a URL from a string, we are technically doing parsing. After demonstrating the many types of parsing that Apple gives us access to, we will take a step back and define the essence of parsing in a single type. That type supports many wonderful types of compositions, and allows us to break large, complex parsing problems into small, understandable units.
A library for turning nebulous data into well-structured data, with a focus on composition, performance, generality, and invertibility.
The Swift core team’s proposal and experimental repository for declarative string processing, which includes result builder syntax for creating regular expressions, and inspired us to explore result builders for parsing.
Why does the
mapfunction appear in every programming language supporting “functional” concepts? And why does Swift have two
mapfunctions? We will answer these questions and show that
maphas many universal properties, and is in some sense unique.