Crate xcdn

Crate xcdn 

Source
Expand description

§xcdn

xcdn is a zero-copy, streaming-capable parser/serializer for xCDN — eXtensible Cognitive Data Notation.

The crate exposes three public layers:

  • lexer tokenizes an xCDN document while tracking line/column.
  • parser produces a typed AST (ast::Document) including optional prolog directives.
  • ser pretty/compact serialization with strong typing (Decimal, UUID, DateTime, Duration, Bytes).

§Quick Start

use xcdn::{parse_str, ser::to_string_pretty, ast::Value};

let input = r#"
$schema: "https://gslf.github.io/xCDN/schemas/v1/meta.xcdn",

server_config: {
  host: "localhost",
  ports: [8080, 9090,],
  timeout: r"PT30S",
  max_cost: d"19.99",
  admin: #user { id: u"550e8400-e29b-41d4-a716-446655440000", role: "superuser" },
  icon: @mime("image/png") b"aGVsbG8=",
}"#;

let doc = parse_str(input).expect("valid xCDN");
assert!(doc.values.len() >= 1);

// Serialize it back
let text = to_string_pretty(&doc).unwrap();
println!("{}", text);

§Design notes

  • This implementation follows the public xCDN grammar and documentation.
  • It supports: comments, unquoted keys, trailing commas, multi-line strings ("""..."""), native types (Decimal, UUID, DateTime, Duration, Bytes), #tags, and @annotations.
  • We do not preserve comments/insignificant whitespace on serialization.

See the project repository for the xCDN specification and examples.

§Crate layout

  • ast — core data structures
  • error — structured error diagnostics with spans
  • lexer — the tokenizer
  • parser — recursive-descent parser
  • ser — serializer

§Optional (via serde feature)

The Value implements serde::Serialize / serde::Deserialize when the serde feature is enabled, enabling easy bridging to your data types.

Re-exports§

pub use parser::parse_str;
pub use parser::parse_reader;

Modules§

ast
AST types for xCDN.
error
Error types with spans and pretty display.
lexer
Tokenizer for xCDN.
parser
Recursive-descent parser for xCDN.
ser
Serializer for xCDN.