slop-rs

Crates.ioslop-rs
lib.rsslop-rs
version0.1.0
sourcesrc
created_at2024-01-22 16:37:39.893218
updated_at2024-01-22 16:37:39.893218
descriptionOfficial implementation of the SLOP data storage language
homepage
repositoryhttps://github.com/ThEnderYoshi/slop-rs
max_upload_size
id1108966
size25,369
ThEnderYoshi (ThEnderYoshi)

documentation

README

SLOP-RS

Rust

This is the official Rust implementation of the SLOP language.

Sans' Lovely Properties (SLOP) is a data storage language designed to be tiny, (both in complexity and amount of characters) while still being human-readable.


Note: The crate is still in a pre-release state, so even minor updates may introduce breaking changes.

If you have a problem/suggestion/general feedback, please create an issue on the crate's GitHub page.


use std::{error::Error, fs};

use slop_rs::Slop;

fn main() -> Result<(), Box<dyn Error>> {
    /// See also: Slop::new() and Slop::open()
    let slop_str = "\
        some-key=some value
        other-key{
            value 1
            value 2
        }";
    let mut slop: Slop = slop_str.parse()?;

    println!("{:?}", slop.get("some-key"));
    println!("{:?}", slop.get("other-key"));

    let mut s = slop
        .get_string("some-key")
        .expect("expected a string kv")
        .to_owned();
    s.push_str("!!!");

    slop.insert("some-key".to_string(), s)?;
    println!("{:?}", slop.get("some-key"));

    slop.save("example.slop");
    Ok(())
}

See examples/ for both examples of the API and sample SLOP files.

The Language

SLOP is so simple it can be entirely explained by the following code block:

# Lines starting with `#` are comments
# Any leading (but not trailing) whitespace in lines is ignored.
# A singular trailing carriage return (\r) is also igonred, if it is present.

# This is a string key-value. (AKA string KV)
some-key=some value # This is NOT a comment, it is part of the value.

# This is a list KV. Each line is an item.
list-kv{
    item 1
    item 2
    item 3
    # This is NOT a comment, every line (even empty ones) between the brackets
    # are treated as items.
Indentation is optional.
List KVs cannot be nested.
}

# This is how empty list KVs look:
empty-list-kv{
}

# This is invalid:
#empty-list-kv{}

# Keys can contain any character except for `=`, `{` and newlines.

And that's it!

Commit count: 0

cargo fmt