Reserve begin/end.
This commit is contained in:
parent
eb4636f219
commit
97368da762
@ -19,7 +19,7 @@ Breaking changes
|
|||||||
----------------
|
----------------
|
||||||
|
|
||||||
* `Module::set_fn`, `Module::set_raw_fn` and `Module::set_fn_XXX_mut` all take an additional parameter of `FnNamespace`.
|
* `Module::set_fn`, `Module::set_raw_fn` and `Module::set_fn_XXX_mut` all take an additional parameter of `FnNamespace`.
|
||||||
* `unless` is now a reserved keyword.
|
* `begin`, `end`, `unless` are now reserved keywords.
|
||||||
* `EvalPackage` is removed in favor of `Engine::disable_symbol`.
|
* `EvalPackage` is removed in favor of `Engine::disable_symbol`.
|
||||||
|
|
||||||
New features
|
New features
|
||||||
|
@ -97,7 +97,7 @@ The Rhai Scripting Language
|
|||||||
19. [Modules](language/modules/index.md)
|
19. [Modules](language/modules/index.md)
|
||||||
1. [Export Variables, Functions and Sub-Modules](language/modules/export.md)
|
1. [Export Variables, Functions and Sub-Modules](language/modules/export.md)
|
||||||
2. [Import Modules](language/modules/import.md)
|
2. [Import Modules](language/modules/import.md)
|
||||||
20. [Eval Statement](language/eval.md)
|
20. [Eval Function](language/eval.md)
|
||||||
6. [Safety and Protection](safety/index.md)
|
6. [Safety and Protection](safety/index.md)
|
||||||
1. [Checked Arithmetic](safety/checked.md)
|
1. [Checked Arithmetic](safety/checked.md)
|
||||||
2. [Sand-Boxing](safety/sandbox.md)
|
2. [Sand-Boxing](safety/sandbox.md)
|
||||||
|
@ -49,6 +49,8 @@ Reserved Keywords
|
|||||||
| --------- | --------------------- |
|
| --------- | --------------------- |
|
||||||
| `var` | variable declaration |
|
| `var` | variable declaration |
|
||||||
| `static` | variable declaration |
|
| `static` | variable declaration |
|
||||||
|
| `begin` | block scope |
|
||||||
|
| `end` | block scope |
|
||||||
| `shared` | share value |
|
| `shared` | share value |
|
||||||
| `each` | looping |
|
| `each` | looping |
|
||||||
| `then` | control flow |
|
| `then` | control flow |
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
`eval` Statement
|
`eval` Function
|
||||||
===============
|
===============
|
||||||
|
|
||||||
{{#include ../links.md}}
|
{{#include ../links.md}}
|
||||||
|
@ -5,21 +5,22 @@ Keywords
|
|||||||
|
|
||||||
The following are reserved keywords in Rhai:
|
The following are reserved keywords in Rhai:
|
||||||
|
|
||||||
| Active keywords | Reserved keywords | Usage | Inactive under feature |
|
| Active keywords | Reserved keywords | Usage | Inactive under feature |
|
||||||
| ------------------------------------------------- | ---------------------------------------------------------- | ---------------------- | :--------------------: |
|
| ---------------------------------------------------------------- | ---------------------------------------------------------- | ---------------------- | :--------------------: |
|
||||||
| `true`, `false` | | boolean constants | |
|
| `true`, `false` | | constants | |
|
||||||
| `let`, `const` | `var`, `static` | variable declarations | |
|
| `let`, `const` | `var`, `static` | variables | |
|
||||||
| `is_shared` | | shared values | [`no_closure`] |
|
| | `begin`, `end` | block scopes | |
|
||||||
| `if`, `else` | `then`, `goto`, `exit` | control flow | |
|
| `is_shared` | | shared values | [`no_closure`] |
|
||||||
| | `switch`, `match`, `case` | matching | |
|
| `if`, `else` | `then`, `unless`, `goto`, `exit` | control flow | |
|
||||||
| `while`, `loop`, `for`, `in`, `continue`, `break` | `do`, `each` | looping | |
|
| `switch` | `match`, `case` | switching and matching | |
|
||||||
| `fn`, `private` | `public`, `new` | functions | [`no_function`] |
|
| `do`, `while`, `loop`, `until`, `for`, `in`, `continue`, `break` | `each` | looping | |
|
||||||
| `return` | | return values | |
|
| `fn`, `private` | `public`, `new` | functions | [`no_function`] |
|
||||||
| `throw`, `try`, `catch` | | throw/catch exceptions | |
|
| `return` | | return values | |
|
||||||
| `import`, `export`, `as` | `use`, `with`, `module`, `package` | modules/packages | [`no_module`] |
|
| `throw`, `try`, `catch` | | throw/catch exceptions | |
|
||||||
| `Fn`, `call`, `curry` | | function pointers | |
|
| `import`, `export`, `as` | `use`, `with`, `module`, `package` | modules/packages | [`no_module`] |
|
||||||
| | `spawn`, `thread`, `go`, `sync`, `async`, `await`, `yield` | threading/async | |
|
| `Fn`, `call`, `curry` | | function pointers | |
|
||||||
| `type_of`, `print`, `debug`, `eval` | | special functions | |
|
| | `spawn`, `thread`, `go`, `sync`, `async`, `await`, `yield` | threading/async | |
|
||||||
| | `default`, `void`, `null`, `nil` | special values | |
|
| `type_of`, `print`, `debug`, `eval` | | special functions | |
|
||||||
|
| | `default`, `void`, `null`, `nil` | special values | |
|
||||||
|
|
||||||
Keywords cannot become the name of a [function] or [variable], even when they are disabled.
|
Keywords cannot become the name of a [function] or [variable], even when they are disabled.
|
||||||
|
@ -9,7 +9,7 @@ Terminated by '`;`'
|
|||||||
Statements are terminated by semicolons '`;`' and they are mandatory,
|
Statements are terminated by semicolons '`;`' and they are mandatory,
|
||||||
except for the _last_ statement in a _block_ (enclosed by '`{`' .. '`}`' pairs) where it can be omitted.
|
except for the _last_ statement in a _block_ (enclosed by '`{`' .. '`}`' pairs) where it can be omitted.
|
||||||
|
|
||||||
Semicolons can also be omitted if the statement contains a block itself
|
Semicolons can also be omitted if the statement ends with a block itself
|
||||||
(e.g. the `if`, `while`, `for` and `loop` statements).
|
(e.g. the `if`, `while`, `for` and `loop` statements).
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
@ -35,6 +35,8 @@ Statement Expression
|
|||||||
A statement can be used anywhere where an expression is expected. These are called, for lack of a more
|
A statement can be used anywhere where an expression is expected. These are called, for lack of a more
|
||||||
creative name, "statement expressions."
|
creative name, "statement expressions."
|
||||||
|
|
||||||
The _last_ statement of a statement block is _always_ the block's return value when used as a statement.
|
The _last_ statement of a statement block is _always_ the block's return value when used as a statement,
|
||||||
|
_regardless_ of whether it is terminated by a semicolon or not. This is different from Rust where,
|
||||||
|
if the last statement is terminated by a semicolon, the block's return value is taken to be `()`.
|
||||||
|
|
||||||
If the last statement has no return value (e.g. variable definitions, assignments) then it is assumed to be [`()`].
|
If the last statement has no return value (e.g. variable definitions, assignments) then it is assumed to be [`()`].
|
||||||
|
13
src/token.rs
13
src/token.rs
@ -532,11 +532,10 @@ impl Token {
|
|||||||
"import" | "export" | "as" => Reserved(syntax.into()),
|
"import" | "export" | "as" => Reserved(syntax.into()),
|
||||||
|
|
||||||
"===" | "!==" | "->" | "<-" | ":=" | "::<" | "(*" | "*)" | "#" | "public" | "new"
|
"===" | "!==" | "->" | "<-" | ":=" | "::<" | "(*" | "*)" | "#" | "public" | "new"
|
||||||
| "use" | "module" | "package" | "var" | "static" | "shared" | "with" | "each"
|
| "use" | "module" | "package" | "var" | "static" | "begin" | "end" | "shared"
|
||||||
| "then" | "goto" | "unless" | "exit" | "match" | "case" | "default" | "void"
|
| "with" | "each" | "then" | "goto" | "unless" | "exit" | "match" | "case"
|
||||||
| "null" | "nil" | "spawn" | "thread" | "go" | "sync" | "async" | "await" | "yield" => {
|
| "default" | "void" | "null" | "nil" | "spawn" | "thread" | "go" | "sync"
|
||||||
Reserved(syntax.into())
|
| "async" | "await" | "yield" => Reserved(syntax.into()),
|
||||||
}
|
|
||||||
|
|
||||||
KEYWORD_PRINT | KEYWORD_DEBUG | KEYWORD_TYPE_OF | KEYWORD_EVAL | KEYWORD_FN_PTR
|
KEYWORD_PRINT | KEYWORD_DEBUG | KEYWORD_TYPE_OF | KEYWORD_EVAL | KEYWORD_FN_PTR
|
||||||
| KEYWORD_FN_PTR_CALL | KEYWORD_FN_PTR_CURRY | KEYWORD_IS_DEF_VAR
|
| KEYWORD_FN_PTR_CALL | KEYWORD_FN_PTR_CURRY | KEYWORD_IS_DEF_VAR
|
||||||
@ -1670,12 +1669,12 @@ impl<'a> Iterator for TokenIterator<'a, '_> {
|
|||||||
"'<-' is not a valid symbol. This is not Go! Should it be '<='?".to_string(),
|
"'<-' is not a valid symbol. This is not Go! Should it be '<='?".to_string(),
|
||||||
)),
|
)),
|
||||||
(":=", false) => Token::LexError(LERR::ImproperSymbol(s,
|
(":=", false) => Token::LexError(LERR::ImproperSymbol(s,
|
||||||
"':=' is not a valid assignment operator. This is not Go! Should it be simply '='?".to_string(),
|
"':=' is not a valid assignment operator. This is not Go or Pascal! Should it be simply '='?".to_string(),
|
||||||
)),
|
)),
|
||||||
("::<", false) => Token::LexError(LERR::ImproperSymbol(s,
|
("::<", false) => Token::LexError(LERR::ImproperSymbol(s,
|
||||||
"'::<>' is not a valid symbol. This is not Rust! Should it be '::'?".to_string(),
|
"'::<>' is not a valid symbol. This is not Rust! Should it be '::'?".to_string(),
|
||||||
)),
|
)),
|
||||||
("(*", false) | ("*)", false) => Token::LexError(LERR::ImproperSymbol(s,
|
("(*", false) | ("*)", false) | ("begin", false) | ("end", false) => Token::LexError(LERR::ImproperSymbol(s,
|
||||||
"'(* .. *)' is not a valid comment format. This is not Pascal! Should it be '/* .. */'?".to_string(),
|
"'(* .. *)' is not a valid comment format. This is not Pascal! Should it be '/* .. */'?".to_string(),
|
||||||
)),
|
)),
|
||||||
("#", false) => Token::LexError(LERR::ImproperSymbol(s,
|
("#", false) => Token::LexError(LERR::ImproperSymbol(s,
|
||||||
|
Loading…
Reference in New Issue
Block a user