Skip to content

Commit

Permalink
Update Language-Definition.md
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Jan 22, 2023
1 parent 30d6ead commit bbf30b4
Showing 1 changed file with 40 additions and 45 deletions.
85 changes: 40 additions & 45 deletions docs/Language-Definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,37 @@
</tr>
</table>

## Supported Literals
## Literals

The package supports:
* `true`
* `false`
* `nil`

* **strings** - single and double quotes (e.g. `"hello"`, `'hello'`)
* **numbers** - e.g. `103`, `2.5`, `.5`
* **arrays** - e.g. `[1, 2, 3]`
* **maps** - e.g. `{foo: "bar"}`
* **booleans** - `true` and `false`
* **nil** - `nil`
### Strings

## Digit separators
Single or double quotes. Unicode sequences (`\uXXXX`) are supported.

Integer literals may contain digit separators to allow digit grouping into more
legible forms.
### Numbers

Example:
Integers and floats.

```js
10_000_000_000
```
* `42`
* `3.14`
* `1e6`
* `0x2A`
* `1_000_000`

## Fields
### Arrays

Struct fields and map elements can be accessed by using the `.` or the `[]`
syntax.
* `[1, 2, 3]`

```js
foo.Field
bar["some-key"]
```
Tailing commas are allowed.

## Functions
### Maps

Functions may be called using the `()` syntax.
* `{foo: "bar"}`

```js
foo.Method()
```
Tailing commas are allowed.

## Operators

Expand All @@ -86,7 +78,7 @@ foo.Method()

Example:

```js
```
x^2 + y^2
```

Expand All @@ -107,7 +99,7 @@ x^2 + y^2

Example:

```js
```
life < universe || life < everything
```

Expand All @@ -121,23 +113,27 @@ life < universe || life < everything

Example:

```js
```
"hello" matches "h.*"
```

### Membership Operators

* `.` (dot)
* `in` (contain)
* `not in` (does not contain)

Struct fields and map elements can be accessed by using the `.` or the `[]`
syntax.

Example:

```js
```
user.Group in ["human_resources", "marketing"]
```

```js
"foo" in {foo: 1, bar: 2}
```
data["tag-name"] in {foo: 1, bar: 2}
```

### Range Operator
Expand All @@ -146,13 +142,13 @@ user.Group in ["human_resources", "marketing"]

Example:

```js
```
user.Age in 18..45
```

The range is inclusive:

```js
```
1..3 == [1, 2, 3]
```

Expand All @@ -166,7 +162,7 @@ Example:

Variable `array` is `[1,2,3,4,5]`.

```js
```
array[1:4] == [2,3,4]
array[:3] == [1,2,3]
array[3:] == [4,5]
Expand All @@ -179,7 +175,7 @@ array[:] == array

Example:

```js
```
user.Age > 30 ? "mature" : "immature"
```

Expand All @@ -190,7 +186,7 @@ user.Age > 30 ? "mature" : "immature"
Returns **true** if all elements satisfies the [predicate](#predicate).
If the array is empty, returns **true**.

```js
```
all(Tweets, {.Size < 280})
```

Expand All @@ -199,13 +195,12 @@ all(Tweets, {.Size < 280})
Returns **true** if any elements satisfies the [predicate](#predicate).
If the array is empty, returns **false**.


### `one(array, predicate)`

Returns **true** if _exactly one_ element satisfies the [predicate](#predicate).
If the array is empty, returns **false**.

```js
```
one(Participants, {.Winner})
```

Expand All @@ -232,22 +227,22 @@ Returns new array by filtering elements of the array by [predicate](#predicate).
Returns the number of elements what satisfies the [predicate](#predicate).
Equivalent to:

```js
```
len(filter(array, predicate))
```

## Predicate

The predicate is an expression that accepts a single argument. To access
The predicate is an expression that accepts a single argument. To access
the argument use the `#` symbol.

```js
```
map(0..9, {# / 2})
```

If items of the array is a struct or a map, it is possible to access fields with
If items of the array is a struct or a map, it is possible to access fields with
omitted `#` symbol (`#.Value` becomes `.Value`).

```js
```
filter(Tweets, {len(.Value) > 280})
```

0 comments on commit bbf30b4

Please sign in to comment.