fomoscript
Toy scripting language, built with Rust
- 0 dependencies*
- 1 file
- no_std with alloc
Only a few days old. Not production ready. The goal is to use it in Fomos as a shell.
* except log, doesn't count ;)
Examples
Simple script
returns 5
Support of higher order functions
returns 1
Use in Rust
Step 1: have some code
let code: = r#"
{
let x = 0
while x<5 {
x = x+1
}
x
}"#
.chars
.collect;
Step 2: parse it
let ast = parse_ast.expect;
Step 3: run it
let mut ctx = new;
let result = eval;
The result will have this type.
Go see the tests for more examples.
By default, there is no side effect possible from the script during eval (except inside ctx)
You can insert native rust closure with (or without) side effects into the script, and use it from there. Example with the print function:
let code: = r#"
{
my_print(1+1)
}
"#
.chars
.collect;
let ast = parse_ast.unwrap;
let mut ctx = new;
let print_closure = new;
ctx.set_var_absolute;
let _ = eval;
Cruelly missing
- Arrays
- Months of work
- Pattern matching
- Javascript-like objects (we just have Number and String 😱)
- Read-Eval-Print Loop
- Error handling (now it just UB if something goes wrong)
- Escape characters in quoted strings
- Operator precedence
Also the inner workings are not very rust-like, no unsafe though ;)