{"id":19788670,"url":"https://github.com/jaredramirez/elm-parser","last_synced_at":"2025-10-25T01:38:53.499Z","repository":{"id":62418585,"uuid":"106060037","full_name":"jaredramirez/elm-parser","owner":"jaredramirez","description":"A parser library for Elm, mostly build for learning purposes","archived":false,"fork":false,"pushed_at":"2018-02-11T00:02:23.000Z","size":112,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-11T03:52:29.828Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredramirez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-07T00:04:39.000Z","updated_at":"2022-03-29T17:49:43.000Z","dependencies_parsed_at":"2022-11-01T16:46:12.897Z","dependency_job_id":null,"html_url":"https://github.com/jaredramirez/elm-parser","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredramirez%2Felm-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredramirez%2Felm-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredramirez%2Felm-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredramirez%2Felm-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredramirez","download_url":"https://codeload.github.com/jaredramirez/elm-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241125061,"owners_count":19913839,"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":[],"created_at":"2024-11-12T06:28:16.891Z","updated_at":"2025-10-25T01:38:48.479Z","avatar_url":"https://github.com/jaredramirez.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Elm Parser\n\n\u003e General purpose parser library for Elm\n\n`elm-package install jaredramirez/elm-parser`\n\n## Usage\n```\nmodule Sample exposing (..)\n\nimport Parser exposing (Parser, (|=), (|*))\nimport Parser.Char as Char\nimport Parser.Number as Number\n\n\ntuple : Parser ( Int, Int )\ntuple =\n    Parser.parse (\\x y -\u003e ( x, y ))\n        |* Char.char '('\n        |= Number.naturalNumber\n        |* Char.char ','\n        |= Number.naturalNumber\n        |* Char.char ')'\n\nrun1 =\n  Parser.run tuple \"(3,3)\"\n\nrun2 =\n  Parser.run tuple \"(35)\"\n```\n\n`run1` will produce the value:\n\n```\nOk (3,3)\n```\n\n`run2` will produce the value:\n\n```\nErr\n    ( { source = \"(35)\"\n      , offset = 3\n      , row = 1\n      , col = 4\n      }\n    , ExpectedSymbol \",\"\n    )\n```\n\nIn the `run2` example, you are givin the `state` of the parser at the moment of failure and the `Problem` with the parse operation.\n\nYou can look all the possible values of `Problem`'s [here](https://github.com/jaredramirez/elm-parser/blob/master/src/Parser.elm#L56).\n\n## How it works\n\nTake the parser from the above example.\n\n```\ntransform : Int -\u003e Int -\u003e ( Int, Int )\ntransform x y =\n    ( x, y )\n\n\ntuple : Parser ( Int, Int )\ntuple =\n    Parser.succeed transform\n        |* Char.char '('\n        |= Number.naturalNumber\n        |* Char.char ','\n        |= Number.naturalNumber\n        |* Char.char ')'\n```\n\nFirst, we create the function `transform` that takes two `Int`s, and puts them in a tuple. Then, in the first line of the `tuple` function, we take the function `transform` and lifting it into a \"parser\".\nIn the subsequent parts of the pipline, we are applying parsers to the function `transform`.\nIf the parser in the pipline begins with\n\n* `|*` it means \"run is parser and make sure it is successful, then **throw away** the result\".\n* `|=` it means \"run is parser and make sure it is successful, then **apply** the result to the function\".\n\nThis relies on partial function application. In this case, `transform` has two arguements, so in our pipeline we must have two `|=` to get a result, otherwise `transform` won't have all of it's arguements applied!\n\nFor more on the pipeline parser concept, see [this](https://github.com/elm-tools/parser#parser-pipelines).\n\nYou can also use this library to chain parsers with `andThen`. This is generally not as readable and can be more confuisng than pipeline-style parsing. It can be helpeful to have though. Say you only want tuples where the values are equal. That is, `(1,1)` would succeed but `(1,2)` would not.\nYou can refactor `tuple` it include that functionality easily with `andThen`:\n\n```\ntuple : Parser ( Int, Int )\ntuple =\n    let\n        tupleParser =\n            Parser.succeed transform\n                |* Char.char '('\n                |= Number.naturalNumber\n                |* Char.char ','\n                |= Number.naturalNumber\n                |* Char.char ')'\n    in\n        tupleParser\n            |\u003e Parser.andThen\n                (\\( x, y ) -\u003e\n                    if x == y then\n                        Parser.succeed ( x, y )\n                    else\n                        Parser.fail \u003c|\n                            Parser.Bad \"I expected the values to match\"\n                )\n```\n\n## Thanks\n\nWhile I wrote all of the code in this package, most of it was heavily influenced/inspired by others (with the exception of `Parser.Html`). This package was written for the purpose of my learning, and I figured I'd publish it for kicks. So, a big thanks to the following as they taught me a lot about parsers in a functional language, and are great resources.\n\n* http://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf\n* https://github.com/elm-tools/parser\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredramirez%2Felm-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredramirez%2Felm-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredramirez%2Felm-parser/lists"}