LanguageKit
LanguageKit supplies reusable tools for source-defined vocabularies: growable text, token readers, phrase-aware parsing, managed values and cross-language bindings. Import it when writing a language extension or using its native helpers directly.
First example
import language-kit
let make_message = fn () -> u8* {
let text = LanguageKit:Text:new()
if !text { return cast(u8*, 0) }
defer text.destroy()
if !text.append("Hello, ") || !text.append("RecurLoop") { return cast(u8*, 0) }
return text.take()
}
let demonstrate = fn () -> i64 {
let message = make_message()
if !message { return 1 }
defer free(message)
return strcmp(message, "Hello, RecurLoop") != 0
}
assert demonstrate() == 0Choose a facility
| Facility | Use it for |
|---|---|
Text | build owned null-terminated byte strings |
Reader | consume the active source cursor |
SliceReader | inspect a bounded, borrowed byte slice |
| Phrase readers | respect aliases and the active grammar |
Value and publish | exchange data between vocabularies |
Lifetime | scope-owned resources and weak handles |
Native pointers and runtime values have different ownership; avoid replacing a documented release operation with free merely because the representation contains a pointer.
Learning path
- Text buffers — Build strings and transfer their buffers.
- Source readers — Inspect and consume source without losing ownership.
- Grammar parsing — Respect the active phrase grammar and aliases.
- Shared values — Publish values and callbacks between vocabularies.
- Managed lifetimes — Manage adopted resources and weak references.