{"id":19681951,"url":"https://github.com/higherorderco/hop","last_synced_at":"2025-04-29T05:30:23.222Z","repository":{"id":135502756,"uuid":"597461307","full_name":"HigherOrderCO/HOP","owner":"HigherOrderCO","description":"Lightweight, higher-order parser in Rust.","archived":false,"fork":false,"pushed_at":"2023-02-04T17:19:26.000Z","size":8,"stargazers_count":12,"open_issues_count":0,"forks_count":6,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-05T13:11:21.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/HigherOrderCO.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-04T16:18:03.000Z","updated_at":"2024-12-13T09:11:26.000Z","dependencies_parsed_at":"2024-06-07T14:15:30.993Z","dependency_job_id":null,"html_url":"https://github.com/HigherOrderCO/HOP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HigherOrderCO%2FHOP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HigherOrderCO%2FHOP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HigherOrderCO%2FHOP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HigherOrderCO%2FHOP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HigherOrderCO","download_url":"https://codeload.github.com/HigherOrderCO/HOP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251444018,"owners_count":21590398,"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-11T18:09:12.314Z","updated_at":"2025-04-29T05:30:23.214Z","avatar_url":"https://github.com/HigherOrderCO.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Higher Order Parser\n===================\n\nHOP is a lightweight, higher-order parser in Rust.\n\nHi-Parser provides a more Haskell-like parser style, and explores the `?` syntax\nof `Result` to have a do-block-like monadic notation. This isn't as good as a\nproper do notation, but avoids identation hell. For example, a lambda, in a\nfunctional language, can be parsed as:\n\n```rust\n// Parses a λ-term in the syntax: `λx =\u003e body`\npub fn parse_lam(state: parser::State) -\u003e parser::Answer\u003cOption\u003cBox\u003cTerm\u003e\u003e\u003e {\n  let (state, _)    = parser::there_take_exact(\"λ\")?;\n  let (state, name) = parser::there_nonempty_name(state)?;\n  let (state, _)    = parser::there_take_exact(\"=\u003e\")?;\n  let (state, body) = parse_term(state)?;\n  Ok((state, Box::new(Term::Lam { name, body })))\n}\n```\n\nA Parser is defined simply as:\n\n```rust\nAnswer\u003cA\u003e = Result\u003c(State, A), String\u003e\nParser\u003cA\u003e = Fn(State) -\u003e Answer\u003cA\u003e\u003e\n```\n\nThat is, a Parser is a function that receives a `State` and returns an `Answer`.\nThat answer is either an updated state, and the parse result (if it succeeds),\nor an error message, as a simple string, if it fails. Note that there are two\nways to fail:\n\n### 1. Recoverable. Return an `Ok` with a `Bool`, or an `Option`:\n\n```rust\n- Ok((new_state, Some(result))) if it succeeds\n- Ok((old_state, None))         if it fails\n```\n\nThis backtracks, and can be used to implement alternatives. For example, if\nyou're parsing an AST, \"Animal\", with 2 constructors, dog and cat, then you\ncould implement:\n\n```rust\nparse_dog    : Parser\u003cOption\u003cAnimal\u003e\u003e\nparse_cat    : Parser\u003cOption\u003cAnimal\u003e\u003e\nparse_animal : Parser\u003cAnimal\u003e\n```\n\n### 2. Irrecoverable. Return an `Err` with a message:\n\n```rust\n- Err(error_message)\n```\n\nThis will abort the entire parser, like a \"throw\", and return the error message.\nUse this when you know that only one parsing branch can reach this location, yet\nthe source is wrong.\n\n---\n\nThis parser is used by [HVM](https://github.com/HigherOrderCO/hvm).\n\nNote: this parser is in very early stage and provides very few features.\n\nTODO: add examples, improve documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhigherorderco%2Fhop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhigherorderco%2Fhop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhigherorderco%2Fhop/lists"}