{"id":13393383,"url":"https://github.com/elm/parser","last_synced_at":"2025-04-05T07:08:07.938Z","repository":{"id":44335956,"uuid":"99150136","full_name":"elm/parser","owner":"elm","description":"A parsing library, focused on simplicity and great error messages","archived":false,"fork":false,"pushed_at":"2024-02-28T21:52:25.000Z","size":109,"stargazers_count":231,"open_issues_count":39,"forks_count":46,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-29T06:09:04.959Z","etag":null,"topics":["elm","parser"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/elm/parser/latest","language":"Elm","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/elm.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-08-02T18:44:48.000Z","updated_at":"2025-01-11T05:59:33.000Z","dependencies_parsed_at":"2024-06-18T21:53:02.220Z","dependency_job_id":null,"html_url":"https://github.com/elm/parser","commit_stats":{"total_commits":82,"total_committers":6,"mean_commits":"13.666666666666666","dds":"0.060975609756097615","last_synced_commit":"7506b07eaa93a93d13b508b948c016105b0953c8"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elm","download_url":"https://codeload.github.com/elm/parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299833,"owners_count":20916190,"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":["elm","parser"],"created_at":"2024-07-30T17:00:51.530Z","updated_at":"2025-04-05T07:08:07.909Z","avatar_url":"https://github.com/elm.png","language":"Elm","funding_links":[],"categories":["Elm"],"sub_categories":[],"readme":"# Parser\n\nRegular expressions are quite confusing and difficult to use. This library provides a coherent alternative that handles more cases and produces clearer code.\n\nThe particular goals of this library are:\n\n  - Make writing parsers as simple and fun as possible.\n  - Produce excellent error messages.\n  - Go pretty fast.\n\nThis is achieved with a couple concepts that I have not seen in any other parser libraries: [parser pipelines](#parser-pipelines), [backtracking](#backtracking), and [tracking context](#tracking-context).\n\n\n## Parser Pipelines\n\nTo parse a 2D point like `( 3, 4 )`, you might create a `point` parser like this:\n\n```elm\nimport Parser exposing (Parser, (|.), (|=), succeed, symbol, float, spaces)\n\ntype alias Point =\n  { x : Float\n  , y : Float\n  }\n\npoint : Parser Point\npoint =\n  succeed Point\n    |. symbol \"(\"\n    |. spaces\n    |= float\n    |. spaces\n    |. symbol \",\"\n    |. spaces\n    |= float\n    |. spaces\n    |. symbol \")\"\n```\n\nAll the interesting stuff is happening in `point`. It uses two operators:\n\n  - [`(|.)`][ignore] means “parse this, but **ignore** the result”\n  - [`(|=)`][keep] means “parse this, and **keep** the result”\n\nSo the `Point` function only gets the result of the two `float` parsers.\n\n[ignore]: https://package.elm-lang.org/packages/elm/parser/latest/Parser#|.\n[keep]: https://package.elm-lang.org/packages/elm/parser/latest/Parser#|=\n\nThe theory is that `|=` introduces more “visual noise” than `|.`, making it pretty easy to pick out which lines in the pipeline are important.\n\nI recommend having one line per operator in your parser pipeline. If you need multiple lines for some reason, use a `let` or make a helper function.\n\n\n\n## Backtracking\n\nTo make fast parsers with precise error messages, all of the parsers in this package do not backtrack by default. Once you start going down a path, you keep going down it.\n\nThis is nice in a string like `[ 1, 23zm5, 3 ]` where you want the error at the `z`. If we had backtracking by default, you might get the error on `[` instead. That is way less specific and harder to fix!\n\nSo the defaults are nice, but sometimes the easiest way to write a parser is to look ahead a bit and see what is going to happen. It is definitely more costly to do this, but it can be handy if there is no other way. This is the role of [`backtrackable`](https://package.elm-lang.org/packages/elm/parser/latest/Parser#backtrackable) parsers. Check out the [semantics](https://github.com/elm/parser/blob/master/semantics.md) page for more details!\n\n\n## Tracking Context\n\nMost parsers tell you the row and column of the problem:\n\n    Something went wrong at (4:17)\n\nThat may be true, but it is not how humans think. It is how text editors think! It would be better to say:\n\n    I found a problem with this list:\n\n        [ 1, 23zm5, 3 ]\n             ^\n    I wanted an integer, like 6 or 90219.\n\nNotice that the error messages says `this list`. That is context! That is the language my brain speaks, not rows and columns.\n\nOnce you get comfortable with the `Parser` module, you can switch over to `Parser.Advanced` and use [`inContext`](https://package.elm-lang.org/packages/elm/parser/latest/Parser-Advanced#inContext) to track exactly what your parser thinks it is doing at the moment. You can let the parser know “I am trying to parse a `\"list\"` right now” so if an error happens anywhere in that context, you get the hand annotation!\n\nThis technique is used by the parser in the Elm compiler to give more helpful error messages.\n\n\n## [Comparison with Prior Work](https://github.com/elm/parser/blob/master/comparison.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felm%2Fparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felm%2Fparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felm%2Fparser/lists"}