{"id":17101423,"url":"https://github.com/valderman/konbini","last_synced_at":"2025-07-29T01:33:45.193Z","repository":{"id":66264405,"uuid":"541165376","full_name":"valderman/konbini","owner":"valderman","description":"Parser library for Kotlin","archived":false,"fork":false,"pushed_at":"2022-09-30T18:53:06.000Z","size":370,"stargazers_count":48,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-12T21:41:51.330Z","etag":null,"topics":["dsl","grammar","kotlin","kotlin-library","language","parser","parser-combinators","parsing","parsing-library","syntax-trees"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/valderman.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-25T12:33:01.000Z","updated_at":"2024-12-31T15:12:03.000Z","dependencies_parsed_at":"2023-04-13T07:16:52.218Z","dependency_job_id":null,"html_url":"https://github.com/valderman/konbini","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/valderman/konbini","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valderman%2Fkonbini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valderman%2Fkonbini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valderman%2Fkonbini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valderman%2Fkonbini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valderman","download_url":"https://codeload.github.com/valderman/konbini/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valderman%2Fkonbini/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267616582,"owners_count":24116155,"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-07-28T02:00:09.689Z","response_time":68,"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":["dsl","grammar","kotlin","kotlin-library","language","parser","parser-combinators","parsing","parsing-library","syntax-trees"],"created_at":"2024-10-14T15:25:12.471Z","updated_at":"2025-07-29T01:33:45.168Z","avatar_url":"https://github.com/valderman.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Konbini\n[![Docs](https://img.shields.io/badge/docs-latest-informational)](http://valderman.github.io/konbini/konbini/cc.ekblad.konbini/)\n[![Release](https://jitpack.io/v/cc.ekblad/konbini.svg)](https://jitpack.io/#cc.ekblad/konbini)\n![Build Status](https://github.com/valderman/konbini/workflows/CI/badge.svg)\n[![License](https://img.shields.io/github/license/valderman/konbini)](https://github.com/valderman/konbini/blob/main/LICENSE)\n\nA Kotlin multiplatform parser combinator library.\n\n## Getting started\n### Adding a Dependency on Konbini\nKonbini is hosted on Jitpack, so you need to first att the Jitpack repository\nto your build file, then add a dependency on Konbini.\n\nFor `build.gradle.kts` (Kotlin DSL):\n```kotlin\nrepositories {\n    maven {\n        url = uri(\"https://jitpack.io\")\n    }\n}\n\ndependencies {\n    implementation(\"cc.ekblad.konbini:konbini:0.1.2\")\n}\n```\n\n### A Simple Parser\nKonbini parsers are constructed from _combinators_: tiny functions which\nglue together other tiny functions into complex parsers.\n\nConsider the following parser which parses and computes expressions containing\ninteger literals and additions:\n```kotlin\nimport cc.ekblad.konbini.Parser\nimport cc.ekblad.konbini.char\nimport cc.ekblad.konbini.integer\nimport cc.ekblad.konbini.oneOf\nimport cc.ekblad.konbini.parser\nimport cc.ekblad.konbini.whitespace\n\nval addition: Parser\u003cLong\u003e = parser {\n    val lhs = expr()\n    whitespace()\n    char('+')\n    whitespace()\n    val rhs = expr()\n    return lhs + rhs\n}\nval expr: Parser\u003cLong\u003e = oneOf(integer, addition)\n```\n\nThis example makes use five basic combinators. Three of them are leaf parsers,\nor atoms:\n- `integer`, which parses any integer that can fits in a 64-bit signed `Long`;\n- `char`, which parses any one out of zero or more characters passed to it as arguments; and\n- `whitespace`, which parses zero or more whitespace characters.\n\nThe remaining two are more interesting:\n- `parser` lets you combine parsers into bigger parsers.\n  To use a parser from within a `parser` block, simply call it as a normal function.\n- `oneOf` takes zero or more parsers as arguments, and tries them all from left to right\n  until it finds one that succeeds. If none of the given parsers succeed, the `oneOf` parser fails.\n  Any parser can be passed as an argument to `oneOf`. Unlike many other parser generators and libraries\n  you may be familiar with, such as [ANTLR](https://www.antlr.org) or [GNU Bison](https://www.gnu.org/software/bison/),\n  Konbini implements arbitrary backtracking.\n\nIn addition to these, Konbini defines several other helpful parser combinators to quickly get your parser\noff the ground.\n- `regex` matches regular expressions.\n- `doubleQuotedString` and `singleQuotedString` matches quoted strings, including escape code handling.\n- `chainl` and `chainr` make it easy to define left-recursive and right-recursive parsers respectively.\n- Fore more information about the combinators available out of the box,\n  see [the API documentation](https://valderman.github.io/konbini/konbini/cc.ekblad.konbini/).\n\n### Running Your Parser\nEach Konbini parser has two extension methods which lets you apply them to arbitrary strings.\n- `parse` applies the parser to a string, reading as much of the string as it can, and returns both the result\n  and any remaining input.\n- `parseToEnd` does the same as `parse`, but returns an error if the parser did not match the _entire_ input string.\n\nBoth methods can be configured to ignore whitespace at the start and end of its input for convenience.\n\n### A More Complex Parser\nUnlike our simple example parser, most real parsers don't calculate values on the fly; they build up a syntax tree\nof some kind. For a more realistic example, the following parser uses mostly built-in functionality to implement\na complete JSON parser.\n\n```kotlin\nval comma = parser { whitespace() ; char(',') ; whitespace() }\nval colon = parser { whitespace() ; char(':') ; whitespace() }\nval pKeyValue = parser { doubleQuotedString().also { colon() } to pValue() }\nval pAtom = oneOf(decimal, doubleQuotedString, boolean, string(\"null\").map { null })\nval pArray = bracket(\n    parser { char('[') ; whitespace() },\n    parser { whitespace() ; char(']') },\n    parser { chain(pValue, comma).terms },\n)\nval pDict = bracket(\n    parser { char('{') ; whitespace() },\n    parser { whitespace() ; char('}') },\n    parser { chain(pKeyValue, comma).terms.toMap() },\n)\nval pValue: Parser\u003cAny?\u003e = oneOf(pAtom, pDict, pArray)\n```\n\nThis parser is capable of processing around 35 MB of JSON per second on an Apple M2; about the same\nspeed as the parser used for the [better-parse](https://github.com/h0tk3y/better-parse) benchmark.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalderman%2Fkonbini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalderman%2Fkonbini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalderman%2Fkonbini/lists"}