
Efficiently parses and evaluates arithmetic expressions, supporting custom operators and functions, enabling dynamic expression evaluation with a lightweight and easy-to-use interface.
A lightweight but powerful parser combinator library for Kotlin π
Parsikle is a Kotlin Multiplatform parser combinator library designed to make it easy (and even fun) to construct complex parsers from simple building blocks. Its goal is to be expressive, concise, and usable across platforms.
Parsikle is available on Maven Central.
implementation("io.github.gmulders.parsikle:core:0.0.4")If youβre using Kotlin Multiplatform (KMP), add it under the appropriate sourceSet:
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.github.gmulders.parsikle:core:0.0.4")
}
}
}
}For the full Parsikle docs and detailed guides, see our Overview page:
Parsikle Documentation Overview
Hereβs an example:
import io.github.gmulders.parsikle.core.*
// A number parser: one non-zero digit then any number of digits β Int,
// Note that this is a bit contrived, normally you'd use a tokenParser, that
// uses a Regex.
val number: Parsikle<Int> =
digit
.filter("Number must not start with '0'") { it != '0' }
.then(digit.many())
.map { (first, rest) ->
(listOf(first) + rest)
.joinToString("")
.toInt()
}
// A '+' parser
val plus: Parsikle<Char> = parse('+')
// An addition expression parser: Int '+' Int
val addExpr: Parsikle<Pair<Int, Int>> =
number thenIgnore plus then number
// Helper to run and print a parser result
fun <T> runParser(p: Parsikle<T>, input: String) {
val result = p(ParserState(input))
when (result) {
is Success -> println("Success β ${result.value}")
is Failure -> println("Error β ${result.error.message}")
}
}
fun main() {
runParser(number, "42") // Success β 42
runParser(addExpr, "3+7") // Success β (3, 7)
runParser(addExpr, "03+7") // Error β Number must not start with '0'
}
Thereβs also a dedicated test module with helpers and matchers:
implementation("io.github.gmulders.parsikle:parsikle-test:0.0.4")parsikle-core: The core parsing primitives and combinatorsparsikle-test: Utilities for testing parsers (e.g. assertions, golden tests)Coming soon! (KDoc, usage guide, parser recipes, etc.)
MIT Geert Mulders
A lightweight but powerful parser combinator library for Kotlin π
Parsikle is a Kotlin Multiplatform parser combinator library designed to make it easy (and even fun) to construct complex parsers from simple building blocks. Its goal is to be expressive, concise, and usable across platforms.
Parsikle is available on Maven Central.
implementation("io.github.gmulders.parsikle:core:0.0.4")If youβre using Kotlin Multiplatform (KMP), add it under the appropriate sourceSet:
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.github.gmulders.parsikle:core:0.0.4")
}
}
}
}For the full Parsikle docs and detailed guides, see our Overview page:
Parsikle Documentation Overview
Hereβs an example:
import io.github.gmulders.parsikle.core.*
// A number parser: one non-zero digit then any number of digits β Int,
// Note that this is a bit contrived, normally you'd use a tokenParser, that
// uses a Regex.
val number: Parsikle<Int> =
digit
.filter("Number must not start with '0'") { it != '0' }
.then(digit.many())
.map { (first, rest) ->
(listOf(first) + rest)
.joinToString("")
.toInt()
}
// A '+' parser
val plus: Parsikle<Char> = parse('+')
// An addition expression parser: Int '+' Int
val addExpr: Parsikle<Pair<Int, Int>> =
number thenIgnore plus then number
// Helper to run and print a parser result
fun <T> runParser(p: Parsikle<T>, input: String) {
val result = p(ParserState(input))
when (result) {
is Success -> println("Success β ${result.value}")
is Failure -> println("Error β ${result.error.message}")
}
}
fun main() {
runParser(number, "42") // Success β 42
runParser(addExpr, "3+7") // Success β (3, 7)
runParser(addExpr, "03+7") // Error β Number must not start with '0'
}
Thereβs also a dedicated test module with helpers and matchers:
implementation("io.github.gmulders.parsikle:parsikle-test:0.0.4")parsikle-core: The core parsing primitives and combinatorsparsikle-test: Utilities for testing parsers (e.g. assertions, golden tests)Coming soon! (KDoc, usage guide, parser recipes, etc.)
MIT Geert Mulders