Repository navigation
0.8.0
-
Added: A case-iterable, raw-representable parser. Simply tack
.parser()onto any conforming type:enum Role: String, CaseIterable { case admin case guest case member } try Role.parser().parse("admin") // Role.admin
-
Fixed: An Xcode 13.3 compiler error has been fixed.
-
Fixed:
Optionallywill now backtrack if the parser fails (thanks @randomeizer). -
Fixed:
Double.parser()now parses as freely asDouble.init'sLosslessStringConvertiblefunctionality. -
Optimized:
PeekandNotwill only backtrack when they are successful (i.e., ifPeek's upstream parser successfully parses a value, or ifNot's upstream parser fails to parse a value). Backtracking on failure is now delegated to any upstreamOneOfs. -
Optimized:
OneOfManyno longer backtracks its final failure, bringing it in line with the behavior of the variadicOneOfs. -
Breaking change: The non-
inoutoverloads ofParser.parsenow attempt to fully consumeCollection-based inputs.// Before: try Int.parser().parse("42hello") // 42 // After: try Int.parser().parse("42hello") // error: unexpected input // --> input:1:13 // 1 | 42hello // | ^ expected end of input
This change makes parsing a bit more strict by default in order to catch potential issues with input.
If you want to ignore trailing output, use the
inoutversion ofparse, or explicitly describe how the input should be ignored in the parser, for example usingOptionally { Rest() }.map { _ in () }. -
Breaking change: The
Restparser now fails when the rest of input is empty.// Before: try Rest().parse("") // "" // After: try Rest().parse("") /// error: unexpected input /// --> input:1:1 /// 1 | /// | ^ expected a non-empty input
If your use of
Restshould not fail on empty input, wrap it explicitly in anOptionallyparser, or usereplaceError(with:)to provide a default value of"". -
Breaking change:
Peekis now aVoidparser. It can be used to inspect a value in order to test that a parser should be successful, but capturing any data is now the responsible for the parsers that comes afterward (thanks @randomeizer). -
Breaking change: The
isSignedparameter ofInt.parser()has been removed.Int.parser()will now always parse a sign ifFixedWidthInteger.isSignedreturns true (e.g.,Int.parser()will parse a sign,UInt.parser()will not.).If you want to parse a number without a sign, use a more explicit parser, or test for the sign before using
Int.parser(). E.g.:let digits = Prefix { $0.isNumber }.compactMap(Int.init) // ...or... let digits = Parse { Not { OneOf { "-"; "+" } } Int.parser() }
-
Updated:
Double.parser()can now be used on any type that conforms toBinaryFloatingPoint, includingFloat16. -
Updated:
Many'supdateAccumulatingResultcan now throw. -
Updated: Documentation has been revamped, including a new DocC-based static site with articles that cover common topics.
-
Infrastructure: Documentation fixes (thanks @haikusw).