#语言 #存储 #slop

slop-rs

SLOP 数据存储语言的官方实现

1 个不稳定版本

0.1.0 2024年1月22日

#2793解析器实现

MIT 许可证

24KB
259

SLOP-RS

Rust

这是 SLOP 语言的官方 Rust 实现。

Sans' Lovely Properties (SLOP) 是一种旨在简单小巧(在复杂性和字符数上)的同时仍具有可读性的数据存储语言。


注意: 该软件包仍然处于预发布状态,因此即使是微小的更新也可能引入破坏性更改。

如果您有任何问题/建议/一般反馈,请在该软件包的 GitHub 页面上创建一个问题。


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(())
}

请参阅 examples/ 中的 API 示例和样本 SLOP 文件。

语言

SLOP 非常简单,可以用以下代码块完全解释

# 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.

这就是全部!

依赖关系

~300–760KB
~18K SLoC