{"id":23747717,"url":"https://github.com/nirvanasupermind/tenrec","last_synced_at":"2026-03-10T10:30:20.406Z","repository":{"id":57376704,"uuid":"361359164","full_name":"nirvanasupermind/tenrec","owner":"nirvanasupermind","description":"Javascript parser combinator library","archived":false,"fork":false,"pushed_at":"2021-05-05T22:19:48.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-23T13:44:43.290Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/nirvanasupermind.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-04-25T07:21:25.000Z","updated_at":"2021-05-05T22:19:50.000Z","dependencies_parsed_at":"2022-08-29T21:21:16.022Z","dependency_job_id":null,"html_url":"https://github.com/nirvanasupermind/tenrec","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/nirvanasupermind%2Ftenrec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanasupermind%2Ftenrec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanasupermind%2Ftenrec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nirvanasupermind%2Ftenrec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nirvanasupermind","download_url":"https://codeload.github.com/nirvanasupermind/tenrec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239907420,"owners_count":19716615,"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-12-31T14:55:49.109Z","updated_at":"2026-03-10T10:30:20.334Z","avatar_url":"https://github.com/nirvanasupermind.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tenrec\n[![npm version](https://badge.fury.io/js/tenrec.svg)](https://badge.fury.io/js/tenrec)\u003cbr\u003e\n**tenrec** is an efficient parser combinator library for JavaScript. It is an API, not a code generation tool.\n\u003cbr\u003e\u003cbr\u003e\ntenrec has no runtime dependencies.\n\n# Examples\nThere are several examples of using tenrec that can be found in [examples](./examples) folder. \n\n# Documentation\n## `Parser`\nBase parser class. All tenrec parsers are instances of this object.\n\n\n## `Parser::parse(text)`\nParses the text, and outputs an array.\u003cbr\u003e\u003cbr\u003e\nIf the parse was successful, the first of element of array will be the parsed result, and the second element will be `null`.\u003cbr\u003e\u003cbr\u003e\nIf the parse failed, the first of element of array will be `null`, and the second element will be an error object.\n\n```js\nconsole.log(tenrec.alphaNumeric.parse(\"s\")); \n/* -\u003e [ Token { value: \"s\", pos_start: 0, pos_end: 1 }, null ] */\n\nconsole.log(tenrec.alphaNumeric.parse(\"_\")); \n/* -\u003e [ null, ParserError { pos: 0 } ] */\n```\n\n\n## `ParserError(pos)`\nClass that stores an error location.\n\n```js\nconsole.log(tenrec.ParserError(8)); //-\u003e ParserError { pos: 8 }\n```\n\n## `Token(value,pos_start,pos_end)`\nClass that stores a value and it's position in the text.\n\n```js\nconsole.log(tenrec.Token(\"a\",0,1)); \n//-\u003e Token { value: \"a\", pos_start: 0, pos_end: 1 }\n```\n\n## `alphaNumeric`\nParser that expects a character from the set `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`.\n\n```js\nconsole.log(tenrec.alphaNumeric.parse(\"s\")); \n// -\u003e [ Token { value: \"s\", pos_start: 0, pos_end: 1 }, null ]\n\nconsole.log(tenrec.alphaNumeric.parse(\"_\")); \n// -\u003e [ null, ParserError { pos: 0 } ]\n```\n\n## `any`\nParser that always succeeds with the input text and consumes it. \n\n```js\nconsole.log(tenrec.any.parse(\"foo\")); \n/* -\u003e [ Token { value: \"foo\", pos_start: 0, pos_end: 3 }, null ] */\n\nconsole.log(tenrec.any.parse(\"bar\")); \n/* -\u003e [ Token { value: \"bar\", pos_start: 0, pos_end: 3 }, null ] */\n```\n\n\n## `anyChar`\nParser that succeeds if the input text is a single character.\n```js\nconsole.log(tenrec.anyChar.parse(\"q\")); \n/* -\u003e [ Token { value: \"q\", pos_start: 0, pos_end: 1 }, null ] */\n\nconsole.log(tenrec.anyChar.parse(\"qq\"));  //-\u003e [ null, ParserError { pos: 1 } ]\n```\n\n## `charSet(chars)`\nReturns a parser that expects one of the characters.\n```js\nvar parser = tenrec.charSet(\"0123456789abc\");\nconsole.log(parser.parse(\"0\"))\n/* -\u003e [ Token { value: \"0\", pos_start: 0, pos_end: 1 }, null ] */\n\nconsole.log(parser.parse(\"1\"))\n/* -\u003e [ Token { value: \"0\", pos_start: 0, pos_end: 1 }, null ] */\n\nconsole.log(parser.parse(\"d\")) //-\u003e [ null, ParserError { pos: 0 } ]\n```\n\n## `delay(f)`\nCreates a parser from a function that is evaluated the first time the parser is used. This is useful for implementing recursive parsers.\n```js\nvar parser = tenrec.delay(() =\u003e {\n    return tenrec.either(\n        tenrec.text(\"b\"),\n        tenrec.seq(\n            tenrec.text(\"a\"),\n            parser\n        )\n    );\n});\n\nconsole.log(parser.parse(\"b\"));\n//-\u003e [ Token { value: \"b\", pos_start: 0, pos_end: 1 }, null ]\n\nconsole.log(parser.parse(\"ab\"));\n/* -\u003e [ [ Token { value: \"a\", pos_start: 0, pos_end: 1 },\n          Token { value: \"b\", pos_start: 1, pos_end: 2 } ], null ] */\n\nconsole.log(parser.parse(\"aab\"));\n/* -\u003e [ [ Token { value: \"a\", pos_start: 0, pos_end: 1 },\n          [   Token { value: \"a\", pos_start: 1, pos_end: 2 },\n              Token { value: \"b\", pos_start: 2, pos_end: 3 }] ], null ] */\n\nconsole.log(parser.parse(\"foo\"));\n// -\u003e [ null, ParserError { pos: 0 } ]\n```\n\n## `digit`\nParser that expects a character from the set `0123456789`.\n```js\nconsole.log(tenrec.digit.parse(\"0\")); \n// -\u003e  [ Token { value: \"0\", pos_start: 0, pos_end: 1 }, null ]\n\nconsole.log(tenrec.digit.parse(\"z\")); \n// -\u003e  [ null, ParserError { pos: 0 } ]\n```\n\n# License\ntenrec is licensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnirvanasupermind%2Ftenrec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnirvanasupermind%2Ftenrec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnirvanasupermind%2Ftenrec/lists"}