Skip to main content

A type-safe applicative parsing library

Project description

functional_parsing_library

A small production non-ready Python library implementing basic applicative parsers. Roughly speaking, these are functions with signature str -> T | CouldNotParse transforming strings into structured data. For example, you might have a function integer which will transform "1" and "-1919" to the integers 1 and -1919, and the string "boink" to CouldNotParse().

What makes these functions useful is that they can be combined with so-called parser combinators. For example, if we already have parsers nonnegative_integer and negative_integer, the integer parser from earlier could be written as integer = nonnegative_integer | negative_integer. This library implements various such combinators, such as many, some, ignore_left, many_till, and so on.

Another piece of structure that makes these functions useful is that they're functorial: If I have a parser p of type Parser[T] (that is, a function which parses strings to objects of type T), and a function f: T -> S, then f * p will be a parser for objects of type S. For example, take len * many(word('borf')), and try to parse "borfborfborf". Here word('borf') will parse "borf" to the string "borf" (and any other string to CouldNotParse), so the parser many(word('borf') will try and match as many "borf"s as possible and parse our string to the list ['borf', 'borf', 'borf']. The length of this list is 3, so len * many(word('borf')) parses our string to the integer 3.

This works with multi-argument functions as well. If f is a function of type [T, S] -> U, and we have parsers p and q for objects of type T and S, then f * p & q will first try to match p, and if this succeeds it will try and match q, and finally it will apply f.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

functional_parsing_library-0.0.11.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

functional_parsing_library-0.0.11-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file functional_parsing_library-0.0.11.tar.gz.

File metadata

File hashes

Hashes for functional_parsing_library-0.0.11.tar.gz
Algorithm Hash digest
SHA256 ece55c98bc70c4aaa978990173dfe325e7477ed5db5c256624c0297b30ce0205
MD5 f1d964bf0515f2011380274e2b48f9b9
BLAKE2b-256 fbf600257030c9cdb0b14e5f8a388cb1709d3e97dc35805b1e9084318e4c4027

See more details on using hashes here.

File details

Details for the file functional_parsing_library-0.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for functional_parsing_library-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 42eeb6baaad31f70f85a5ed75889db10a845bd535e53ff4cf8135e35662027f3
MD5 705443a663956bb487198e81c5a57c96
BLAKE2b-256 15be02675208b87d35c32726a15d21e54f9aeef968e989ed20e6feef79f322c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page