Crates.io | swahili-dsl |
lib.rs | swahili-dsl |
version | 0.1.8 |
source | src |
created_at | 2020-10-07 10:35:41.73573 |
updated_at | 2020-10-08 10:52:46.395893 |
description | A Swahili-based DSL made for educational purposes. |
homepage | |
repository | https://github.com/collinsmuriuki/swahili-dsl |
max_upload_size | |
id | 296911 |
size | 9,603 |
An attempt at creating a Swahili-based DSL. A DSL is a mini "language" embedded in a Rust macro. Made for educational purposes.
Heavily influenced by swahili-lang and macro-lisp
// declaring variables
swh!(wacha jina = 2020);
// booleans
swh!(wacha swala = swh!(kweli));
swh!(wacha swala = swh!(uwongo));
// list comprehensions
swh!(matokeo; kwa n katika swh!(masafa(0,10)) => kama n%2 == 0);
// Declaring functions (very rudimental)
swh!(shughuli ongeza(n: u32) -> u32 {
rudisha n + 11
});
swh!(wacha hesabu = ongeza(1));
// inbuilt functions
swh!(wacha urefu = swh!(urefu(vec![1,2,4])));
swh!(andika("Habari Duinia"));
swh!(wacha orodha = swh!(masafa(1, 5)));
// collections
swh!(wacha l = swh!(orodha -> [1,2,4]));
swh!(wacha hm = swh!(kamusi -> {
"id" => "#12",
"jina" => "Juma"
}));
// arithmetic operations
swh!(wacha hesabu = swh!(suluhisha 4 * 4));
swh!(wacha hesabu = swh!(suluhisha (12/4) * (16/4)));
swh!(wacha hesabu = swh!(suluhisha 4 * 4, suluhisha 4 * 2));
// ternary operator
swh!(wacha swala = swh!(kweli));
swh!(swala => {
swh!(andika("Kweli")) ;
swh!(andika("Uwongo"))
});
cargo test -- --show-output
This project is MIT licensed.