Utilities for Koka: a small library for string templating and parser helpers.
util-kk is a lightweight Koka library intended for personal projects and
downstream flakes. It currently provides:
- string interpolation helpers for named and positional placeholders
- parser utilities built around
std/text/parse - a convenient
showimplementation for parse results - a
lexhelper that consumes trailing whitespace for token-based grammars
This library helps when you want cleaner formatting and simpler parsing code in Koka without pulling in a larger framework.
Common examples include:
- building user-facing strings with
%nameand%1placeholders - writing small recursive-descent parsers without repeating whitespace handling
- rendering parse results in a readable, debug-friendly form
From another Koka project:
koki add LitFill:util-kkinputs.util-kk.url = "github:LitFill/util-kk";Then expose the library to your Koka build:
kokaLibsFor = pkgs: [
self.inputs.util-kk.kokaLibraries.${pkgs.stdenv.hostPlatform.system}.util.includePath
];The library is imported as:
import utilval greeting = "%greeting, %name!"!^("greeting", "Hello")!^("name", "World")
println(greeting) // Hello, World!
val summary = "%user logged in from %host"!^^[("user", "LitFill"), ("host", "localhost")]
println(summary) // LitFill logged in from localhost
println("%1 + %2 = %3"%^ [1, 2, 3]) // 1 + 2 = 3The library includes helpers for std/text/parse, including lex and token:
import std/text/parse
import util
fun binding() : parse (string, int)
token("let")
val name = lex({ many1(alpha).string })
token("=")
val value = lex(pint)
(name, value)This pattern is demonstrated in example.kk.
The repository includes a small example program:
example.kk— demonstrates string interpolation and parser helpers
Run it with:
nix develop
koka -e example.kksrc/util.kk— the library itselfexample.kk— example usageflake.nix— Nix build and flake outputs for downstream consumers
koki build # nix build
koki check # nix flake check
koki dev # nix developThis project is licensed under the MIT License.