{"id":32119067,"url":"https://github.com/keean/applicative_parser","last_synced_at":"2026-07-13T20:31:12.757Z","repository":{"id":62422231,"uuid":"385342354","full_name":"keean/applicative_parser","owner":"keean","description":"parser combinators applicative TypeScript deno module","archived":false,"fork":false,"pushed_at":"2021-08-14T13:22:22.000Z","size":115,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T18:00:51.233Z","etag":null,"topics":["parser","parser-combinators","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keean.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}},"created_at":"2021-07-12T18:15:51.000Z","updated_at":"2022-12-08T21:06:27.000Z","dependencies_parsed_at":"2022-11-01T17:33:02.205Z","dependency_job_id":null,"html_url":"https://github.com/keean/applicative_parser","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/keean/applicative_parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keean%2Fapplicative_parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keean%2Fapplicative_parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keean%2Fapplicative_parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keean%2Fapplicative_parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keean","download_url":"https://codeload.github.com/keean/applicative_parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keean%2Fapplicative_parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35436278,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-13T02:00:06.543Z","response_time":119,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["parser","parser-combinators","typescript"],"created_at":"2025-10-20T18:00:23.410Z","updated_at":"2026-07-13T20:31:12.747Z","avatar_url":"https://github.com/keean.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# applicative_parser\n*parser combinators applicative TypeScript deno module*\n\nThe applicative approach to parsing has benefits compared to the monadic approach,\nit separates the structure of the parser from the implementation. This allows different\nimplementations to be used (for example with or without backtracking, or error recovery)\nwithout changing the use of the application of the parser. It also allows other algorithms\nover the parser applications such as pretty-printing or symbol extraction.\n\nThese features cannot be implemented with a monadic parser because the second argument of\nmonadic-bind is a function, and hence opaque.\n\nKey features:\n\n- no external dependencies\n- able to extract all valid symbols from parser\n- allows pretty printing\n- supports multiple evaluation strategies (backtracking vs non-backtracking etc)\n\nBased on \"Notes on Computing\", \"Applicative Parsing\" in ML :\n\n\u003chttps://jobjo.github.io/2019/05/19/applicative-parsing.html\u003e\n\nUsing existential encoding from \"Existential Quantification in TypeScript\"\nto encode the GADT used in \"Applicative Parsing\"\n\n\u003chttps://unsafe-perform.io/posts/2020-02-21-existential-quantification-in-typescript\u003e\n\nHere is an example parser for floating point numbers:\n\n```ts\nconst digit = OneOf('0123456789');\nconst float1 = seqMap((a, b) =\u003e [...a, b], many1(digit), OneOf('.'));\nconst float2 = seqMap((a, b) =\u003e [...a, ...b], float1, many1(digit));\nconst float3 = seqMap((a, b, c) =\u003e [...a, b, ...c], choice(float2, many1(digit)), OneOf('e'), many1(digit));\nexport const float: Parser\u003cunknown,number\u003e = FMap(a =\u003e parseFloat(a.join('')), choice(float3, float2, float1));\n}\n```\nThis parser can be compiled into a function:\n```ts\nconst floatParser = parse(float);\n```\n`parse` is just one possible compiler, as the static parser definition (in this case float) does\nnot depend on the implementation of `parse`, you can replace `parse` with a different implementation\nof the parser (say with no backtracking, or better error reporting) _without_ chaning the definiton\nof `float` at all.\n\nThe supplied `parse` compiler produces a parser with the following type:\n```ts\ntype Parse\u003cA,B\u003e = (_: {cs: string, pos: number, args: A}) =\u003e {result: B, cs: string, pos: number}|null;\n```\nSo the parser can be applied to an input string as follows:\n```ts\nconst parsed = floatParser({cs: '123.456e2', pos: 0});\n```\nThe output `parsed` would then be:\n```ts\n{cs: '123.456e2', pos: 9, result: 12345.6}\n```\n`cs` is the complete input string, `pos` is the final position of the parser, and these can be used as the input to further parsers, alhough it would be better to build all the logic into a single parser as any needed logic can be\nexpressed using the parser combinators. A `null` will be returned if the parser failed.\n\nBelow is the result of `show(float)` but with the functions in the maps replaced with `?`, to show that the \nwhole structure of the parser is static, and transparent (unlike with the monadic approach). The helper functions like\n`choice` and `seqMap` are all represented by the combinators in the initial algebra.\n```ts\nFMap(?, (Either(FMap(?, (FMap(?, (Product(FMap(?, (Either(FMap(?, (FMap(?, (Product(FMap(?, (FMap(?, (FMap(?, (Product(FMap(?, (FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fix(Either(FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fail(''))), Return()))))), FMap(?, (Product(FMap(?, (OneOf('.')), Return())))))), FMap(?, (Product(FMap(?, (FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fix(Either(FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fail(''))), Return()))))), Return()))))), Either(FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fix(Either(FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fail(''))), Return())))), Fail('')))), FMap(?, (Product(FMap(?, (OneOf('e')), FMap(?, (Product(FMap(?, (FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fix(Either(FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fail(''))), Return()))))), Return()))))))), Either(FMap(?, (FMap(?, (Product(FMap(?, (FMap(?, (FMap(?, (Product(FMap(?, (FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fix(Either(FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fail(''))), Return()))))), FMap(?, (Product(FMap(?, (OneOf('.')), Return())))))), FMap(?, (Product(FMap(?, (FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fix(Either(FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fail(''))), Return()))))), Return()))))), Either(FMap(?, (FMap(?, (Product(FMap(?, (FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fix(Either(FMap(?, (Product(FMap(?, (OneOf('0123456789')), Fail(''))), Return()))))), FMap(?, (Product(FMap(?, (OneOf('.')), Return()))))), Fail('')))))\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeean%2Fapplicative_parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeean%2Fapplicative_parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeean%2Fapplicative_parser/lists"}