slop-rs 0.1.0

Official implementation of the SLOP data storage language
Documentation
  • Coverage
  • 100%
    35 out of 35 items documented12 out of 25 items with examples
  • Size
  • Source code size: 25.36 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 777.77 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ThEnderYoshi/slop-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ThEnderYoshi

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!