5 releases (3 breaking)

0.3.0 Sep 11, 2024
0.2.0 Sep 11, 2024
0.1.1 Sep 4, 2024
0.0.16 Feb 18, 2023

#420 in Parser implementations


Used in 2 crates

MIT/Apache

1.5MB
3K SLoC

Rust 2K SLoC // 0.2% comments JavaScript 1K SLoC // 0.1% comments

Contains (WOFF font, 99KB) fontawesome-webfont.woff, (WOFF font, 78KB) fontawesome-webfont.woff2, (WOFF font, 45KB) open-sans-v17-all-charsets-300.woff2, (WOFF font, 41KB) open-sans-v17-all-charsets-300italic.woff2, (WOFF font, 45KB) open-sans-v17-all-charsets-600.woff2, (WOFF font, 43KB) open-sans-v17-all-charsets-600italic.woff2 and 7 more.

KFL

mdbook

  • Nominal Typing
  • Trait-Based
  • Two-Level
  • Decode-Encode Dual
  • Literal

A KDL file format parser with great error reporting and convenient derive macros.

About KDL

To give you some background on the KDL format. Here is a small example:

foo 1 "three" key="val" {
    bar
    (role)baz 1 2
}

Here is what are annotations for all the datum as described by the specification and this guide:

foo 1 "three" key="val" {                           ╮
─┬─ ┬ ───┬─── ────┬────                             │
 │  │    │        ╰───── property (can be multiple) │
 │  │    │                                          │
 │  ╰────┴────────────── arguments                  │
 │                                                  │
 ╰── node name                                      ├─ node "foo", with
                                                    │  "bar" and "baz"
    bar                                             │  being children
    (role)baz 1 2                                   │
     ──┬─                                           │
       ╰────── type name for node named "baz"       │
}                                                   ╯

Usage

Most common usage of this library is using derive and [decode] or [decode_children] function:

use kfl::{Decode, DecodePartial, Encode};
use std::path::PathBuf;
#[cfg(feature = "http")]
use http::Uri;

#[derive(DecodePartial, Default)]
struct Document {
    #[kfl(children)]
    routes: Vec<Route>,
    #[kfl(children)]
    plugins: Vec<Plugin>,
}

#[derive(Decode, Encode)]
struct Route {
    #[kfl(argument)]
    path: PathBuf,
    #[kfl(children)]
    subroutes: Vec<Route>,
}

#[derive(Decode, Encode)]
struct Plugin {
    #[kfl(argument)]
    name: String,
    #[cfg(feature = "http")]
    #[kfl(property)]
    url: Uri,
}

# fn main() -> miette::Result<()> {
let document = kfl::decode_children::<Document>("example.kdl", r#"
    route /api {
        route /api/v1
    }
    plugin "http" url=https://example.org/http
"#)?;
# Ok(())
# }

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~4–5.5MB
~86K SLoC