eww/docs/content/main/expression_language.md
ElKowar 9a8bbf4114
Expression language (#124)
* Add AST

* add make-shift testing parser, and make stuff ocmpile

* add proper expression parser

* make string format use '

* Add empty doc page for expressions

* add tests

* Clean up file structure and add unary operators

* Write documentation
2021-03-02 10:27:52 +01:00

33 lines
926 B
Markdown

+++
title = "Eww expressions"
slug = "Embedded eww expression language"
weight = 6
+++
# The embedded Eww expression-language
Within variable references, you can make use of a small, built-in expression language.
This can be used whereever you can use variable-references (`{{varname}}`).
## Example
```xml
<button
class="{{if button_active then 'active' else 'inactive'}}"
onclick="toggle_thing">
{{if button_active then 'disable' else 'enable'}}
</button>
Some math: {{12 + 2 * 10}}
```
## Syntax
The expression language supports:
- simple mathematical operations (`+`, `-`, `*`, `/`, `%`)
- comparisons (`==`, `!=`, `>`, `<`)
- boolean operations (`||`, `&&`, `!`)
- conditionals (`if condition then 'value' else 'other value'`)
- numbers, strings, booleans and variable references (`12`, `'hi'`, `true`, `some_variable`)
- strings can contain other expressions again: `'foo {{some_variable}} bar'`