5 releases

Uses old Rust 2015

0.1.4 Jul 12, 2015
0.1.3 May 27, 2015
0.1.2 May 26, 2015
0.1.1 May 26, 2015
0.1.0 May 26, 2015

#5 in #ucl

25 downloads per month

MIT license

20KB
435 lines

Rust wrapper around libucl

Build Status

Usage

extern crate ucl;
use ucl::Parser;

let parser = Parser::new();
let result = parser.parse(r#"name = "mort";
section {
    nice = true;
    server = "http://localhost:6666";
    chunk = 1Gb;
}"#).unwrap();

println!("{}", result.fetch_path("section.nice").and_then(|v| v.as_bool()));

Licence

Check out LICENSE file.


lib.rs:

UCL (Universal Configuration Library)

This library is parser for UCL files.

Basic structure

UCL provide support for 2 different syntaxes:

  • JSON

    {
        "param": "value",
        "section": {
            "flag": true,
            "number": 10000,
            "subsection": {
                "hosts": [
                    {
                        "host": "localhost",
                        "port": 9000
                    },
                    {
                        "host": "remotehost",
                        "port": 9090
                    }
            }
        }
    }
    
  • nginx like UCL

    param = value;
    section {
        flag = true;
        number = 10k;
        subsection {
            hosts = {
                host = "localhost";
                port = 9000
            }
            hosts = {
                host = "remotehost"
                port = 9090
            }
        }
    }
    

Differences between UCL and JSON:

  • outmost braces are optional so {"a": "b"} is equivalent to "a": "b"
  • quotes on keys and strings are optional
  • : can be replaced with = or even skipped for objects
  • comma can be replaced with semicolon
  • trailing commas are allowed
  • automatic array creation - non-unique keys in object are allowed and are automatically converted to arrays

Parser usage

Simple example:

static DOC: &'static str = r#"
param = value;
section {
    flag = true;
    number = 10k;
    subsection {
        hosts = {
            host = "localhost";
            port = 9000
        }
        hosts = {
            host = "remotehost"
            port = 9090
        }
    }
}
"#;

let parser = ucl::Parser::new();
let document = parser.parse(DOC).unwrap();

assert_eq!(document.fetch("param").unwrap().as_string(), Some("value".to_string()));

Dependencies

~155KB