sml 0.1.2

Simple markup language.
Documentation

SML

SML is a simple markup language. It is designed to convert human readable information into Rust data-structures.

Data Format

  1. Indentation has meaning and is 4 spaces, relative to the top key.
  2. All values must be double quoted.
  3. Every key/value combination must be nested in a key. For example
    hobbit: "Frodo"

by itself is invalid. It can be written:

    hobbit:
        name: "Frodo"
  1. Separation of lines has meaning.
  2. Keys may not include :.
  3. Double quotes in values must be escaped using \".
  4. Everything after the second double quote is ignored (and can be used for commenting).
  5. There can be an arbitary amount of whitespace and returns before the first key and after the last key.

Example

use small::{Data, Small, SmallError};

#[derive(Debug)]
struct Hobbit {
    name:    String,
    age:     u32,
    friends: Vec<Hobbit>,
    bicycle: Option<String>,
}

impl Small for Hobbit {
    fn from_data(data: Data) -> Result<Self, SmallError> {
        Ok(Self {
            name:    String::sml(&data, "hobbit::name")?,
            age:     u32::sml(&data, "hobbit::age")?,
            friends: Vec::<Hobbit>::sml(&data, "hobbit::friends::hobbit")?,
            bicycle: Option::<String>::sml(&data, "hobbit::bicycle")?,
        })
    }
}

fn main() {
    let s = r#"
        hobbit:
            name:         "Frodo Baggins"
            age:          "98"
            friends:
                hobbit:
                    name: "Bilbo Baggins"
                    age:  "176"
                hobbit:
                    name: "Samwise Gamgee"
                    age:  "66""#;
    
    let frodo = Hobbit::from_str_debug(s);
}