KDL document language parser, formatter, query engine, and schema validation library for MoonBit
{
"deps": {
"lenitain/kdl": "0.1.0"
}
}let doc = @parser.parse(r#"node "hello" { child key=42 }"#)?
println(doc.to_kdl_string())
let node = doc.get("node")
println(node)// Parse KDL v2 (default)
let doc = @parser.parse(input)?
// Parse KDL v1
let doc = @parser.parse_v1(input)?
// Access document nodes
let nodes = doc.nodes()
let first = doc.get("node-name")| Type | Description |
|---|---|
| KdlDocument | Top-level document containing an array of nodes |
| KdlNode | A named node with entries and optional children |
| KdlEntry | A value argument or key=value property |
| KdlValue | Enum: String, Integer(Int64), Float(Double), Bool, Null |
| KdlIdentifier | A node/property key name with optional repr |
| KdlError | Collection of KdlDiagnostic errors |
| KdlDiagnostic | Single diagnostic with span, message, label, severity |
let node = @KdlNode::new(@KdlIdentifier::new("server"))
let doc = @KdlDocument::new()
doc.push(node)
println(doc.to_kdl_string())match entry.value {
String(s) => println(s)
Integer(n) => println(n.to_string())
Float(f) => println(f.to_string())
Bool(b) => println(b.to_string())
Null => println("null")
}// Compact output
println(doc.to_kdl_string())
// Pretty-printed with 2-space indentation
println(doc.to_kdl_string_formatted(2))let results = @query.query(doc, "node > child")?let schema_doc = @parser.parse(schema_input)?
let schema = @schema.parse_schema(schema_doc)?
@schema.validate(doc, schema)?moon build cmd/mainkdl parse <file> Parse and print document summary
kdl check <file> [schema] Validate against optional schema
kdl format <file> Pretty-print a KDL file
kdl help Show usage| Import | Purpose |
|---|---|
| lenitain/kdl | Core types |
| lenitain/kdl/parser | Parsing functions |
| lenitain/kdl/query | KQL queries |
| lenitain/kdl/schema | Schema validation |
pub struct KdlDiagnostic {
input : String
span_start : Int
span_len : Int
message : String?
label : String?
help : String?
severity : KdlSeverity
} derive(Eq)impl Show for KdlDiagnosticfn KdlDiagnostic::new(input : String, span_start : Int, span_len : Int, message : String?, label : String?, help : String?, severity : KdlSeverity) -> KdlDiagnosticimpl Eq for KdlDocumentimpl Show for KdlDocumentfn KdlEntry::new_prop_with_ty(ty : KdlIdentifier?, name : KdlIdentifier, value : KdlValue) -> KdlEntrypub struct KdlNode {
ty : KdlIdentifier?
name : KdlIdentifier
entries : Array[KdlEntry]
children : Array[KdlNode]?
}fn KdlNode::full(ty : KdlIdentifier?, name : KdlIdentifier, entries : Array[KdlEntry], children : Array[KdlNode]?) -> KdlNodepub(all) enum KdlValue {
String(String)
Integer(Int64)
Float(Double)
Bool(Bool)
Null
}Install
Download zipKDL document language parser, formatter, query engine, and schema validation library for MoonBit