Skip to content

Commit c30485d

Browse files
committed
Update Language-Definition.md
1 parent a682629 commit c30485d

File tree

1 file changed

+30
-43
lines changed

1 file changed

+30
-43
lines changed

docs/Language-Definition.md

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Language Definition
22

3-
**Expr** package uses a specific syntax. In this document, you can find all supported
4-
syntaxes.
3+
**Expr** is an expression evaluation language for Go.
54

65
## Supported Literals
76

@@ -24,26 +23,24 @@ Example:
2423
10_000_000_000
2524
```
2625

27-
## Accessing Public Properties
26+
## Fields
2827

29-
Public properties on structs can be accessed by using the `.` syntax.
30-
If you pass an array into an expression, use the `[]` syntax to access array keys.
28+
Struct fields and map elements can be accessed by using the `.` or the `[]` syntax.
3129

32-
```js
33-
foo.Array[0].Value
30+
```
31+
foo.Field
32+
bar["some-key"]
3433
```
3534

36-
## Functions and Methods
35+
## Functions
3736

38-
Functions may be called using `()` syntax. The `.` syntax can also be used to call methods on an struct.
37+
Functions may be called using the `()` syntax.
3938

40-
```js
41-
price.String()
39+
```
40+
foo.Method()
4241
```
4342

44-
## Supported Operators
45-
46-
The package comes with a lot of operators:
43+
## Operators
4744

4845
### Arithmetic Operators
4946

@@ -56,8 +53,8 @@ The package comes with a lot of operators:
5653

5754
Example:
5855

59-
```js
60-
life + universe + everything
56+
```
57+
x**2 + y
6158
```
6259

6360
### Comparison Operators
@@ -89,21 +86,11 @@ life < universe || life < everything
8986
* `startsWith` (has prefix)
9087
* `endsWith` (has suffix)
9188

92-
To test if a string does *not* match a regex, use the logical `not` operator in combination with the `matches` operator:
93-
94-
```js
95-
not ("foo" matches "^b.+")
96-
```
97-
98-
You must use parenthesis because the unary operator `not` has precedence over the binary operator `matches`.
99-
10089
Example:
10190

102-
```js
103-
'Arthur' + ' ' + 'Dent'
10491
```
105-
106-
Result will be set to `Arthur Dent`.
92+
"hello" matches "h.*"
93+
```
10794

10895
### Membership Operators
10996

@@ -112,11 +99,11 @@ Result will be set to `Arthur Dent`.
11299

113100
Example:
114101

115-
```js
102+
```
116103
user.Group in ["human_resources", "marketing"]
117104
```
118105

119-
```js
106+
```
120107
"foo" in {foo: 1, bar: 2}
121108
```
122109

@@ -126,13 +113,13 @@ user.Group in ["human_resources", "marketing"]
126113

127114
Example:
128115

129-
```js
116+
```
130117
user.Age in 18..45
131118
```
132119

133120
The range is inclusive:
134121

135-
```js
122+
```
136123
1..3 == [1, 2, 3]
137124
```
138125

@@ -142,15 +129,15 @@ The range is inclusive:
142129

143130
Example:
144131

145-
```js
132+
```
146133
user.Age > 30 ? "mature" : "immature"
147134
```
148135

149136
## Builtin functions
150137

151138
* `len` (length of array, map or string)
152139
* `all` (will return `true` if all element satisfies the predicate)
153-
* `none` (will return `true` if all element does NOT satisfies the predicate)
140+
* `none` (will return `true` if all element does NOT satisfy the predicate)
154141
* `any` (will return `true` if any element satisfies the predicate)
155142
* `one` (will return `true` if exactly ONE element satisfies the predicate)
156143
* `filter` (filter array by the predicate)
@@ -161,29 +148,29 @@ Examples:
161148

162149
Ensure all tweets are less than 280 chars.
163150

164-
```js
151+
```
165152
all(Tweets, {.Size < 280})
166153
```
167154

168155
Ensure there is exactly one winner.
169156

170-
```js
157+
```
171158
one(Participants, {.Winner})
172159
```
173160

174161
## Closures
175162

176-
* `{...}` (closure)
177-
178-
Closures allowed only with builtin functions. To access current item use `#` symbol.
163+
The closure is an expression that accepts a single argument. To access
164+
the argument use the `#` symbol.
179165

180-
```js
166+
```
181167
map(0..9, {# / 2})
182168
```
183169

184-
If the item of array is struct, it's possible to access fields of struct with omitted `#` symbol (`#.Value` becomes `.Value`).
170+
If the item of array is struct, it is possible to access fields of struct with
171+
omitted `#` symbol (`#.Value` becomes `.Value`).
185172

186-
```js
173+
```
187174
filter(Tweets, {len(.Value) > 280})
188175
```
189176

@@ -197,7 +184,7 @@ Example:
197184

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

200-
```js
187+
```
201188
array[1:5] == [2,3,4]
202189
array[3:] == [4,5]
203190
array[:4] == [1,2,3]

0 commit comments

Comments
 (0)