A scripting language written in Rust
You can try Dom for yourself using the playground here.
- Comments
- Types
- Booleans
- Integers
- Floats
- Strings
- Lists
- Variables
- Mutable
- Constant
- Comparisons
- Unary expressions
- Binary expressions
- Scope
- Functions
- Defined
- Built-in
- Loops
- Control flow
- Conditional statements
- Single conditions
- Multiple conditions
- Return
- Continue
- Break
- Conditional statements
Commenting is done with the // characters:
// Hello, world!They are not parsed in any manner.
Numerical comparison uses the usual operators:
let foo = 1
let bar = 2
print(foo <= bar) // true
print(foo >= bar) // false
print(foo != bar) // true
print(foo == bar) // falseLikewise, for binary comparisons:
let foo = true
let bar = false
print(foo && bar) // false
print(foo || bar) // trueArithmetic can be performed as you would expect. For example:
(2 + 2) * (2 / 2) - 2Outputs 2. Operations follow the usual order of operations.
Currently supported operations are:
- Addition
+ - Subtraction
- - Multiplication
* - Division
/
Variables can be set using the let keyword as follows:
let foo = 1They are always mutable.
Conditional statements can be formed using the if keyword:
let foo = 1
let bar = 2
if foo < bar {
print("`foo` is less than `bar`")
}Lists can be created using brackets [..]:
let list = [0, "foo", 1, "bar"]
print(get(list, 1)) // "foo"There are built-in functions for working with lists: get, set, push, pop, and len.
Functions are defined using the fn keyword as follows:
fn sum(a, b) {
a + b
}Unless the return keyword is used, they return the last evaluated expression. They are called as you may expect:
sum(1, 1)Arguments are always passed by value, for now.
Dom has support for pipes, which let you pass the result of one function onto the next. For example:
["foo"]
|> push("bar")
|> print()will output ["foo", "bar"].
Dom also contains some built-in functions, which can be seen below:
Note
These functions don't produce errors right now, i.e. for incorrect arguments or runtime errors.
| Function | Arguments | Description |
|---|---|---|
print |
Any |
Outputs a literal to the console |
input |
None |
Requests and returns input from the console. Not supported in dom_wasm |
get |
List, Int |
Gets an item at a specified index from a List |
set |
List, Int, Any |
Sets an item at a specified index in a List |
push |
List, Any |
Pushes an item to the end of a List |
pop |
List, Int |
Pops an item at a specified index in a List |
len |
List, Int |
Returns the length of a List |
Loops are defined using the loop keyword, and use break and continue for control flow:
let foo = 0
let bar = 2
loop {
foo = foo + 1
if foo == bar {
// Exit this iteration
continue
}
print(foo)
if foo > 10 {
// Exit the loop
break
}
}Make sure you have the Rust toolchain installed.
- Clone this repository and navigate to it:
git clone https://github.com/chompaa/dom && cd dom- To start the interactive shell:
cargo run -p dom_cli- To interpret a file:
cargo run -p dom_cli <file>