{"id":18023447,"url":"https://github.com/meooow25/parser-regex","last_synced_at":"2025-03-26T23:31:07.439Z","repository":{"id":225524765,"uuid":"736346269","full_name":"meooow25/parser-regex","owner":"meooow25","description":"Regex based parsers","archived":false,"fork":false,"pushed_at":"2025-03-15T02:43:12.000Z","size":431,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T17:23:20.036Z","etag":null,"topics":["haskell","parser-combinators","regex"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meooow25.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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}},"created_at":"2023-12-27T16:45:46.000Z","updated_at":"2025-03-15T02:36:41.000Z","dependencies_parsed_at":"2024-05-20T22:56:03.854Z","dependency_job_id":"b8529da2-a7b9-4396-92d5-3f10d6741114","html_url":"https://github.com/meooow25/parser-regex","commit_stats":null,"previous_names":["meooow25/parser-regex"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meooow25%2Fparser-regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meooow25%2Fparser-regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meooow25%2Fparser-regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meooow25%2Fparser-regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meooow25","download_url":"https://codeload.github.com/meooow25/parser-regex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245753926,"owners_count":20666833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["haskell","parser-combinators","regex"],"created_at":"2024-10-30T07:09:31.115Z","updated_at":"2025-03-26T23:31:07.424Z","avatar_url":"https://github.com/meooow25.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parser-regex\n\n[![Hackage](https://img.shields.io/hackage/v/parser-regex?logo=haskell\u0026color=blue)](https://hackage.haskell.org/package/parser-regex)\n[![Haskell-CI](https://github.com/meooow25/parser-regex/actions/workflows/haskell-ci.yml/badge.svg)](https://github.com/meooow25/parser-regex/actions/workflows/haskell-ci.yml)\n\nRegex based parsers\n\n## Features\n\n* Parsers based on [regular expressions](https://en.wikipedia.org/wiki/Regular_expression),\n  capable of parsing [regular languages](https://en.wikipedia.org/wiki/Regular_language).\n  Note that there are no extra features to make parsing non-regular languages\n  possible.\n* Regexes are composed using combinators.\n* Resumable parsing of sequences of any type containing values of any type.\n* Special support for `Text` and `String` in the form of convenient combinators\n  and operations like find and replace.\n* Parsing runtime is linear in the length of the sequence being parsed. No\n  exponential backtracking.\n\n## Examples\n\n### Versus regex patterns\n\n```\n^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?\n```\n\nCan you guess what this matches?\n\nThis is a non-validating regex to extract parts of a URI, from\n[RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#appendix-B). It can\nbe translated as follows.\n\n```hs\n{-# LANGUAGE OverloadedStrings #-}\nimport Control.Applicative (optional)\nimport Data.Text (Text)\n\nimport Regex.Text (REText)\nimport qualified Regex.Text as R\nimport qualified Data.CharSet as CS\n\ndata URI = URI\n  { scheme    :: Maybe Text\n  , authority :: Maybe Text\n  , path      :: Text\n  , query     :: Maybe Text\n  , fragment  :: Maybe Text\n  } deriving Show\n\nuriRE :: REText URI\nuriRE = URI\n  \u003c$\u003e optional (R.someTextOf (CS.not \":/?#\") \u003c* R.char ':')\n  \u003c*\u003e optional (R.text \"//\" *\u003e R.manyTextOf (CS.not \"/?#\"))\n  \u003c*\u003e R.manyTextOf (CS.not \"?#\")\n  \u003c*\u003e optional (R.char '?' *\u003e R.manyTextOf (CS.not \"#\"))\n  \u003c*\u003e optional (R.char '#' *\u003e R.manyText)\n```\n```hs\n\u003e\u003e\u003e R.reParse uriRE \"https://github.com/meooow25/parser-regex?tab=readme-ov-file#parser-regex\"\nJust (URI { scheme = Just \"https\"\n          , authority = Just \"github.com\"\n          , path = \"/meooow25/parser-regex\"\n          , query = Just \"tab=readme-ov-file\"\n          , fragment = Just \"parser-regex\" })\n```\n\n### More parsing\n\nParsing is straightforward, even for tasks which may be impractical with\nsubmatch extraction typically offered by regex libraries.\n\n```hs\nimport Control.Applicative ((\u003c|\u003e))\nimport Data.Text (Text)\n\nimport Regex.Text (REText)\nimport qualified Regex.Text as R\nimport qualified Data.CharSet as CS\n\ndata Expr\n  = Var Text\n  | Expr :+ Expr\n  | Expr :- Expr\n  | Expr :* Expr\n  deriving Show\n\nexprRE :: REText Expr\nexprRE = var `R.chainl1` mul `R.chainl1` (add \u003c|\u003e sub)\n  where\n    var = Var \u003c$\u003e R.someTextOf CS.asciiLower\n    add = (:+) \u003c$ R.char '+'\n    sub = (:-) \u003c$ R.char '-'\n    mul = (:*) \u003c$ R.char '*'\n```\n```hs\n\u003e\u003e\u003e import qualified Regex.Text as R\n\u003e\u003e\u003e R.reParse exprRE \"a+b-c*d*e+f\"\nJust (((Var \"a\" :+ Var \"b\") :- ((Var \"c\" :* Var \"d\") :* Var \"e\")) :+ Var \"f\")\n```\n\n### Find and replace\n\nFind and replace using regexes are supported for `Text` and lists.\n\n```hs\n\u003e\u003e\u003e import Control.Applicative ((\u003c|\u003e))\n\u003e\u003e\u003e import qualified Data.Text as T\n\u003e\u003e\u003e import qualified Regex.Text as R\n\u003e\u003e\u003e\n\u003e\u003e\u003e data Color = Blue | Orange deriving Show\n\u003e\u003e\u003e let re = Blue \u003c$ R.text \"blue\" \u003c|\u003e Orange \u003c$ R.text \"orange\"\n\u003e\u003e\u003e R.find re \"color: orange\"\nJust Orange\n\u003e\u003e\u003e\n\u003e\u003e\u003e let re = T.toUpper \u003c$\u003e (R.text \"cat\" \u003c|\u003e R.text \"dog\" \u003c|\u003e R.text \"fish\")\n\u003e\u003e\u003e R.replaceAll re \"locate selfish hotdog\"\n\"loCATe selFISH hotDOG\"\n```\n\n### Parse any sequence\n\nRegexes are not restricted to parsing text. For example, one may parse vectors\nfrom the [vector](https://hackage.haskell.org/package/vector) library, because\nwhy not.\n\n```hs\nimport Regex.Base (Parser)\nimport qualified Regex.Base as R\nimport qualified Data.Vector.Generic as VG\n\nparseVector :: VG.Vector v c =\u003e Parser c a -\u003e v c -\u003e Maybe a\nparseVector = R.parseFoldr VG.foldr\n```\n```hs\n\u003e\u003e\u003e import Control.Applicative (many)\n\u003e\u003e\u003e import qualified Data.Vector as V\n\u003e\u003e\u003e import qualified Regex.Base as R\n\u003e\u003e\u003e\n\u003e\u003e\u003e let p = R.compile $ many ((,) \u003c$\u003e R.satisfy even \u003c*\u003e R.satisfy odd)\n\u003e\u003e\u003e let v = V.fromList [0..5] :: V.Vector Int\n\u003e\u003e\u003e parseVector p v\nJust [(0,1),(2,3),(4,5)]\n```\n\n## Documentation\n\nDocumentation is available on Hackage:\n[parser-regex](https://hackage.haskell.org/package/parser-regex)\n\nAlready familiar with regex patterns? See the\n[Regex pattern cheat sheet](https://github.com/meooow25/parser-regex/wiki/Regex-pattern-cheat-sheet).\n\n## Alternatives\n\n### `regex-applicative`\n\n[`regex-applicative`](https://hackage.haskell.org/package/regex-applicative) is\nthe primary inspiration for this library, and is similar in many ways.\n\n`parser-regex` attempts to be a more efficient and featureful library built on\nthe ideas of `regex-applicative`, though it does not aim to provide a superset\nof `regex-applicative`'s API.\n\n### Traditional regex libraries\n\nThese libraries use regex patterns.\n\n* [`regex-pcre`](https://hackage.haskell.org/package/regex-pcre)/[`regex-pcre-builtin`](https://hackage.haskell.org/package/regex-pcre-builtin)\n* [`regex-tdfa`](https://hackage.haskell.org/package/regex-tdfa)\n* [`pcre-light`](https://hackage.haskell.org/package/pcre-light)/[`pcre-heavy`](https://hackage.haskell.org/package/pcre-heavy)\n* [`pcre2`](https://hackage.haskell.org/package/pcre2)\n\nConsider using these if\n\n* The terseness of regex patterns is well-suited for your use case.\n* You need something very fast for typical use cases. `regex-pcre`,\n  `regex-pcre-builtin`, `pcre-light`, `pcre-heavy` are faster than\n  `parser-regex` for typical use cases, but there are trade-offs—such as losing\n  Unicode support and a risk of [ReDoS](https://en.wikipedia.org/wiki/ReDoS).\n\nUse `parser-regex` instead if\n\n* You prefer parser combinators over regex patterns\n* You need more powerful parsing capabilities than just submatch extraction\n* You need to parse a sequence that is not supported by the above libraries\n\nFor a detailed comparison of regex libraries,\n[see here](https://github.com/meooow25/parser-regex/tree/master/bench).\n\n### Other options\n\nIf you are not restricted to regexes, there are many other parsing libraries you\nmay use, too many to list here. See the\n[\"Parsing\" category on Hackage](https://hackage.haskell.org/packages/#cat:Parsing)\nfor a start.\n\n## Contributing\n\nQuestions, bug reports, documentation improvements, code contributions welcome!\nPlease [open an issue](https://github.com/meooow25/parser-regex/issues) as the\nfirst step.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeooow25%2Fparser-regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeooow25%2Fparser-regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeooow25%2Fparser-regex/lists"}