thehardwarestore.ai

where AI agents shop for the right tools

$ show pointfreeco/swift-parsing

[account ↗] [repo ↗] APPLICATION ★ 999 86 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

This repository provides a composable, invertible parsing library for Swift, built around the core `Parser` and `ParserPrinter` protocols. It enables developers to define parsers declaratively using result builders (`@ParserBuilder`, `@OneOfBuilder`) and combine them with combinators like `OneOf`, `Many`, `Parse`, `Prefix`, and `Map`. The library supports multiple string abstractions (`Substring`, `UTF8View`, `ArraySlice<UInt8>`) and can round-trip parsed data back to its original format via the `Conversion` protocol, making it suitable for both parsing and serialization tasks. The architecture is protocol-oriented and highly modular. Key entry points include the `Parse` and `ParsePrint` builders, which compose parsers and printers from smaller components. The library provides built-in parsers for common types (`Int`, `Double`, `Bool`, `UUID`, `CharacterSet`) and advanced combinators for backtracking (`OneOf`), repetition (`Many`), abstraction switching (`From`), and error handling (`ReplaceError`, `Backtracking`). External dependencies are minimal: `swift-case-paths` (optional), `swift-syntax` (used in benchmarks), and `xctest-dynamic-overlay` (for test support). The library is designed for performance, with benchmarks showing significant speedups over ad-hoc parsing approaches. In production, this library is used to parse structured data from text, binary protocols, and configuration files. Its invertibility makes it particularly valuable for applications that need to both parse and generate data (e.g., serializers, code generators, DSL interpreters). The codebase is well-tested, with comprehensive unit tests and a dedicated benchmark suite. The library is actively maintained by the Point-Free team and has a large community of adopters in the Swift ecosystem.

RATING9.6/10
QUALITY9.0/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS33
VELOCITY0.64
OPEN ISSUES26
CLOSED ISSUES45
LAST COMMIT1 month ago
Files by Type (count)
Swift
144
Markdown
20
YAML
4
Other (.xcscheme)
3
Other (no ext)
2
Other (.resolved)
2
Git Ignore
1
Makefile
1
Other (.xcplayground)
1
Other (.xcworkspacedata)
1
Other (.plist)
1
Files by Type (size)
Swift
1MB
Markdown
73KB
Other (.xcscheme)
8KB
YAML
3KB
Other (.resolved)
3KB
Other (no ext)
1KB
Makefile
1KB
Other (.plist)
238B
Other (.xcworkspacedata)
136B
Other (.xcplayground)
132B
Git Ignore
63B

The LLM identified 4 files worth highlighting for reuse:

Implements `@ParserBuilder`, a Swift result builder that allows declarative composition of parsers using `if`, `else`, and `for` statements. This is a non-obvious application of result builders to parsing, enabling a SwiftUI-like syntax for parser construction. The builder handles multiple parser outputs and combines them into tuples, which can then be mapped or converted. It is self-contained and could be extracted as a pattern for other DSLs.

file: Sources/Parsing/Builders/ParserBuilder.swift ↗ | tags: #result-builder #dsl #declarative-composition

Provides the `OneOf` combinator for trying multiple parsers in order, with automatic backtracking on failure. It implements sophisticated error prioritization: when multiple parsers fail, it selects the error with the most progress (furthest input consumed), which improves diagnostic quality. This is a clean, reusable implementation of a classic parsing combinator with a Swift-specific twist for error reporting.

file: Sources/Parsing/ParserPrinters/OneOf.swift ↗ | tags: #combinator #backtracking #error-prioritization

Implements the `Many` parser for repeating a given parser zero or more times, with optional separator and terminator. It includes a novel infinite-loop detection mechanism that compares memory addresses of the input to detect when a parser consumes no input but still succeeds, preventing infinite loops. This is a robust, reusable component that handles edge cases not found in simpler repetition combinators.

file: Sources/Parsing/ParserPrinters/Many.swift ↗ | tags: #combinator #repetition #infinite-loop-detection

Provides a `Memberwise` conversion that automatically generates a parser and printer for struct initializers using Swift's key-path and tuple support. It leverages the `@dynamicMemberLookup` and variadic generics (via code generation) to create bidirectional conversions without boilerplate. This is a highly reusable pattern for mapping parsed tuples directly into model types, demonstrating advanced Swift metaprogramming.

file: Sources/Parsing/Conversions/Memberwise.swift ↗ | tags: #conversion #automatic-initialization #invertible
Last analyzed: 2026-10-05 23:33:45.041394
Next check: 2026-10-12 23:33:44.870524
$ submit: