9 releases

0.1.8 Oct 8, 2020
0.1.7 Oct 8, 2020

#1902 in Rust patterns

Download history 4/week @ 2024-03-30 235/week @ 2024-06-08 10/week @ 2024-06-15

245 downloads per month

MIT license

9KB
143 lines

swahili-dsl

License: MIT crates.io Travis CI

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

Examples

// 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"))
});

Run tests

cargo test -- --show-output

This project is MIT licensed.

No runtime deps