{"id":13576276,"url":"https://github.com/dashbitco/nimble_parsec","last_synced_at":"2025-05-13T17:12:50.849Z","repository":{"id":37849846,"uuid":"123405590","full_name":"dashbitco/nimble_parsec","owner":"dashbitco","description":"A simple and fast library for text-based parser combinators","archived":false,"fork":false,"pushed_at":"2025-02-04T08:00:47.000Z","size":359,"stargazers_count":842,"open_issues_count":4,"forks_count":52,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-03T01:57:20.366Z","etag":null,"topics":["binary","elixir","parser-combinator"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/dashbitco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2018-03-01T08:31:07.000Z","updated_at":"2025-05-01T09:57:45.000Z","dependencies_parsed_at":"2023-12-06T05:22:57.848Z","dependency_job_id":"a6b88097-389c-4b13-abf3-9bf334dc77b6","html_url":"https://github.com/dashbitco/nimble_parsec","commit_stats":{"total_commits":224,"total_committers":38,"mean_commits":5.894736842105263,"dds":0.4553571428571429,"last_synced_commit":"7f56984902f14bc7e37575a3fa4086eacb4cca6a"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashbitco%2Fnimble_parsec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashbitco%2Fnimble_parsec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashbitco%2Fnimble_parsec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashbitco%2Fnimble_parsec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashbitco","download_url":"https://codeload.github.com/dashbitco/nimble_parsec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990482,"owners_count":21995775,"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":["binary","elixir","parser-combinator"],"created_at":"2024-08-01T15:01:08.750Z","updated_at":"2025-05-13T17:12:50.806Z","avatar_url":"https://github.com/dashbitco.png","language":"Elixir","readme":"# NimbleParsec\n\n[![CI](https://github.com/dashbitco/nimble_parsec/actions/workflows/ci.yml/badge.svg)](https://github.com/dashbitco/nimble_parsec/actions/workflows/ci.yml)\n[![Module Version](https://img.shields.io/hexpm/v/nimble_parsec.svg)](https://hex.pm/packages/nimble_parsec)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/nimble_parsec)\n\n\u003c!-- MDOC !--\u003e\n\n`NimbleParsec` is a simple and fast library for text-based parser\ncombinators.\n\nCombinators are composed programmatically and compiled into multiple\nclauses with binary matching. This provides the following benefits:\n\n  * Performance: since it compiles to binary matching, it leverages\n    many Erlang VM optimizations to generate a fast parser code with\n    low memory usage\n\n  * Composable: this library does not rely on macros for building and\n    composing parsers, therefore they are fully composable. The only\n    macros are `defparsec/3` and `defparsecp/3` which emit the compiled\n    clauses with  binary matching\n\n  * No runtime dependency: after compilation, the generated parser\n    clauses have no runtime dependency on `NimbleParsec`. This opens up\n    the possibility to compile parsers and do not impose a dependency on\n    users of your library\n\n  * No footprints: `NimbleParsec` only needs to be imported in your modules.\n    There is no need for `use NimbleParsec`, leaving no footprints on your\n    modules\n\nThe goal of this library is to focus on a set of primitives for writing\nefficient parser combinators. The composition aspect means you should be\nable to use those primitives to implement higher level combinators.\n\nNote this library does not handle low-level binary parsing. In such cases,\nwe recommend using [Elixir's bitstring syntax](https://hexdocs.pm/elixir/Kernel.SpecialForms.html#%3C%3C%3E%3E/1).\n\n## Examples\n\n```elixir\ndefmodule MyParser do\n  import NimbleParsec\n\n  date =\n    integer(4)\n    |\u003e ignore(string(\"-\"))\n    |\u003e integer(2)\n    |\u003e ignore(string(\"-\"))\n    |\u003e integer(2)\n\n  time =\n    integer(2)\n    |\u003e ignore(string(\":\"))\n    |\u003e integer(2)\n    |\u003e ignore(string(\":\"))\n    |\u003e integer(2)\n    |\u003e optional(string(\"Z\"))\n\n  defparsec :datetime, date |\u003e ignore(string(\"T\")) |\u003e concat(time), debug: true\nend\n\nMyParser.datetime(\"2010-04-17T14:12:34Z\")\n#=\u003e {:ok, [2010, 4, 17, 14, 12, 34, \"Z\"], \"\", %{}, {1, 0}, 20}\n```\n\nIf you add `debug: true` to `defparsec/3`, it will print the generated\nclauses, which are shown below:\n\n```elixir\ndefp datetime__0(\u003c\u003cx0, x1, x2, x3, \"-\", x4, x5, \"-\", x6, x7, \"T\",\n                   x8, x9, \":\", x10, x11, \":\", x12, x13, rest::binary\u003e\u003e,\n                 acc, stack, comb__context, comb__line, comb__column)\n     when x0 \u003e= 48 and x0 \u003c= 57 and (x1 \u003e= 48 and x1 \u003c= 57) and\n         (x2 \u003e= 48 and x2 \u003c= 57) and (x3 \u003e= 48 and x3 \u003c= 57) and\n         (x4 \u003e= 48 and x4 \u003c= 57) and (x5 \u003e= 48 and x5 \u003c= 57) and\n         (x6 \u003e= 48 and x6 \u003c= 57) and (x7 \u003e= 48 and x7 \u003c= 57) and\n         (x8 \u003e= 48 and x8 \u003c= 57) and (x9 \u003e= 48 and x9 \u003c= 57) and\n         (x10 \u003e= 48 and x10 \u003c= 57) and (x11 \u003e= 48 and x11 \u003c= 57) and\n         (x12 \u003e= 48 and x12 \u003c= 57) and (x13 \u003e= 48 and x13 \u003c= 57) do\n  datetime__1(\n    rest,\n    [(x13 - 48) * 1 + (x12 - 48) * 10, (x11 - 48) * 1 + (x10 - 48) * 10,\n     (x9 - 48) * 1 + (x8 - 48) * 10, (x7 - 48) * 1 + (x6 - 48) * 10, (x5 - 48) * 1 + (x4 - 48) * 10,\n     (x3 - 48) * 1 + (x2 - 48) * 10 + (x1 - 48) * 100 + (x0 - 48) * 1000] ++ acc,\n    stack,\n    comb__context,\n    comb__line,\n    comb__column + 19\n  )\nend\n\ndefp datetime__0(rest, acc, _stack, context, line, column) do\n  {:error, \"...\", rest, context, line, column}\nend\n\ndefp datetime__1(\u003c\u003c\"Z\", rest::binary\u003e\u003e, acc, stack, comb__context, comb__line, comb__column) do\n  datetime__2(rest, [\"Z\"] ++ acc, stack, comb__context, comb__line, comb__column + 1)\nend\n\ndefp datetime__1(rest, acc, stack, context, line, column) do\n  datetime__2(rest, acc, stack, context, line, column)\nend\n\ndefp datetime__2(rest, acc, _stack, context, line, column) do\n  {:ok, acc, rest, context, line, column}\nend\n```\n\nAs you can see, it generates highly inlined code, comparable to\nhand-written parsers. This gives `NimbleParsec` an order of magnitude\nperformance gains compared to other parser combinators. Further performance\ncan be gained by giving the `inline: true` option to `defparsec/3`.\n\n\u003c!-- MDOC !--\u003e\n\n## Installation\n\nAdd `nimble_parsec` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:nimble_parsec, \"~\u003e 1.0\"}\n  ]\nend\n```\n\n## Nimble*\n\nAll nimble libraries by Dashbit:\n\n  * [NimbleCSV](https://github.com/dashbitco/nimble_csv) - simple and fast CSV parsing\n  * [NimbleOptions](https://github.com/dashbitco/nimble_options) - tiny library for validating and documenting high-level options\n  * [NimbleParsec](https://github.com/dashbitco/nimble_parsec) - simple and fast parser combinators\n  * [NimblePool](https://github.com/dashbitco/nimble_pool) - tiny resource-pool implementation\n  * [NimblePublisher](https://github.com/dashbitco/nimble_publisher) - a minimal filesystem-based publishing engine with Markdown support and code highlighting\n  * [NimbleTOTP](https://github.com/dashbitco/nimble_totp) - tiny library for generating time-based one time passwords (TOTP)\n\n## License\n\nCopyright 2018 Plataformatec \\\nCopyright 2020 Dashbit\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n      http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n","funding_links":[],"categories":["Elixir"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashbitco%2Fnimble_parsec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashbitco%2Fnimble_parsec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashbitco%2Fnimble_parsec/lists"}