Skip to content

Commit

Permalink
Feature/optional parenthesises (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbittich authored Feb 4, 2024
1 parent 5b03a8f commit b5e7316
Show file tree
Hide file tree
Showing 28 changed files with 275 additions and 120 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
# targets: x86_64-unknown-linux-musl
targets: x86_64-unknown-linux-gnu
- run: rustup component add clippy
- run: cargo test --verbose -- --nocapture
- run: cargo clippy --all-targets --all-features -- -D warnings
- run: cargo publish --dry-run
36 changes: 7 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ nu-ansi-term = "0.50.0"
rustyline = "13.0.0"
rustyline-derive = "0.10.0"
serde = { version = "1.0.196", features = ['serde_derive', 'rc'] }
serde_json = "1.0.111"
serde_json = "1.0.113"
slab_tree = "0.3.2"
strum = { version = "0.26.1", features = ["derive"] }
ctrlc = "3.4.2"

#adana-script-core = { git = "https://github.com/nbittich/adana-script-core.git", branch = "feature/bitwise-and-new-ints" }
adana-script-core = "0.16.0"
adana-script-core = "0.16.1"
arboard = "3.3.0"

[dependencies.env_logger]
Expand Down
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ If it is not installed yet, you will see instructions on how to install it, e.g:
std lib doesn't exist: "/home/nbittich/.local/share/.libs_adana/adana-std/fs.so".
Try to install it like so:
- wget -P /tmp https://github.com/nbittich/adana-std/releases/download/0.16.0/adana-std.tar.gz
- wget -P /tmp https://github.com/nbittich/adana-std/releases/download/0.16.1/adana-std.tar.gz
- mkdir /home/nbittich/.local/share/.libs_adana/adana-std && tar xvzf /tmp/adana-std.tar.gz \
-C /home/nbittich/.local/share/.libs_adana/adana-std
```
Expand All @@ -367,7 +367,7 @@ There are two loops, the while loop and the for-each loop.
The while loop looks like the one in C, while the for-each loop is a little bit more
modern.

For-each loop doesn't require parenthesizes.
For-each loop & while loop don't require parenthesizes.
You can only iterate over structs, strings and arrays.

```C
Expand All @@ -379,6 +379,14 @@ while(count < 10) {
}
```
```
# also valid
while count < 10 {
println(count)
count = count + 1
}
```

```javascript
for n in [1,2,3] {
println(n)
Expand Down Expand Up @@ -430,7 +438,7 @@ for (index,a in arr) {
You can break if you match a certain condition within a while:

```C
while(count < 10) {
while count < 10 {
println(count)
count = count + 1
if(count % 3 ==0) {
Expand Down Expand Up @@ -461,12 +469,12 @@ for i in 1..=10 {

### Conditions

Same as C:
Same as C but parenthesizes are optional:

```C
if(age > 12) {
if age > 12 {
println("age > 12")
} else if(age <9) {
} else if age < 9 {
println("age < 9")
} else {
println("dunno")
Expand Down Expand Up @@ -813,7 +821,11 @@ RUST_LOG=adana=debug adana
#### Run a script without entering in the repl

```
# using file
adana -sp /path/to/script.adana
# using code
adana -e 1+1
```

```
Expand Down
20 changes: 10 additions & 10 deletions dynamic_lib/example_lib_src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dynamic_lib/example_lib_src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
crate-type = ["dylib"]

[dependencies]
adana-script-core = "0.16.0"
adana-script-core = "0.16.1"
#adana-script-core = { git = "https://github.com/nbittich/adana-script-core.git", branch = "feature/bitwise-and-new-ints" }

anyhow = "1.0.79"
Expand Down
4 changes: 2 additions & 2 deletions file_tests/sort.adana
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
sort = (array) => {
is_sorted = false
while (!is_sorted) {
while !is_sorted {
is_sorted = true
bound = length(array) - 1
for i in 0..bound {
if (array[i] > array[i+1]) {
if array[i] > array[i+1] {
is_sorted = false
temp = array[i+1]
array[i+1] = array[i]
Expand Down
8 changes: 4 additions & 4 deletions file_tests/string.adana
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# c: the character to search
# return: array of strings
split = (s, c) => {
if(s == null || length(s) == 0 || c == null || length(c) == 0) {
if s == null || length(s) == 0 || c == null || length(c) == 0 {
return null
}
res = []
buf = ""
count = 0
while(count < length(s)) {
while count < length(s) {
curr = s[count]
if(buf == "aka") {
return [buf]
Expand All @@ -22,10 +22,10 @@ split = (s, c) => {
}
count = count + 1
}
if(length(buf) != 0) {
if length(buf) != 0 {
res = res + [buf]
}
if(s!= null && length(res) == 0) {
if s!= null && length(res) == 0 {
res = [s]
}
res
Expand Down
2 changes: 1 addition & 1 deletion file_tests/test2.adana
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ b = null
x = null
z = null
r = null
if(a > 20) {
if a > 20 {
b = 12
x = 15
z = 18
Expand Down
6 changes: 3 additions & 3 deletions file_tests/test_array.adana
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ copy = []
count = 0

# copy the array one by one
while (count < arrlen) {
while count < arrlen {
copy = copy + [arr[count]]
count = count + 1
}
Expand All @@ -28,7 +28,7 @@ arr[9] = "Yolo"
i = 9
list = []

while(i !=0) {
while i !=0 {
list = [i, list]
i = i -1
}
Expand All @@ -37,4 +37,4 @@ while(i !=0) {
println(list)

# should print 2
println(length(list))
println(length(list))
8 changes: 4 additions & 4 deletions file_tests/test_fizzbuzz.adana
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ text = ""
while (count <= 100) {
toprint = false

if(count % 3 == 0) {
if count % 3 == 0 {
#fizz
toprint = true
text = multiline {
Expand All @@ -13,7 +13,7 @@ while (count <= 100) {
}
}

if(count % 5 == 0) {
if count % 5 == 0 {
# buzz
toprint = true
text = multiline {
Expand All @@ -22,15 +22,15 @@ while (count <= 100) {
}
}

if(count % 3 == 0 && count % 5 == 0) {
if count % 3 == 0 && count % 5 == 0 {
# Fizz Buzz
toprint = true
text = count + " = FizzBuzz"
}

count = count + 1

if(toprint) {
if toprint {
println(text)
}

Expand Down
10 changes: 5 additions & 5 deletions file_tests/test_fizzbuzz_else.adana
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
count = -1

text = ""
while (count <= 100) {
while count <= 100 {
count = count + 1
if(count % 3 == 0 && count % 5 == 0) {
if count % 3 == 0 && count % 5 == 0 {
# Fizz Buzz
text = count + " = FizzBuzz"
println(text)

} else if(count % 5 == 0) {
} else if count % 5 == 0 {
# buzz
text = multiline {
count +
" = Buzz" # oops
}
println(text)
} else if(count % 3 == 0) {
} else if count % 3 == 0 {
#fizz
text = multiline {
count
Expand All @@ -24,7 +24,7 @@ while (count <= 100) {
}
println(text)

}else {
} else {
println(count + " neither fizz nor buzz")
}
}
4 changes: 2 additions & 2 deletions file_tests/test_if_else.adana
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if(count == 102) {
if count == 102 {
count = count -1
println("101")
} else {
count = count -50
println("oops")
}
}
Loading

0 comments on commit b5e7316

Please sign in to comment.