{"id":15621543,"url":"https://github.com/thosakwe/combinator","last_synced_at":"2025-04-28T14:07:19.864Z","repository":{"id":56827162,"uuid":"109247623","full_name":"thosakwe/combinator","owner":"thosakwe","description":"Parser combinators that support static typing, file spans, and more.","archived":false,"fork":false,"pushed_at":"2019-01-08T12:30:14.000Z","size":61,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-28T14:07:10.416Z","etag":null,"topics":["dart","parser","parser-combinators","parsing"],"latest_commit_sha":null,"homepage":"https://pub.dartlang.org/packages/combinator","language":"Dart","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/thosakwe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-11-02T10:03:18.000Z","updated_at":"2025-02-20T00:46:22.000Z","dependencies_parsed_at":"2022-09-20T22:11:47.153Z","dependency_job_id":null,"html_url":"https://github.com/thosakwe/combinator","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/thosakwe%2Fcombinator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thosakwe%2Fcombinator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thosakwe%2Fcombinator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thosakwe%2Fcombinator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thosakwe","download_url":"https://codeload.github.com/thosakwe/combinator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251326841,"owners_count":21571635,"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":["dart","parser","parser-combinators","parsing"],"created_at":"2024-10-03T09:41:41.672Z","updated_at":"2025-04-28T14:07:19.842Z","avatar_url":"https://github.com/thosakwe.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# combinator\n[![version](https://img.shields.io/pub/v/combinator.svg)](https://pub.dartlang.org/packages/combinator)\n[![build status](https://travis-ci.org/thosakwe/combinator.svg)](https://travis-ci.org/thosakwe/combinator)\n\nPackrat parser combinators that support static typing, generics, file spans, memoization, and more.\n\n**RECOMMENDED:**\nCheck `example/` for examples.\nThe examples contain examples of using:\n* Generic typing\n* Reading `FileSpan` from `ParseResult`\n* More...\n\n## Basic Usage\n```dart\nvoid main() {\n  // Parse a Pattern (usually String or RegExp).\n  var foo = match('foo');\n  var number = match(new RegExp(r'[0-9]+'), errorMessage: 'Expected a number.');\n  \n  // Set a value.\n  var numWithValue = number.map((r) =\u003e int.parse(r.span.text));\n  \n  // Expect a pattern, or nothing.\n  var optional = numWithValue.opt();\n  \n  // Expect a pattern zero or more times.\n  var star = optional.star();\n  \n  // Expect one or more times.\n  var plus = optional.plus();\n  \n  // Expect an arbitrary number of times.\n  var threeTimes = optional.times(3);\n  \n  // Expect a sequence of patterns.\n  var doraTheExplorer = chain([\n    match('Dora').space(),\n    match('the').space(),\n    match('Explorer').space(),\n  ]);\n  \n  // Choose exactly one of a set of patterns, whichever\n  // appears first.\n  var alt = any([\n    match('1'),\n    match('11'),\n    match('111'),\n  ]);\n  \n  // Choose the *longest* match for any of the given alternatives.\n  var alt2 = longest([\n    match('1'),\n    match('11'),\n    match('111'),\n  ]);\n  \n  // Friendly operators\n  var fooOrNumber = foo | number;\n  var fooAndNumber = foo \u0026 number;\n  var notFoo = ~foo;\n}\n```\n\n## Error Messages\nParsers without descriptive error messages can lead to frustrating dead-ends\nfor end-users. Fortunately, `combinator` is built with error handling in mind.\n\n```dart\nvoid main(Parser parser) {\n  // Append an arbitrary error message to a parser if it is not matched.\n  var withError = parser.error(errorMessage: 'Hey!!! Wrong!!!');\n  \n  // You can also set the severity of an error.\n  var asHint = parser.error(severity: SyntaxErrorSeverity.hint);\n  \n  // Constructs like `any`, `chain`, and `longest` support this as well.\n  var foo = longest([\n    parser.error(errorMessage: 'foo'),\n    parser.error(errorMessage: 'bar')\n  ], errorMessage: 'Expected a \"foo\" or a \"bar\"');\n  \n  // If multiple errors are present at one location,\n  // it can create a lot of noise.\n  //\n  // Use `foldErrors` to only take one error at a given location.\n  var lessNoise = parser.foldErrors();\n}\n```\n\n## Whitespaces\nHandling optional whitespace is dead-easy:\n\n```dart\nvoid main(Parser parser) {\n  var optionalSpace = parser.space();\n}\n```\n\n## For Programming Languages\n`combinator` was conceived to make writing parsers for complex grammars easier,\nnamely programming languages. Thus, there are functions built-in to make common constructs\neasier:\n\n```dart\nvoid main(Parser parser) {\n  var array = parser\n                .separatedByComma()\n                .surroundedBySquareBrackets(defaultValue: []);\n  \n  var braces = parser.surroundedByCurlyBraces();\n  \n  var sep = parser.separatedBy(match('!').space());\n}\n```\n\n## Differences between this and Petitparser\n* `combinator` makes extensive use of Dart's dynamic typing\n* `combinator` supports detailed error messages (with configurable severity)\n* `combinator` keeps track of locations (ex. `line 1: 3`)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthosakwe%2Fcombinator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthosakwe%2Fcombinator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthosakwe%2Fcombinator/lists"}