Add feature to disable symbols.
This commit is contained in:
28
doc/src/engine/disable.md
Normal file
28
doc/src/engine/disable.md
Normal file
@@ -0,0 +1,28 @@
|
||||
Disable Certain Keywords and/or Operators
|
||||
========================================
|
||||
|
||||
{{#include ../links.md}}
|
||||
|
||||
For certain embedded usage, it is sometimes necessary to restrict the language to a strict subset of Rhai
|
||||
to prevent usage of certain language features.
|
||||
|
||||
Rhai supports surgically disabling a keyword or operator via the `Engine::disable_symbol` method.
|
||||
|
||||
```rust
|
||||
use rhai::Engine;
|
||||
|
||||
let mut engine = Engine::new();
|
||||
|
||||
engine.disable_symbol("if"); // disable the 'if' keyword
|
||||
engine.disable_symbol("+="); // disable the '+=' operator
|
||||
|
||||
// The following all return parse errors.
|
||||
|
||||
engine.compile("let x = if true { 42 } else { 0 };")?;
|
||||
// ^ missing ';' after statement end
|
||||
// ^ 'if' is parsed as a variable name
|
||||
|
||||
engine.compile("let x = 40 + 2; x += 1;")?;
|
||||
// ^ '+=' is not recognized as an operator
|
||||
// ^ other operators are not affected
|
||||
```
|
Reference in New Issue
Block a user