
CSS lexer and parser producing a fully navigable AST with exact character offsets per token/node, W3C Syntax Level 3-compliant, plus interactive AST explorer demo.
A Kotlin Multiplatform CSS lexer and parser that produces a fully navigable Abstract Syntax Tree (AST) with source-position tracking.
KSS tokenizes and parses CSS following the W3C CSS Syntax Level 3 specification, providing precise character offsets for every token and AST node. It runs on JVM, macOS, Linux, JS, and WebAssembly.
| Module | Description |
|---|---|
| core | Shared abstractions: Token, TokenKind, CssLocation, AST node base types |
| lexer | CSS tokenizer — turns a CSS string into List<Token<out CssTokenKind>>
|
| parser | CSS parser — turns tokens into a StyleSheet AST |
| bom | Bill of Materials for version alignment |
| demo/shared | Shared Compose Multiplatform UI for the demo app |
| demo/desktop | Desktop (JVM) entry point for the demo |
| demo/web | Web (wasmJs) entry point for the demo |
// Use the BOM for version alignment
dependencies {
implementation(platform("dev.tonholo.kss:kss-bom:1.0.2"))
implementation("dev.tonholo.kss:kss-parser") // includes core + lexer transitively
}dependencies {
implementation(platform("dev.tonholo.kss:kss-bom:1.0.2"))
implementation("dev.tonholo.kss:kss-parser")
}In your module.yaml:
dependencies:
- dev.tonholo.kss:kss-parser:1.0.2Or with individual modules:
dependencies:
- dev.tonholo.kss:kss-core:1.0.2
- dev.tonholo.kss:kss-lexer:1.0.2import dev.tonholo.kss.lexer.css.CssTokenizer
val css = "body { color: red; }"
val tokens = CssTokenizer().tokenize(css)
for (token in tokens) {
println("${token.kind} [${token.startOffset}..${token.endOffset}]")
}import dev.tonholo.kss.lexer.css.CssTokenizer
import dev.tonholo.kss.parser.ast.css.CssParser
import dev.tonholo.kss.parser.ast.css.consumer.CssConsumers
val css = "body { color: red; }"
val tokens = CssTokenizer().tokenize(css)
val consumers = CssConsumers(css)
val styleSheet = CssParser(consumers).parse(tokens)
// Navigate the AST
for (child in styleSheet.children) {
println(child)
}The project includes a Compose Multiplatform demo app — a CSS AST Explorer with a split-pane layout: a syntax-highlighted CSS editor on the left and an interactive AST tree viewer on the right, with bidirectional synchronization.
./amper run -m demo/desktopRequires Node.js (>= 18) and npm:
./scripts/run-web.shThis builds the wasmJs module, extracts the Skiko runtime, installs npm dependencies, and starts
a Vite dev server at http://localhost:3000.
KSS uses the Amper build system.
# Build all modules
./amper build
# Run tests
./amper test
# Run code quality checks (ktlint + detekt)
./scripts/check.sh
# Auto-format with ktlint
./scripts/check.sh formatSee CONTRIBUTING.md for guidelines on how to contribute.
This project is licensed under the MIT License.
A Kotlin Multiplatform CSS lexer and parser that produces a fully navigable Abstract Syntax Tree (AST) with source-position tracking.
KSS tokenizes and parses CSS following the W3C CSS Syntax Level 3 specification, providing precise character offsets for every token and AST node. It runs on JVM, macOS, Linux, JS, and WebAssembly.
| Module | Description |
|---|---|
| core | Shared abstractions: Token, TokenKind, CssLocation, AST node base types |
| lexer | CSS tokenizer — turns a CSS string into List<Token<out CssTokenKind>>
|
| parser | CSS parser — turns tokens into a StyleSheet AST |
| bom | Bill of Materials for version alignment |
| demo/shared | Shared Compose Multiplatform UI for the demo app |
| demo/desktop | Desktop (JVM) entry point for the demo |
| demo/web | Web (wasmJs) entry point for the demo |
// Use the BOM for version alignment
dependencies {
implementation(platform("dev.tonholo.kss:kss-bom:1.0.2"))
implementation("dev.tonholo.kss:kss-parser") // includes core + lexer transitively
}dependencies {
implementation(platform("dev.tonholo.kss:kss-bom:1.0.2"))
implementation("dev.tonholo.kss:kss-parser")
}In your module.yaml:
dependencies:
- dev.tonholo.kss:kss-parser:1.0.2Or with individual modules:
dependencies:
- dev.tonholo.kss:kss-core:1.0.2
- dev.tonholo.kss:kss-lexer:1.0.2import dev.tonholo.kss.lexer.css.CssTokenizer
val css = "body { color: red; }"
val tokens = CssTokenizer().tokenize(css)
for (token in tokens) {
println("${token.kind} [${token.startOffset}..${token.endOffset}]")
}import dev.tonholo.kss.lexer.css.CssTokenizer
import dev.tonholo.kss.parser.ast.css.CssParser
import dev.tonholo.kss.parser.ast.css.consumer.CssConsumers
val css = "body { color: red; }"
val tokens = CssTokenizer().tokenize(css)
val consumers = CssConsumers(css)
val styleSheet = CssParser(consumers).parse(tokens)
// Navigate the AST
for (child in styleSheet.children) {
println(child)
}The project includes a Compose Multiplatform demo app — a CSS AST Explorer with a split-pane layout: a syntax-highlighted CSS editor on the left and an interactive AST tree viewer on the right, with bidirectional synchronization.
./amper run -m demo/desktopRequires Node.js (>= 18) and npm:
./scripts/run-web.shThis builds the wasmJs module, extracts the Skiko runtime, installs npm dependencies, and starts
a Vite dev server at http://localhost:3000.
KSS uses the Amper build system.
# Build all modules
./amper build
# Run tests
./amper test
# Run code quality checks (ktlint + detekt)
./scripts/check.sh
# Auto-format with ktlint
./scripts/check.sh formatSee CONTRIBUTING.md for guidelines on how to contribute.
This project is licensed under the MIT License.