Skip to content

Commit

Permalink
Fixing issue #59, all keys/values
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborsch committed Jun 28, 2024
1 parent cc57267 commit ceebd12
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/spec_ext.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ The built-in function `last of` returns the last element in an array.
Say last of the colors
```

## Associative Array extension

### Keys and values

The `all keys of X` and `all values of X` functions return the key set and the value set of an associative array `X`. Note that the sets are unsorted.


## DEC64 Arithmetics

As per the original Rockstar specification, Rocky fully supports DEC64 arithmetic with `--dec64` command line option (including rounding functions).
Expand Down
13 changes: 13 additions & 0 deletions programs/tests/fixtures/Rocky_ext/array_ext/assoc_array_all.rock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let the weather at "London" be "rainy"
let the weather at "Phoenix" be "dry"
let the weather at "Siberia" be "cold"

let cities be all keys of the weather
let climates be all values of the weather

While cities sorted alike a hamlet
say a hamlet

While climates sorted alike a sunray
say a sunray

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
London
Phoenix
Siberia
cold
dry
rainy
Binary file modified rocky.jar
Binary file not shown.
10 changes: 5 additions & 5 deletions src/rockstar/parser/ExpressionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,13 @@ else if (containsAtLeast(2) && checkNext(Keyword.OF)) {
type = BuiltinFunction.Type.PEEK;
next(2);
}
} // all keys of
// all values of
else if (containsAtLeast(3) && checkCurrent(Keyword.ALL) && checkNext(Keyword.OF)) {
if (checkNext(2, Keyword.KEYS)) {
}
else if (containsAtLeast(3) && checkCurrent(Keyword.ALL) && checkNext(2, Keyword.OF)) {
// all keys of / all values of
if (checkNext(Keyword.KEYS)) {
type = BuiltinFunction.Type.KEYS;
next(3);
} else if (checkNext(2, Keyword.VALUES)) {
} else if (checkNext(Keyword.VALUES)) {
type = BuiltinFunction.Type.VALUES;
next(3);
}
Expand Down

0 comments on commit ceebd12

Please sign in to comment.