{"id":13682434,"url":"https://github.com/purescript-contrib/purescript-parsing","last_synced_at":"2026-02-11T11:01:28.289Z","repository":{"id":13892375,"uuid":"16590695","full_name":"purescript-contrib/purescript-parsing","owner":"purescript-contrib","description":"A parser combinator library based on Parsec","archived":false,"fork":false,"pushed_at":"2026-01-17T08:07:48.000Z","size":603,"stargazers_count":155,"open_issues_count":20,"forks_count":52,"subscribers_count":10,"default_branch":"main","last_synced_at":"2026-02-01T22:53:35.367Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pursuit.purescript.org/packages/purescript-parsing","language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/purescript-contrib.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-02-06T19:27:17.000Z","updated_at":"2026-01-17T08:07:51.000Z","dependencies_parsed_at":"2024-01-14T15:26:54.012Z","dependency_job_id":"195ad97e-3064-44cb-87e7-ca6997302d78","html_url":"https://github.com/purescript-contrib/purescript-parsing","commit_stats":null,"previous_names":["purescript/purescript-parsing"],"tags_count":59,"template":false,"template_full_name":null,"purl":"pkg:github/purescript-contrib/purescript-parsing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-parsing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-parsing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-parsing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-parsing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purescript-contrib","download_url":"https://codeload.github.com/purescript-contrib/purescript-parsing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-parsing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29332292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T06:13:03.264Z","status":"ssl_error","status_checked_at":"2026-02-11T06:12:55.843Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T13:01:45.943Z","updated_at":"2026-02-11T11:01:28.231Z","avatar_url":"https://github.com/purescript-contrib.png","language":"PureScript","funding_links":[],"categories":["PureScript"],"sub_categories":[],"readme":"# Parsing\n\n[![CI](https://github.com/purescript-contrib/purescript-parsing/workflows/CI/badge.svg?branch=main)](https://github.com/purescript-contrib/purescript-parsing/actions?query=workflow%3ACI+branch%3Amain)\n[![Release](https://img.shields.io/github/release/purescript-contrib/purescript-parsing.svg)](https://github.com/purescript-contrib/purescript-parsing/releases)\n[![Pursuit](https://pursuit.purescript.org/packages/purescript-parsing/badge)](https://pursuit.purescript.org/packages/purescript-parsing)\n[![Maintainer: jamesdbrock](https://img.shields.io/badge/maintainer-jamesdbrock-teal.svg)](https://github.com/jamesdbrock)\n[![Maintainer: robertdp](https://img.shields.io/badge/maintainer-robertdp-teal.svg)](https://github.com/robertdp)\n[![Maintainer: chtenb](https://img.shields.io/badge/maintainer-chtenb-teal.svg)](http://github.com/chtenb)\n\nA monadic parser combinator library based on Haskell’s\n[Parsec](https://hackage.haskell.org/package/parsec).\n\n## Installation\n\nInstall `parsing` with [Spago](https://github.com/purescript/spago):\n\n```console\n$ spago install parsing\n```\n\n## Quick start\n\nHere is a basic tutorial introduction to monadic parsing with this package.\n\n### Parsers\n\nA parser turns a string into a data structure. Parsers in this library have the type `Parser s a`, where `s` is the type of the input string, and `a` is the type of the data which the parser will produce on success. `Parser s` is a monad. It’s defined in the module `Parsing`.\n\nMonads can be used to provide context for a computation, and that’s how we use them in monadic parsing.\nThe context provided by the `Parser s` monad is __the parser’s current location in the input string__.\nParsing starts at the beginning of the input string.\n\nParsing requires two more capabilities: __alternative__ and __failure__.\n\nWe need __alternative__ to be able to choose what kind of thing we’re parsing depending\non the input which we encounter. This is provided by the  `\u003c|\u003e` “alt”\noperator of the `Alt` typeclass instance of the `Parser s` monad.\nThe expression `p_left \u003c|\u003e p_right` will first try the `p_left` parser and if that fails\n__and consumes no input__ then it will try the `p_right` parser.\n\nWe need __failure__ in case the input stream is not parseable. This is provided by the `fail`\nfunction, which calls the `throwError` function of the `MonadThrow` typeclass instance of\nthe `Parser s` monad.\n\nTo run a parser, call the function `runParser :: s -\u003e Parser s a -\u003e Either ParseError a` in\nthe `Parsing` module, and supply it with an input string and a parser.\nIf the parse succeeds then the result is `Right a` and if the parse fails then the\nresult is `Left ParseError`.\n\n### Primitive parsers\n\nEach type of input string needs primitive parsers.\nPrimitive parsers for input string type `String` are in the `Parsing.String` module.\nFor example, the primitive `char :: Char -\u003e Parser String Char` parser will exactly match\none literal character and then advance by one position in the input string.\n\nWe can use these primitive parsers to write other `String` parsers.\n\n### Writing a parser\n\nHere is a parser `ayebee :: Parser String Boolean` which will accept only two input\nstrings: `\"ab\"` or `\"aB\"`.\nIt will return `true` if the `b` character is uppercase.\nIt will return `false` if the `b` character is lowercase.\nIt will fail with a `ParseError` if the input string is anything else.\n\n```purescript\nayebee :: Parser String Boolean\nayebee = do\n  _ \u003c- char 'a'\n  b \u003c- char 'b' \u003c|\u003e char 'B'\n  pure (b == 'B')\n```\n\nWe can run the parser `ayebee` like so\n\n```purescript\nrunParser \"aB\" ayebee\n```\n\nand then the parser will succeed and return `Right true`.\n\n#### [✨ Run the `ayebee` parser in your browser on *Try PureScript!*](https://try.purescript.org/?github=/purescript-contrib/purescript-parsing/main/docs/examples/QuickStart.purs)\n\n### More parsers\n\nThere are other `String` parsers in the module `Parsing.String.Basic`, for example the parser `letter :: Parser String Char` which will accept any single alphabetic letter.\n\n### Parser combinators\n\nParser combinators are in this package in the module `Parsing.Combinators`.\n\nA parser combinator is a function which takes a parser as an argument and returns a new parser. The `many` combinator, for example, will repeat a parser as many times as it can. So the parser `many letter` will have type `Parser String (Array Char)`.\n\nRunning the parser\n\n```purescript\nrunParser \"aBabaB\" (many ayebee)\n```\n\nwill return `Right [true, false, true]`.\n\n## Stack-safety\n\nStarting with v9.0.0, all parsers and combinators in this package are always\nstack-safe.\n\n## Recursion\n\nFor the most part, we can just write recursive parsers (parsers defined in\nterms of themselves) and they will work as we expect.\n\nIn some cases like this:\n\n```purescript\naye :: Parser String Char\naye = char 'a' *\u003e aye\n```\n\nwe might get a compile-time *CycleInDeclaration* error which looks like this:\n\n```\n  The value of aye is undefined here, so this reference is not allowed.\n\n\nSee https://github.com/purescript/documentation/blob/master/errors/CycleInDeclaration.md for more information,\nor to contribute content related to this error.\n```\n\nThis is happening because we tried to call `aye` recursively __“at a point\nwhere such a reference would be unavailable because of *strict evaluation*.”__\n\nThe\n[best way to solve](https://discourse.purescript.org/t/parsing-recursively-with-purescript-parsing/3184/2)\nthis is to stick a\n[`Control.Lazy.defer`](https://pursuit.purescript.org/packages/purescript-control/docs/Control.Lazy#t:Lazy)\nin front of the parser to break the cycle.\n```purescript\naye :: Parser String Char\naye = defer \\_ -\u003e char 'a' *\u003e aye\n```\n\n\n\n## Resources\n\n- [*Monadic Parsers at the Input Boundary* (YouTube)](https://www.youtube.com/watch?v=LLkbzt4ms6M) by James Brock is an introductory tutorial to monadic parser combinators with this package.\n\n- [*Monadic Parser Combinators*](https://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf) by Graham Hutton and Erik Meijer 1996.\n\n- The original short classic [FUNCTIONAL PEARLS *Monadic Parsing in Haskell*](https://www.cs.nott.ac.uk/~pszgmh/pearl.pdf) by Graham Hutton and Erik Meijer 1998.\n\n- [*Parsec: Direct Style Monadic Parser Combinators For The Real World*](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/parsec-paper-letter.pdf) by Daan Leijen and Erik Meijer 2001.\n\n- [*Parse, don't validate*](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/) by Alexis King is about what it means to “parse” something, without any mention of monads.\n\n- [*Revisiting Monadic Parsing in Haskell*](https://vaibhavsagar.com/blog/2018/02/04/revisiting-monadic-parsing-haskell/) by Vaibhav Sagar is a reflection on the Hutton, Meijer FUNCTIONAL PEARL.\n\n- [*Parsec: “try a \u003c|\u003e b” considered harmful*](http://blog.ezyang.com/2014/05/parsec-try-a-or-b-considered-harmful/) by Edward Z. Yang is about how to decide when to backtrack\nfrom a failed alternative.\n\n- [*Parser Combinators in Haskell*](https://serokell.io/blog/parser-combinators-in-haskell) by Heitor Toledo Lassarote de Paula.\n\nThere are lots of other great monadic parsing tutorials on the internet.\n\n## Related Packages\n\n- [__`parsing-dataview`__](https://pursuit.purescript.org/packages/purescript-parsing-dataview) primitive parsers for binary parsing of `ArrayBuffer`.\n- [__`datetime-parsing`__](https://pursuit.purescript.org/packages/purescript-datetime-parsing) parsers for dates and times.\n- [__`formatters`__](https://pursuit.purescript.org/packages/purescript-formatters) parsers for dates and times and various other things. \n\n## Documentation\n\n`parsing` documentation is stored in a few places:\n\n1. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-parsing).\n2. Written documentation is kept in the [docs directory](./docs).\n3. Usage examples can be found in [the test suite](./test).\n\nIf you get stuck, there are several ways to get help:\n\n- [Open an issue](https://github.com/purescript-contrib/purescript-parsing/issues) if you have encountered a bug or problem.\n- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://purescript.org/chat) chat.\n\n## Contributing\n\nYou can contribute to `parsing` in several ways:\n\n1. If you encounter a problem or have a question, please [open an issue](https://github.com/purescript-contrib/purescript-parsing/issues). We'll do our best to work with you to resolve or answer it.\n\n2. If you would like to contribute code, tests, or documentation, please [read the contributor guide](./CONTRIBUTING.md). It's a short, helpful introduction to contributing to this library, including development instructions.\n\n3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the [PureScript Discourse](https://discourse.purescript.org)! Writing libraries and learning resources are a great way to help this library succeed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurescript-contrib%2Fpurescript-parsing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurescript-contrib%2Fpurescript-parsing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurescript-contrib%2Fpurescript-parsing/lists"}