{"id":13998492,"url":"https://github.com/sufianrhazi/parsinator","last_synced_at":"2025-09-24T15:46:45.877Z","repository":{"id":57319715,"uuid":"91850027","full_name":"sufianrhazi/parsinator","owner":"sufianrhazi","description":"parser combinators for typescript and javascript","archived":false,"fork":false,"pushed_at":"2022-09-23T03:21:38.000Z","size":221,"stargazers_count":12,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-18T04:09:07.220Z","etag":null,"topics":["javascript","parser","parser-combinators","parsing","typescript"],"latest_commit_sha":null,"homepage":"https://abstract.properties/work/parsinator.html","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/sufianrhazi.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":"2017-05-19T22:29:27.000Z","updated_at":"2024-06-29T03:32:31.000Z","dependencies_parsed_at":"2022-08-25T20:22:33.694Z","dependency_job_id":null,"html_url":"https://github.com/sufianrhazi/parsinator","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/sufianrhazi/parsinator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sufianrhazi%2Fparsinator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sufianrhazi%2Fparsinator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sufianrhazi%2Fparsinator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sufianrhazi%2Fparsinator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sufianrhazi","download_url":"https://codeload.github.com/sufianrhazi/parsinator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sufianrhazi%2Fparsinator/sbom","scorecard":{"id":857453,"data":{"date":"2025-08-11","repo":{"name":"github.com/sufianrhazi/parsinator","commit":"39ab57c6a6c8ac378b959794851fbc686254a7e9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.1,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":3,"reason":"7 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T00:14:59.612Z","repository_id":57319715,"created_at":"2025-08-24T00:14:59.612Z","updated_at":"2025-08-24T00:14:59.612Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276112117,"owners_count":25587271,"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","status":"online","status_checked_at":"2025-09-20T02:00:10.207Z","response_time":63,"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":["javascript","parser","parser-combinators","parsing","typescript"],"created_at":"2024-08-09T19:01:43.186Z","updated_at":"2025-09-24T15:46:45.822Z","avatar_url":"https://github.com/sufianrhazi.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Parsinator\n\nParsinator lets you build small well-defined parsers in JavaScript or TypeScript which can be combined together to\naccomplish just about any parsing task.\n\n\n## Installation\n\nInstall from the [npm published package](https://www.npmjs.com/package/parsinator):\n\n```bash\nnpm install parsinator\n```\n\n\n## What it does\n\nParsinator uses [parser combinators](https://en.wikipedia.org/wiki/Parser_combinator) to build structured data from\nstring input. Unlike other ways of parsing data, Parser Combinators are:\n\n* **Maintainable**: designed to be read and written by humans, unlike regular expressions which are designed to be\n  executable by machines.\n* **Reusable**: complex parsers are built from smaller pieces, which are each responsible for parsing individual parts.\n* **Debuggable**: parse failures provide a detailed error message which shows what the parser was expecting.\n* **Powerful**: can match/extract data which is impossible (like equal nesting) for regular expressions to parse.\n\nParsinator is inspired by the excellent [parsec](https://github.com/aslatter/parsec) Haskell library.\n\nParsinator allows you to easily define and combine parsers to produce structured data from string input.\n\n\n## Example\n\nHere's a small text parser that parses a greeting between a matching number of `\u003c` and `\u003e` characters:\n\n```ts\nimport * as Parsinator from 'parsinator';\n\nconst greeting = Parsinator.fromGenerator(function *() {\n    const exclamations = yield* Parsinator.many(Parsinator.str(\"\u003c\"));\n    const intro = yield* Parsinator.regex(/[hH]ello, /);\n    const who = yield* Parsinator.until(Parsinator.str(\"!\"));\n    yield* Parsinator.count(exclamations.length, Parsinator.str(\"\u003e\"));\n    return {\n        who: who,\n        excitement: exclamations.length\n    };\n});\n\nParsinator.runToEnd(greeting, \"\u003cHello, Parsinator\u003e\");\n// { who: \"Parsinator\", excitement: 1 }\nParsinator.runToEnd(greeting, \"\u003c\u003c\u003c\u003chello, stranger\u003e\u003e\u003e\u003e\");\n// { who: \"stranger\", excitement: 4 }\n```\n\n\n## Documentation\n\nThe main abstraction is the `Parser\u003cT\u003e` type, which represents a parser which _consumes_ some amount of a string input,\nand produces an arbitrary value (of type `T`) as a result of parsing the string text.\n\n\n### Building blocks\n\nThe following building blocks can be used to build both simple and parsers.\n\n\n#### `function regex(re: RegExp): Parser\u003cstring\u003e`\n\nConsume and produce the full string match from a regular expression.\n\n\n#### `function regexMatch(regex: RegExp): Parser\u003cstring[]\u003e;`\n\nConsume and produce the full match and all groups from a regular expression.\n\nProduces a string array; item 0 is the full match, subsequent items are the regular expression matched groups.\n\n\n#### `function str\u003cT extends string\u003e(string: T): Parser\u003cT\u003e;`\n\nConsume and produce a string value.\n\n\n#### `function fromGenerator\u003cP, V\u003e(generator: () =\u003e Generator\u003cnumber | ParseState, V, ParseState\u003e): Parser\u003cV\u003e;`\n\nCreate a custom parser for a generator function. This is the recommended approach for building parsers. For example,\nhere's how to parse a word surrounded by any number of matching parenthesis:\n\n```ts\nconst parenMatcher = Parsinator.fromGenerator(function* () {\n  const maybeOpen = Parsinator.maybe(Parsinator.str('('));\n  let parenCount = 0;\n  let match = yield* maybeOpen;\n  while (match !== null) {\n    parenCount += 1;\n    match = yield* maybeOpen;\n  }\n  const name = yield* Parsinator.regex(/[a-zA-Z]+/);\n  for (let i = 0; i \u003c parenCount; ++i) {\n    yield* Parsinator.str(')');\n  }\n  return match;\n});\n\nParsinator.run(parenMatcher, '(((three)))'); // evaluates to 'three'\nParsinator.run(parenMatcher, '(one)'); // evaluates to 'one'\n\nParsinator.run(parenMatcher, '((two)'); // Fails with:\n// Error: Parse failure at 1:7: \")\" not found\n//   -\u003e «((two)»\n//            ^\n```\n\n**Running sub-parsers**\n\nParsers are executed with a `yield*` expression. The parser is executed and the expression evaluates to the produced\nvalue of the parser.\n\n\n**Changing parse state**\n\nParsers may obtain the state of the parser via `yield 0`. Parse state is an object containing:\n`{ input: string, offset: number }`.\n\nParsers may advance the offset by a number of characters via `yield numChars` where `numChars` is a number.\n\nParsers may reset state to a prior state by `yield priorState`.\n\nIf a parser fails, an exception is thrown. Note: the state of the parser is *not* reset after an exception if caught,\nit's up to the caller to save and restore parse state.\n\n\n#### `function fail\u003cT\u003e(message: string): Parser\u003cT\u003e;`\n\nCreate a parser which consumes nothing and always fails with a specific error message.\n\n\n#### `function wrapFail\u003cT\u003e(parser: Parser\u003cT\u003e, wrapper: (message: string) =\u003e string): Parser\u003cT\u003e;`\n\nCreate a parser which acts like the passed parser, but when fails, provides an alternate error message.\n\n\n#### `function debugTrace(log: (str: string) =\u003e void): Parser\u003cundefined\u003e;`\n\nA parser which consumes nothing and produces `undefined`. Helpful to log inside a parser.\n\n\n#### `const end: Parser\u003cnull\u003e;`\n\nA parser which consumes nothing, but successfully produces `null` when at the end of input and fails if there is more\ninput.\n\n\n### Running parsers\n\nOnce a parser is created, the parser can be performed via these functions.\n\n\n#### `function run\u003cT\u003e(parser: Parser\u003cT\u003e, input: string): T;`\n\nRun a parser on an input string, returning the parser's produced value.\n\nNote: the parser does not need to consume the entire input string.\n\n\n#### `function runToEnd\u003cT\u003e(parser: Parser\u003cT\u003e, input: string): T;`\n\nRun a parser on an input string, returning the parser's produced value.\n\nFails if the parser does not consume the entire input string.\n\n\n### Parser combinator helpers\n\nThese functions are helpers for common parsers.\n\n\n#### `function maybe\u003cP\u003e(parser: Parser\u003cP\u003e): Parser\u003cP | null\u003e;`\n\nCreate a parser which acts like the provided parser, but produces null if it fails.\n\n\n#### `function many\u003cP\u003e(parser: Parser\u003cP\u003e): Parser\u003cP[]\u003e;`\n\nCreate a parser which produces an array of items by applying the provided parser any number of times (including zero).\n\n\n#### `function many1\u003cP\u003e(parser: Parser\u003cP\u003e): Parser\u003cP[]\u003e;`\n\nCreate a parser which produces an array of items by applying the provided parser one or more times.\n\n\n#### `function choice\u003cV\u003e(parsers: Parser\u003cV\u003e[]): Parser\u003cV\u003e;`\n\nCreate a parser which produces the first successful result of matching the provided parsers.\n\n\n#### `function sequence\u003cV\u003e(parsers: Parser\u003cV\u003e[]): Parser\u003cV[]\u003e;`\n\nCreate a parser which produces an array of results, provided by running the provided parsers in sequence.\n\n\n#### `function count\u003cV\u003e(num: number, parser: Parser\u003cV\u003e): Parser\u003cV[]\u003e;`\n\nCreate a parser which produces an array of values by running the provided parser a specific number of times.\n\n\n#### `function sepBy1\u003cS, V\u003e(sepParser: Parser\u003cS\u003e, valParser: Parser\u003cV\u003e): Parser\u003cV[]\u003e;`\n\nCreate a parser which produces an array of desired values separated discarded separators.\n\nIf no values are found, the parser fails.\n\n\nFor example, this parses comma separated words:\n\n```ts\nconst commaSeparatedDigits = Parsinator.sepBy1(Parsinator.str(','), Parsinator.regex(/[a-z]+/));\n\nParsinator.runToEnd(commaSeparatedDigits, 'foo,bar,baz'); // evaluates to ['foo', 'bar', 'baz']\n```\n\n\n#### `function sepBy\u003cS, V\u003e(sepParser: Parser\u003cS\u003e, valParser: Parser\u003cV\u003e): Parser\u003cV[]\u003e;`\n\nCreate a parser which produces an array of desired values separated discarded separators.\n\nIf no values are found, the parser produces an empty array.\n\n\n#### `function peek\u003cP\u003e(parser: Parser\u003cP\u003e): Parser\u003cP\u003e;`\n\nCreate a parser which produces a value by running the provided parser, but does not advance state.\n\nNote: If an error occurs, it will still raise an exception. Use `maybe` in addition to avoid the error.\n\n\n#### `function until\u003cT\u003e(terminator: Parser\u003cT\u003e): Parser\u003cstring\u003e;`\n\nCreate a parser which produces a string that spans until the provided terminator is parsed.\n\n\n#### `function between\u003cT\u003e(start: Parser\u003cT\u003e, end: Parser\u003cT\u003e): Parser\u003cstring\u003e;`\n\nCreate a parser which produces a string that spans from the provided start parser to the provided end parser.\n\n\n#### `function map\u003cV, W\u003e(parser: Parser\u003cV\u003e, fn: (val: V) =\u003e W): Parser\u003cW\u003e;`\n\nCreate a parser which produces a transformed value from a provided parser.\n\n\n#### `function surround\u003cL, T, R\u003e(left: Parser\u003cL\u003e, val: Parser\u003cT\u003e, right: Parser\u003cR\u003e): Parser\u003cT\u003e;`\n\nCreate a parser which produces a value surrounded by a provided prefix and suffix parser.\n\nFor example, this parser returns a word surrounded by parenthesis:\n\n```ts\nconst parenthetical = Parsinator.surround(Parsinator.str('('), Parsinator.regex(/[a-z]+/), Parsinator.str(')'));\n\nParsinator.run(parenthetical, '(howdy)'); // evaluates to: 'howdy'\n```\n\n#### `function buildExpressionParser\u003cT\u003e(operators: OperatorDecls\u003cT\u003e, parseTermFactory: () =\u003e Parser\u003cT\u003e): Parser\u003cT\u003e;`\n\nProduce a parser which can parse arbitrary binary and unary expressions.\n\n`buildExpressionParser` deals with the heavy lifting of dealing with operator fixity, precedence, and associativity.\n\nAs an example, here's a very simple arithmetic parser:\n\n```ts\nvar number = Parsinator.map(Parsinator.regex(/[0-9]+/), (str) =\u003e parseInt(str, 10));\n\nvar operator = (opstr, action) =\u003e Parsinator.map(Parsinator.str(opstr), () =\u003e action);\n\nvar negate = operator('-', (val) =\u003e -val);\nvar sum = operator('+', (x, y) =\u003e x + y);\nvar multiply = operator('*', (x, y) =\u003e x * y);\nvar exponent = operator('^', (x, y) =\u003e Math.pow(x, y));\n\nvar evaluate = Parsinator.buildExpressionParser([\n    { fixity: \"prefix\", parser: negate },\n    { fixity: \"infix\", associativity: \"right\", parser: exponent },\n    { fixity: \"infix\", associativity: \"left\", parser: multiply },\n    { fixity: \"infix\", associativity: \"left\", parser: sum }\n], () =\u003e Parsinator.choice([\n    Parsinator.surround(Parsinator.str(\"(\"), evaluate, Parsinator.str(\")\")),\n    number\n]));\n\nParsinator.runToEnd(evaluate, \"1+2*3+1\"); // evaluates to 8\nParsinator.runToEnd(evaluate, \"(1+2)*-(3+1)\"); // evaluates to -12\nParsinator.runToEnd(evaluate, \"3^3^3\"); // evaluates to 7625597484987\n```\n\n\n## Upgrading from Version 1 to Version 2\n\nNote: Version 2 does not support ES5.\n\nVersion 2 uses TypeScript features only available in version 3.6, in order to allow for correct typing of generators.\nThis required an API change and a language runtime that supports the `yield*` keyword.\n\nTo upgrade, change all your `fromGenerator` calls that contain `yield` so that they are `yield*`.\n\nIf you wrote custom parsers which take and return state, you must use generators now.\n* `yield 0` retrieves the current state\n* `yield number` increments the offset by number\n* `yield state` sets the state to the new state\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsufianrhazi%2Fparsinator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsufianrhazi%2Fparsinator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsufianrhazi%2Fparsinator/lists"}