Do not parse closures when allow_anonymous_fn is false.

This commit is contained in:
Stephen Chung
2020-08-22 11:08:27 +08:00
parent 24610688d3
commit 0b04d05afe
4 changed files with 84 additions and 3 deletions

View File

@@ -11,9 +11,11 @@ In these cases, use the `Engine::compile_expression` and `Engine::eval_expressio
let result = engine.eval_expression::<i64>("2 + (10 + 10) * 2")?;
```
When evaluating _expressions_, no full-blown statement (e.g. `if`, `while`, `for`) - not even variable assignment -
When evaluating _expressions_, no full-blown statement (e.g. `if`, `while`, `for`, `fn`) - not even variable assignment -
is supported and will be considered parse errors when encountered.
[Closures] and [anonymous functions] are also not supported because in the background they compile to functions.
```rust
// The following are all syntax errors because the script is not an expression.