waozi cb1fe01ec7 Tokenize Ziran, C, and Make source as a standalone package
The tokenizer moves out of Kryon so any Ziran program can use it without
a UI dependency. It reports token kinds and byte ranges and colors them
into caller-owned SyntaxColorSpan values, which have the same fields as
Kryon's TextAreaColorSpan.
2026-09-29 19:44:33 -03:00

Syntax

Syntax is a small Ziran package that tokenizes Ziran, C, and Make source. It reports each token's byte range and kind (keyword, string, number, path, comment, whitespace, or plain text) and can color the tokens for a light or dark background. It allocates nothing: callers pass the text and own the output spans.

Use it

ziran add https://github.com/ziranlang/syntax.git
#import "syntax/Syntax"

using SyntaxMode;

spans: [256]SyntaxColorSpan
result: SyntaxSpansResult = SyntaxColorSpans(source, cast(SyntaxMode)SyntaxZiran,
    background, foreground, spans[:])
// spans[0:result.count] cover the text; result.complete is false when the
// output was too short.

SyntaxTokenAt scans one token at a time for editors that keep their own line state. A SyntaxColorSpan has the same start, end, and color fields as a Kryon TextAreaColorSpan, so a Kryon app copies them into its TextArea props.

Develop

make check checks the package and runs its tests as C and as a portable bundle. It uses the ziran launcher and the compiler pinned in ziran.lock. Put a Ziran checkout next to this one, or copy ziran.local.toml from the example below, to test against a local compiler:

[overrides]
ziran = "../ziran"
S
Description
Tokenization and syntax highlighting for Ziran, C and Make.
Readme BSD-3-Clause
45 KiB
0 Stars 1 Watchers 0 Forks