https://github.com/copper-leaf/kudzu
A monadic (I think...) recursive-descent parser written in Kotlin
https://github.com/copper-leaf/kudzu
Last synced: 9 months ago
JSON representation
A monadic (I think...) recursive-descent parser written in Kotlin
- Host: GitHub
- URL: https://github.com/copper-leaf/kudzu
- Owner: copper-leaf
- License: bsd-3-clause
- Created: 2018-08-08T01:07:05.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T03:20:35.000Z (over 1 year ago)
- Last Synced: 2025-04-11T21:21:43.710Z (about 1 year ago)
- Language: Kotlin
- Homepage: https://copper-leaf.github.io/kudzu/
- Size: 1.15 MB
- Stars: 23
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Kudzu
> A monadic (I think...) recursive-descent parser combinator written in Kotlin



Kudzu is a recursive-descent parser written in Kotlin, inspired by [Parsec](https://github.com/haskell/parsec), with the
goal of immutability, simplicity, testability, and multiplatform usability. It's designed to be a simple starting place
for writing smaller parsers to evaluate relatively simple grammars for other Copper-Leaf libraries, but flexible enough
to be used for larger languages.
Notable features:
- Multiplatform targets: JVM, Android, JS Legacy, JS IR, iOS
- No separate lexer/parser. You really just don't need it, so Kudzu omits it
- Parser combinator structure means every piece of your grammar is a complete parser, and thus smaller parsing units can
be tested in isolation, but the combination of them creates the full language
- Everything in Kudzu is immutable, and thus fully thread-safe
- Built on top of [DeepRecursiveFunction](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-deep-recursive-function/#:~:text=Defines%20deep%20recursive%20function%20that,function%20use%20its%20invoke%20function.&text=The%20block%20of%20code%20defines%20the%20body%20of%20a%20recursive%20function.)
to provide readable stacktraces and prevent StackOverflowErrors
- No complicated DSL or arcane combinator operators required, just normal, readable Kotlin classes. You don't need a
Ph.D. in computational linguistics or functional programming to understand a Kudzu parser
- Many useful combinators provided out of the box
- Boolean, Int, Double literals
- String and Character literals, with standard escaped characters (i.e. \n) and Unicode sequences (i.e. \u00A2)
- Identifiers
- Choice, repetition, optional higher-kinded parsers
- Parses input to an Abstract Syntax Tree (AST) and provides facilities for simplifying and/or introspecting the AST
- Line- and column-number source tracking
- Generic expression parser with all the fixin's
- Customizable operator precedence
- Operators with prefix, postfix, and infix with both left- and right-recursive associativity
- Parentheses
- Simplify deeply-nested expressions AST to simpler representation
# Supported Platforms/Features
| Platform |
|----------|
| Android |
| JVM |
| iOS |
| JS |
| WasmJS |
# Installation
```kotlin
repositories {
mavenCentral()
}
// for plain JVM or Android projects
dependencies {
implementation("io.github.copper-leaf:kudzu-core:{{gradle.version}}")
}
// for multiplatform projects
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.github.copper-leaf:kudzu-core:{{gradle.version}}")
}
}
}
}
```
# Documentation
See the [website](https://copper-leaf.github.io/kudzu/) for detailed documentation and usage instructions.
# License
Kudzu is licensed under the BSD 3-Clause License, see [LICENSE.md](https://github.com/copper-leaf/kudzu/tree/main/LICENSE.md).
# References
- [Parsec](https://github.com/haskell/parsec)
- [JParsec](https://github.com/jparsec/jparsec)