Best way to write a parser in Swift?

What is the recommendation on writing a parser in Swift?

I went down the route of looking for a Parsec/combinator library and found several implementations in Swift but most haven't been updated in a while. Also, the Parsec implementations appear to be very heavily Haskell influenced in their syntax/style which I think will limit who can work on it.

Is there a "Swift-Way" to parse structured content? (i.e. an AST)

If you're willing to take on a dependency, swift-parsing is a pretty full-featured library that takes a combinator approach using result builders (much like Swift's regex builders). Its parsing is fully generic over the input (so you can write URL routers with it), and it supports bidirectional parsing, much like Foundation's formatters support both parsing and printing. It also has a competitive performance profile when compared to more ad hoc parsing approaches.


oh I didn't see this one earlier, I'll check it out. Thank you :grinning: