swahili-dsl

Crates.ioswahili-dsl
lib.rsswahili-dsl
version0.1.8
sourcesrc
created_at2020-10-07 10:35:41.73573
updated_at2020-10-08 10:52:46.395893
descriptionA Swahili-based DSL made for educational purposes.
homepage
repositoryhttps://github.com/collinsmuriuki/swahili-dsl
max_upload_size
id296911
size9,603
Collins Muriuki (c12i)

documentation

README

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.

Commit count: 35

cargo fmt