|
|
||
|---|---|---|
| .forgejo/workflows | ||
| src | ||
| .gitignore | ||
| Cargo.toml | ||
| LICENSE | ||
| README.markdown | ||
JMU 📜 🖤 🎀
A parser and deserializer for a data markup language inspired by Jirai Kei. 📜 🖤 🎀
ABOUT 📚
This repository contains the source code for a parser for a data markup
language inspired by Jirai Kei. The parser is written
without any external dependencies and was made to be light and fast. The
language itself was designed by me and is an abbreviation for
Jirai MarkUp language. The crate does depend on the
serde library to handle deserialization of JMU data into Rust data
structures.
SPECIFICATION 🧮
JMU is a key-value mapping language. The rules for this language are outlined in the list below:
- Boolean values: Boolean values can only be written as either
trueorfalse. - Integer values: Integer values are simply numbers and do not need delimiters.
- Floating-point number values: Floating-point values are simply numbers and do not need delimiters.
- String values: String values must be surrounded by double quotes and contain text. Example:
"cat". - Lists of values: Lists are enclosed by square brackets and values are separated by a comma.
- Keys for values: Keys for values can only be strings.
- Each key-value mapping can start and end on the same line.
- Assignments are done via the
>~<operator. - Assignments can be nested. The start and end of a nested section is marked by the
|operator. - JMU documents must end in the
.jmufile extension. - A list of assignment blocks:
- Comments start with the
#symbol and MUST end with the newline character. - The following primitive Rust types are supported:
- Numbers: Any floating-point number types and integer number types.
- String: The
Stringtype. - Booleans: The
booltype. - Lists of values: The
Vec<T>type, whereTis any of the previous primitive types. - Options: The
Option<T>type, whereTis any of the previous primitive types.
USAGE ⚒️
To add the JMU crate to your Rust project and to start
deserializing text written in the JMU format, add
the following lines to the dependencies section of your
project's Cargo.toml:
serde = { version = "1.0.228", features = ["derive"] }
jmu = { git = "https://source.alyxshang.boo/alyxshang/jmu", tag = "v.0.2.0" }
You would use the JMU crate in your code in a manner similar to the one outlined in the code sample below:
use jmu::from_str;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
struct MyData{
pub name: String,
pub age: usize,
pub pi: f64,
pub is_awesome: bool,
pub is_political: bool,
pub hobbies: Vec<String>,
pub truth_table: Vec<bool>,
pub nested_assignment: NestedAssignment
}
#[derive(Deserialize, Debug)]
struct NestedAssignment{
pub favourite_fashion: String,
pub also_interested_in: String,
pub important_nums: Vec<f64>,
pub important_ints: Vec<usize>,
pub is_unhinged: bool
}
fn main(){
let slice = r#"
"name" >~< "Alyx"
"age" >~< 2026
"pi" >~< 3.1415
"is_awesome" >~< true
"is_political" >~< false
"hobbies" >~< ["code", "art", "music"]
"truth_table" >~< [true, false, true]
"nested_assignment" >~< |
"favourite_fashion" >~< "goth"
"also_interested_in" >~< "Jirai Kei"
"is_unhinged" >~< true
|
"#;
let deserialized: MyData = from_str(&slice.to_string())
.expect("Unable to deserialize the string slice.");
println!("{:?}", deserialized); // should output the structure "MyData"
}
More information on the entities inside this crate can be obtained
by reading the API documentation of this crate. The documentation can be
read by cloning this repository and running the command cargo doc --open
from the root of the repository.
CHANGELOG ✒️
Version 0.1.0
- Initial release.
- Initial upload to Forgejo.
Version 0.2.0
- Updated specification.
- Added the possibility to write a list of assignment blocks in JMU data.
NOTE 📜
- JMU 📜 🖤 🎀 by Alyx Shang 🖤.
- Licensed under the FSL v1.