4 releases (stable)

Uses new Rust 2024

new 2.0.0 Mar 3, 2026
1.0.1 Jan 23, 2026
1.0.0 Jan 22, 2026
0.0.1 Jan 20, 2026

#39 in Configuration

Download history 22/week @ 2026-01-17 30/week @ 2026-01-24 23/week @ 2026-01-31 2/week @ 2026-02-07 6/week @ 2026-02-14 21/week @ 2026-02-21 47/week @ 2026-02-28

77 downloads per month
Used in 12 crates (3 directly)

MIT/Apache

96KB
2K SLoC

styx-cst

crates.io documentation MIT/Apache-2.0 licensed

Lossless Concrete Syntax Tree for the Styx configuration language. Preserves all whitespace and comments for formatting and refactoring tools.

This crate provides a CST (Concrete Syntax Tree) representation of Styx documents using the rowan library. Unlike an AST, the CST preserves all source information including whitespace, comments, and exact token positions, making it ideal for tooling like formatters, refactoring tools, and language servers.

Features

  • Lossless representation: Source text can be exactly reconstructed from the CST
  • Cheap cloning: Syntax nodes use reference counting internally
  • Parent pointers: Navigate up and down the tree
  • Typed AST layer: Ergonomic wrappers over raw CST nodes
  • Semantic validation: Check for issues like duplicate keys and mixed separators

Example

use styx_cst::{parse, ast::{AstNode, Document}};

let source = r#"
host localhost
port 8080
"#;

let parsed = parse(source);
assert!(parsed.is_ok());

let doc = Document::cast(parsed.syntax()).unwrap();
for entry in doc.entries() {
    if let Some(key) = entry.key_text() {
        println!("Found key: {}", key);
    }
}

// Roundtrip: source can be exactly reconstructed
assert_eq!(parsed.syntax().to_string(), source);

Validation

use styx_cst::{parse, validation::validate};

let source = "{ a 1, a 2 }"; // Duplicate key
let parsed = parse(source);
let diagnostics = validate(&parsed.syntax());

assert!(!diagnostics.is_empty());

Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

...along with corporate sponsors:

AWS Zed Depot

...without whom this work could not exist.

License

Licensed under either of:

at your option.

Dependencies

~5.5–8MB
~62K SLoC