Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
leongrdic committed Jun 13, 2022
1 parent 68d849d commit 41d9ec6
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,48 @@ Vars passed this way will override vars passed in the constructor and will only

In case of an exception, `Le\SMPLang\Exception` will be thrown with a short description of the error.

## Syntax
## Expression syntax

Vars are accessed by only their name. If a var is not provided in neither constructor or `evaluate()`, an exception will be thrown.
Vars are accessed by only their name. If a var is not defined in neither constructor or `evaluate()`, an exception will be thrown.

Array elements are accessed with one of the following syntaxes: `array.key.0` or `array['key'][0]` (which allows for dynamic array access).
### Supported literals
- `null`
- booleans (`true` and `false`)
- strings (`"string"` or `'string'` or <code>\`string\`</code>)
- numbers (`1`, `1.2`, `-1`, `-1.2`)
- arrays (`[23, 'string']` or `["key": 23, 'key2': 'string']`)
- objects (`{foo: "bar", baz: 23}`)

Object properties and methods are accessed with the following syntax: `object.property` or `object.method(parameters)`.

Closures/functions are called with the following syntax: `closure(paramValue, ...)`. Named arguments are supported using the following syntax: `closure(param: value, ...)`.
### Arrays

Array unpacking (`...array`) is supported both in array definitions and closure calls.
Array definition: `[element1, element2]`

Arrays can be defined using any of the following two syntaxes: `[element1, element2, ...]` or `{element1, element2, ...}`.
Associative array definition: `["key": element, string_variable: element2]`

Arrays can also serve as hashes by providing keys: `{key1: value1, key2: value2, ...}` or `["key1": value1, "key2": "value2", ...]`. The latter syntax can be used to define arrays with dynamic keys by passing vars as keys.
You can define associative arrays with dynamic keys by using string vars in place of keys.

Array unpacking is supported: `[element1, ...array, ...array2]`

Access array elements using either of the following syntaxes: `array.key.0` or `array['key'][0]` (which allows for dynamic array access).

### Objects

Object definition: `{foo: "bar", baz: 23}` (supports array unpacking)

Object property access: `object.property`

Object method call: `object.method(parameters)`

### Function / closure call

Call a function or closure var: `closure_var(param1, param2)`.

Named arguments: `foo(search: value, count: 1)`.

Function / closure calls support array unpacking: `bar(param1, ...array, ...array2)`


### Supported literals
- `null`
- booleans (`true` and `false`)
- strings (`"string"` or `'string'` or <code>\`string\`</code>)
- numbers (`1`, `1.2`, `-1`, `-1.2`)
- arrays (`[23, 'string']` or `{foo: "bar", baz: 23}`)

### Arithmetic operators
- `+`: addition
Expand Down

0 comments on commit 41d9ec6

Please sign in to comment.