I wouldn't say my code is beautiful but you can see all the code in the github repository.
https://github.com/lechatthecat/oran
I made a scripting language in Rust. You can try this language by
$ git clone https://github.com/lechatthecat/oran.git
$ cd oran
$ cargo build --release
$ ./target/release/oran -f ./examples/hello.orn
Please note that you need to install git and Rust in your PC beforehand.
Then you can see 'Hello World' is printed as follows:
$ ./target/release/oran -f ./examples/hello.orn
Hello World.
In this language, you can define functions as follows:
fn test () {
println('hello');
}
test();
You can copy-and-paste the above in ./examples/hello.orn and run it. If you run this script, you can see the function is called as follows:
$ ./target/release/oran -f ./examples/hello.orn
hello
Of course you can define variables as follows:
fn test () {
let test = 'hey';
println(test);
}
test();
$ ./target/release/oran -f ./examples/hello.orn
hey
But variables are immutable by default. You can't substitute other values to the variable.
fn test () {
let test = 'hey';
test = 'hello'; // error!
println(test);
}
test();
You must define it as a mutable variable to substitute other values:
fn test () {
let mut test = 'hey';
test = 'hello'; // Now it runs
println(test);
}
test();
You can also use for-loop in this language.
fn test () {
let test = ' test';
for i in 0..5 {
println(i << test);
}
}
test();
Result:
$ ./target/release/oran -f ./examples/hello.orn
0 test
1 test
2 test
3 test
4 test
If you want to do inclusive for-loop, you can write as follows:
fn test () {
let test = ' test';
for i in 0..=5 {
println(i << test);
}
}
test();
Result:
$ ./target/release/oran -f ./examples/hello.orn
0 test
1 test
2 test
3 test
4 test
5 test
You can also use 'if':
fn test (test1, test2) {
return test1 + test2;
}
if test(5,5) == 10 {
println('it is ten!');
}
Result:
$ ./target/release/oran -f ./examples/hello.orn
it is ten!
Escaping is also implemented:
fn test (test1, test2) {
test1 + test2
}
let t = 10;
if t == test(5,5) {
println("variable \"t\" is " << t);
}
Result:
$ ./target/release/oran -f ./examples/hello.orn
variable "t" is 10
Also, as you could see, you can omit 'return' in function just like in Rust:
/* both functions work */
fn test (test1, test2) {
test1 + test2
}
fn test2 (test1, test2) {
return test1 * test2;
}
println(test(5,5));
println(test2(5,5));
You can see many other random dirty examples in
https://github.com/lechatthecat/oran/blob/master/examples/example.orn
You can run it by:
$ ./target/release/oran -f ./examples/example.orn
Top comments (2)
Great project!
Thank you very much :)