-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
256 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "onlang" | ||
name = "on" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
![onlang logo](static/logos/OnLang-transparent.png) | ||
|
||
# You may have questions | ||
|
||
ONLang - Object Notation Language (js`ON`) | ||
|
||
## 1. God, what the f\*\*\*\* is this | ||
|
||
ONLang is an experimental, esoteric programming language, that allows you to use **json** for **PROGRAMMING**. The interpreter currently supports only json5 format. | ||
|
||
## 2. What is it for | ||
|
||
For writing simple scripts. | ||
|
||
## 3. How run scripts | ||
|
||
1. Add the executable file to the path variable | ||
2. `on example.json5` | ||
|
||
or | ||
|
||
1. Clone this repo | ||
2. `cargo run --quiet --release -- example.json5` | ||
|
||
## 4. How to write on this | ||
|
||
[Documentation](doc/main.md) | ||
|
||
If you want to help create a pull request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# TODO CONCEPTS | ||
|
||
1. Functions | ||
2. imports | ||
3. scopes of visibility | ||
4. parallel tasks `{parallel:[..tasks]}` | ||
5. types conversion | ||
6. methods for arrays | ||
7. writing objects to a variable | ||
8. yaml support? | ||
|
||
and something else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
# How to | ||
|
||
`All posibilities in example.json5` | ||
|
||
## How to print | ||
|
||
```json5 | ||
[ | ||
"Just string in array", | ||
["array", "of", "strings"], | ||
{ | ||
print: ["Function"], | ||
}, | ||
{ | ||
println: ["Function"], | ||
}, | ||
] | ||
``` | ||
|
||
## How to calclulate values | ||
|
||
works only with numbers (and variables with number type) | ||
|
||
```json5 | ||
[ | ||
{ calc: [2, "*", 3] }, //only 3 arguments | ||
{ calc: [{ var: "some_variable" }, "-", 2] }, //{var:"some_var"} this is a way to get a variable | ||
] | ||
``` | ||
|
||
### Supported operators | ||
|
||
1. \+ | ||
2. \- | ||
3. \* | ||
4. \/ | ||
5. \% | ||
6. \>\> | ||
7. \<\< | ||
8. \^ | ||
9. \& | ||
10. \| | ||
|
||
## How to compare values | ||
|
||
```json5 | ||
[ | ||
{ comp: [true, "!=", false] }, //only 3 arguments | ||
{ | ||
comp: [ | ||
{ | ||
comp: [ | ||
{ comp: [{ calc: [1, "+", 1] }, ">", 3] }, | ||
"==", | ||
{ var: "var_with_bool_value" }, | ||
], | ||
}, | ||
"&&", | ||
{ comp: [{ comp: [{ calc: [1, "+", 1] }, ">", 3] }, "==", true] }, | ||
], | ||
}, //more complex comparisons: (( 1 + 1 > 3 ) == var_with_bool_value) && (( 1 + 1 > 3 ) == true) | ||
] | ||
``` | ||
|
||
### Supported operators for compare | ||
|
||
1. == | ||
2. != | ||
3. \> | ||
4. \< | ||
5. \>= | ||
6. \<= | ||
7. \&\& | ||
8. \|\| | ||
|
||
## How to create a variable | ||
|
||
```json5 | ||
[ | ||
{ | ||
let: { | ||
str: "A", | ||
num: 2, | ||
arr: ["Array", "in", "variable"], | ||
}, | ||
}, | ||
|
||
{ | ||
let: { | ||
calculated: { calc: [{ var: "num" }, "*", 4] }, //result 8 | ||
}, | ||
}, | ||
] | ||
``` | ||
|
||
## How to assign variable | ||
|
||
```json5 | ||
[ | ||
{ | ||
assign: { | ||
calculated: { calc: [{ var: "calculated" }, "+", 1] }, // calculated = calculated + 1 | ||
}, | ||
}, | ||
] | ||
``` | ||
|
||
## Loops | ||
|
||
```json5 | ||
[ | ||
{ | ||
loop: [ | ||
{ | ||
if: { | ||
condition: { comp: [{ var: "i" }, ">=", 10] }, //if i >= 10 break loop | ||
body: ["break"], | ||
//else: [..commands] also work | ||
}, | ||
}, | ||
{ assign: { i: { calc: [{ var: "i" }, "+", 1] } } }, // i += 1 | ||
{ print: ["\ri = ", { var: "i" }] }, | ||
{ sleep: 500 }, //sleep 500 ms | ||
], | ||
}, | ||
] | ||
``` | ||
|
||
## Input from console | ||
|
||
```json5 | ||
[ | ||
{ | ||
let: { | ||
name: { input: "Your name: " }, | ||
}, | ||
}, | ||
{ print: ["Bye, ", { var: "name" }, "!"] }, | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters