Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Feb 7, 2023
1 parent 7b5f72b commit b32f28a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 45 deletions.
2 changes: 0 additions & 2 deletions docs/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,3 @@ Here is another example with a few function signatures:
new(func(string) int),
)
```

* Next: [Operator Overloading](Operator-Overloading.md)
2 changes: 0 additions & 2 deletions docs/Internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,3 @@ fib(42)
Will be replaced with the result of `fib`(42)` on the compile step.

[ConstExpr Example](https://pkg.go.dev/github.com/antonmedv/expr?tab=doc#ConstExpr)

* Next: [Tips](Tips.md)
51 changes: 14 additions & 37 deletions docs/Language-Definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@
<tr>
<td>Map</td>
<td>
<code>{a: 1, b: 2, c: 3}</code>
<code>&#123;a: 1, b: 2, c: 3&#125;</code>
</td>
</tr>
<tr>
<td>Nil</t
d>
<td>Nil</td>
<td>
<code>nil</code>
</td>
Expand Down Expand Up @@ -116,11 +115,11 @@ d>

Examples:

```c++
```expr
user.Age in 18..45 and user.Name not in ["admin", "root"]
```

```c++
```expr
foo matches "^[A-Z].*"
```

Expand All @@ -143,7 +142,7 @@ The `?.` operator can be used to access a field of a struct or an item of a map
without checking if the struct or the map is `nil`. If the struct or the map is
`nil`, the result of the expression is `nil`.

```c++
```expr
author?.User?.Name
```

Expand All @@ -152,7 +151,7 @@ author?.User?.Name
The `??` operator can be used to return the left-hand side if it is not `nil`,
otherwise the right-hand side is returned.

```c++
```expr
author?.User?.Name ?? "Anonymous"
```

Expand All @@ -162,7 +161,7 @@ The slice operator `[:]` can be used to access a slice of an array.

For example, variable `array` is `[1, 2, 3, 4, 5]`:

```c++
```expr
array[1:4] == [2, 3, 4]
array[1:-1] == [2, 3, 4]
array[:3] == [1, 2, 3]
Expand All @@ -173,34 +172,12 @@ array[:] == array

## Built-in Functions

<table>
<tr>
<td>
<a href="#allarray-predicate">all()</a><br>
<a href="#anyarray-predicate">any()</a><br>
<a href="#onearray-predicate">one()</a><br>
<a href="#nonearray-predicate">none()</a><br>
</td>
<td>
<a href="#maparray-predicate">map()</a><br>
<a href="#filterarray-predicate">filter()</a><br>
<a href="#countarray-predicate">count()</a><br>
</td>
<td>
<a href="#lenv">len()</a><br>
<a href="#absv">abs()</a><br>
<a href="#intv">int()</a><br>
<a href="#floatv">float()</a><br>
</td>
</tr>
</table>

### all(array, predicate)

Returns **true** if all elements satisfies the [predicate](#predicate).
If the array is empty, returns **true**.

```c++
```expr
all(Tweets, {.Size < 280})
```

Expand All @@ -214,7 +191,7 @@ If the array is empty, returns **false**.
Returns **true** if _exactly one_ element satisfies the [predicate](#predicate).
If the array is empty, returns **false**.

```c++
```expr
one(Participants, {.Winner})
```

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

```c++
```expr
len(filter(array, predicate))
```

Expand All @@ -253,7 +230,7 @@ Returns the absolute value of a number.

Returns the integer value of a number or a string.

```c++
```expr
int("123") == 123
```

Expand All @@ -266,19 +243,19 @@ Returns the float value of a number or a string.
The predicate is an expression that accepts a single argument. To access
the argument use the `#` symbol.

```c++
```expr
map(0..9, {# / 2})
```

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

```c++
```expr
filter(Tweets, {len(.Value) > 280})
```

Braces `{` `}` can be omitted:

```c++
```expr
filter(Tweets, len(.Value) > 280)
```
2 changes: 0 additions & 2 deletions docs/Operator-Overloading.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,3 @@ func (Env) Sub(a, b time.Time) time.Duration { return a.Sub(b) }
**Expr** uses functions from `Env` for operator overloading. If types of
operands match types of a function, the operator will be replaced with a
function call.

* Next: [Visitor and Patch](Visitor-and-Patch.md)
2 changes: 0 additions & 2 deletions docs/Visitor-and-Patch.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,3 @@ func (p *stringerPatcher) Visit(node *ast.Node) {

}
```

* Next: [Internals](Internals.md)

0 comments on commit b32f28a

Please sign in to comment.