pointfreeco /swift-parsing
A library for turning nebulous data into well-structured data, with a focus on composition, performance, generality, and ergonomics.
★ 1,001⑂ 95👁 14⑃ 202● 59▤ 27
+0
日增长
1,001
stars
95
forks
14
watchers
202
prs
59
issues
27
releases
README
swift-parsing
!CI
A library for turning unstructured data into structured data, with a focus on composition, performance, generality, and invertibility:
Composition: Ability to break large, complex parsing problems down into smaller, simpler ones. And the ability to take small, simple parsers and easily combine them into larger, more complex ones.
Performance: Parsers that have been composed of many smaller parts should perform as well as highly-tuned, hand-written parsers.
Generality: Ability to parse _any_ kind of input into _any_ kind of output. This allows you to choose which abstraction levels you want to work on based on how much performance you need or how much correctness you want guaranteed. For example, you can write a highly tuned parser on collections of UTF-8 code units, and it will automatically plug into parsers of strings, arrays, unsafe buffer pointers and more.
Invertibility: Ability to invert your parsers so that they are printers. This allows you to transform your well-structured data back into unstructured data, which is useful for serialization, sending data over the network, [URL routing][swift-url-routing], and more.
---
Motivation
Getting started
Benchmarks
Documentation
Community
Other libraries
License
Learn More
This library was designed over the course of many episodes on Point-Free, a video series exploring functional programming and the Swift language, hosted by Brandon Williams and Stephen Celis. You can watch all of the episodes here.
Motivation
Parsing is a surprisingly ubiquitous problem in programming. We can define parsing as trying to transform unstructured data into structured data. The Swift standard library comes with a number of parsers that we reach for every day. For example, there are initializers on Int, Double, and even Bool, that attempt to parse numbers and booleans from strings:
swift
Int("42") // 42
Int("Hello") // nil
Double("123.45") // 123.45
Double("Goodbye") // nil
Bool("true") // true
Bool("0") // nil
And there are types like JSONDecoder and PropertyListDecoder that attempt to parse Decodable-conforming types from data:
swift
try JSONDecoder().decode(User.self, from: data)
try PropertyListDecoder().decode(Settings.self, from: data)
While parsers are everywhere in Swift, Swift has no holistic story _for_ parsing. Instead, we typically parse data in an ad hoc fashion using a number of unrelated initializers, methods, and other means. And this typically leads to less maintainable, less reusable code.
This library aims to write such a story for parsing in Swift. It introduces a single unit of parsing that can be combined in interesting ways to form large, complex parsers that can tackle the programming problems you need to solve in a maintainable way.
Getting started
This is an abridged version of the ["Getting Started"][getting-started-docs] article in the library's [documentation][swift-parsing-docs].
Suppose yoTop issues
#376Concurrency: make Parsers sendable8 comments · 2025-05-16#328EXC_BREAKPOINT crash when using ReplaceError parser5 comments · 2023-12-03#344FromUnicodeScalarView deprecation message possibly references unimplemented conversion?4 comments · 2024-04-02#114Suggestion: Pull comments about philosophy / design of the library into one place in the documentation4 comments · 2022-02-10#349Example in Getting started don't work - ambiguous use of 'buildExpression'2 comments · 2024-08-17#342tests fail to build with Xcode 15.32 comments · 2024-03-25#402Whitespace is missing U+200B1 comments · 2026-11-24#197Explore branch and factor combinators for printer-parsers1 comments · 2022-04-13
Discussions
#386How to run the Rest parser when a OneOf parser fails2 comments · 2026-01-27#385Updating swift-case-paths - EnumReflection.swift:87:74: error1 comments · 2025-12-11#383Possible to generate EBNF from a parser?1 comments · 2025-06-13#377Parsing strings from binary data1 comments · 2025-06-01#375How to parse boolean expressions as a list?1 comments · 2025-04-18#374Parsing quoted string0 comments · 2025-04-15#373How to hold `Prefix` correctly?4 comments · 2025-04-09#372Complete PGN Parsing in Swift – Tags, Moves, Comments & More1 comments · 2025-04-05
Latest release
0.15.3 0.15.3 2026-11-23What's Changed Update supported platforms for Swift 6.4. @bunoza in https://github.com/pointfreeco/swift-parsing/pull/401 New Contributors @bunoza made their first contribution in https://github.com/pointfreeco/swift-parsing/pull/401 Full Changelog: https://github.com/pointfreeco/swift-parsing/compare/0.15.2...0.15.3