5个版本
0.1.4 | 2022年2月2日 |
---|---|
0.1.3 | 2022年1月30日 |
0.1.2 | 2022年1月30日 |
0.1.1 | 2022年1月30日 |
0.1.0 | 2022年1月30日 |
#2809 in 解析器实现
14KB
262 行
mico
此库实现了mico(极简配置文件格式)的解析器和发射器。
格式示例
Name: mico
Description: minimalistic config file format
Benefits
- easy to read and write for everyone
- ludicrously simple parsing logic (roughly 30 lines of code)
解析和发射mico
有两个便利函数用于解析和发射
use mico::Mapping;
// parse string
let mappings = mico::from_str("foo: bar");
assert_eq!(mappings[0].key, "foo");
assert_eq!(mappings[0].value, "bar".into());
// emit mappings
let mappings = [Mapping::new("foo", "bar")];
assert_eq!(mico::to_string(&mappings, 0), "foo: bar\n");
注意
mico
旨在让人们快速编写简单的配置文件。无需考虑缩进、转义或引号,因此任何文本行都可以直接粘贴到mico
文件中而无需进一步编辑。
只有两种类型
-
从键到字符串的映射
key: value
-
从键到字符串列表的映射
key - value 1 - value 2
以下是一个mico示例
foo: bar
indentation is possible: but does not matter
white space : will be trimmed
this is a key:this: is:a :value
empty string:
empty lines: will be ignored
list ...
- keys must not include a colon
- items start with '-'
this is an empty list, because this line does not include a colon
this is no list because of the colon at the end of this line:
- this is an empty list
以下是对应的JSON示例
[
{ "foo": "bar" },
{ "indentation is possible": "but does not matter" },
{ "white space": "will be trimmed" },
{ "this is a key": "this: is:a :value" },
{ "empty string": "" },
{ "empty lines": "will be ignored" },
{ "list ...": ["keys must not include a colon", "items start with '-'"] },
{ "This is an empty list, because this line does not include a colon": [] },
{ "This is no list because of the colon at the end of this line:": "" },
{ "- this is an empty list": [] }
]