Reserve $ symbol.
This commit is contained in:
parent
44f8d9e429
commit
1de44c7ecd
@ -8,7 +8,7 @@ Literals Syntax
|
|||||||
| `INT` | decimal: `42`, `-123`, `0`<br/>hex: `0x????..`<br/>binary: `0b????..`<br/>octal: `0o????..` |
|
| `INT` | decimal: `42`, `-123`, `0`<br/>hex: `0x????..`<br/>binary: `0b????..`<br/>octal: `0o????..` |
|
||||||
| `FLOAT` | `42.0`, `-123.456`, `0.0` |
|
| `FLOAT` | `42.0`, `-123.456`, `0.0` |
|
||||||
| [String] | `"... \x?? \u???? \U???????? ..."` |
|
| [String] | `"... \x?? \u???? \U???????? ..."` |
|
||||||
| Character | single: `'?'`<br/>ASCII hex: `'\x??'`<br/>Unicode: `'\u????'`, `'\U????????'` |
|
| [Character][string] | single: `'?'`<br/>ASCII hex: `'\x??'`<br/>Unicode: `'\u????'`, `'\U????????'` |
|
||||||
| [`Array`] | `[ ???, ???, ??? ]` |
|
| [`Array`] | `[ ???, ???, ??? ]` |
|
||||||
| [Object map] | `#{ a: ???, b: ???, c: ???, "def": ??? }` |
|
| [Object map] | `#{ a: ???, b: ???, c: ???, "def": ??? }` |
|
||||||
| Boolean true | `true` |
|
| Boolean true | `true` |
|
||||||
|
@ -8,18 +8,19 @@ Operators
|
|||||||
---------
|
---------
|
||||||
|
|
||||||
| Operator | Description | Binary? | Binding direction |
|
| Operator | Description | Binary? | Binding direction |
|
||||||
| :---------------: | ------------------------------ | :-----: | :---------------: |
|
| :-----------------------------------------------------------------------------------------: | -------------------------------------- | :--------: | :---------------: |
|
||||||
| `+` | add | yes | left |
|
| `+` | add | yes | left |
|
||||||
| `-` | subtract, Minus | yes/no | left |
|
| `-` | 1) subtract<br/>2) negative | yes<br/>no | left<br/>right |
|
||||||
| `*` | multiply | yes | left |
|
| `*` | multiply | yes | left |
|
||||||
| `/` | divide | yes | left |
|
| `/` | divide | yes | left |
|
||||||
| `%` | modulo | yes | left |
|
| `%` | modulo | yes | left |
|
||||||
| `~` | power | yes | left |
|
| `~` | power | yes | left |
|
||||||
| `>>` | right bit-shift | yes | left |
|
| `>>` | right bit-shift | yes | left |
|
||||||
| `<<` | left bit-shift | yes | left |
|
| `<<` | left bit-shift | yes | left |
|
||||||
| `&` | bit-wise _And_, boolean _And_ | yes | left |
|
| `&` | 1) bit-wise _And_<br/>2) boolean _And_ | yes | left |
|
||||||
| <code>\|</code> | bit-wise _Or_, boolean _Or_ | yes | left |
|
| <code>\|</code> | 1) bit-wise _Or_<br/>2) boolean _Or_ | yes | left |
|
||||||
| `^` | bit-wise _Xor_, boolean _Xor_ | yes | left |
|
| `^` | 1) bit-wise _Xor_<br/>2) boolean _Xor_ | yes | left |
|
||||||
|
| `=`, `+=`, `-=`, `*=`, `/=`,<br/>`~=`, `%=`, `<<=`, `>>=`, `&=`,<br/><code>\|=</code>, `^=` | assignments | yes | right |
|
||||||
| `==` | equals to | yes | left |
|
| `==` | equals to | yes | left |
|
||||||
| `~=` | not equals to | yes | left |
|
| `~=` | not equals to | yes | left |
|
||||||
| `>` | greater than | yes | left |
|
| `>` | greater than | yes | left |
|
||||||
@ -30,23 +31,38 @@ Operators
|
|||||||
| <code>\|\|</code> | boolean _Or_ (short-circuits) | yes | left |
|
| <code>\|\|</code> | boolean _Or_ (short-circuits) | yes | left |
|
||||||
| `!` | boolean _Not_ | no | left |
|
| `!` | boolean _Not_ | no | left |
|
||||||
| `[` .. `]` | indexing | yes | right |
|
| `[` .. `]` | indexing | yes | right |
|
||||||
| `.` | property access, method call | yes | right |
|
| `.` | 1) property access<br/>2) method call | yes | right |
|
||||||
|
|
||||||
|
|
||||||
Symbols
|
Symbols and Patterns
|
||||||
-------
|
--------------------
|
||||||
|
|
||||||
| Symbol | Description |
|
| Symbol | Name | Description |
|
||||||
| ------------ | ------------------------ |
|
| ---------------------------------- | :------------------: | ------------------------------------- |
|
||||||
| `:` | property value separator |
|
| `;` | semicolon | statement separator |
|
||||||
| `::` | module path separator |
|
| `,` | comma | list separator |
|
||||||
| `#` | _reserved_ |
|
| `:` | colon | [object map] property value separator |
|
||||||
| `=>` | _reserved_ |
|
| `::` | path | module path separator |
|
||||||
| `->` | _reserved_ |
|
| `#{` .. `}` | hash map | [object map] literal |
|
||||||
| `<-` | _reserved_ |
|
| `"` .. `"` | double quote | [string] |
|
||||||
| `===` | _reserved_ |
|
| `'` .. `'` | single quote | [character][string] |
|
||||||
| `!==` | _reserved_ |
|
| `\` | escape | escape character literal |
|
||||||
| `:=` | _reserved_ |
|
| `(` .. `)` | parentheses | expression grouping |
|
||||||
| `::<` .. `>` | _reserved_ |
|
| `{` .. `}` | braces | block statement |
|
||||||
| `@` | _reserved_ |
|
| <code>\|</code> .. <code>\|</code> | pipes | closure |
|
||||||
| `(*` .. `*)` | _reserved_ |
|
| `[` .. `]` | brackets | [array] literal |
|
||||||
|
| `!` | bang | function call in calling scope |
|
||||||
|
| `//` | comment | line comment |
|
||||||
|
| `/*` .. `*/` | comment | block comment |
|
||||||
|
| `(*` .. `*)` | comment | _reserved_ |
|
||||||
|
| `<` .. `>` | angular brackets | _reserved_ |
|
||||||
|
| `#` | hash | _reserved_ |
|
||||||
|
| `@` | at | _reserved_ |
|
||||||
|
| `$` | dollar | _reserved_ |
|
||||||
|
| `=>` | double arrow | _reserved_ |
|
||||||
|
| `->` | arrow | _reserved_ |
|
||||||
|
| `<-` | left arrow | _reserved_ |
|
||||||
|
| `===` | strict equals to | _reserved_ |
|
||||||
|
| `!==` | strict not equals to | _reserved_ |
|
||||||
|
| `:=` | assignment | _reserved_ |
|
||||||
|
| `::<` .. `>` | turbofish | _reserved_ |
|
||||||
|
@ -47,9 +47,13 @@ Constants propagation is used to remove dead code:
|
|||||||
|
|
||||||
```rust
|
```rust
|
||||||
const ABC = true;
|
const ABC = true;
|
||||||
|
|
||||||
if ABC || some_work() { print("done!"); } // 'ABC' is constant so it is replaced by 'true'...
|
if ABC || some_work() { print("done!"); } // 'ABC' is constant so it is replaced by 'true'...
|
||||||
|
|
||||||
if true || some_work() { print("done!"); } // since '||' short-circuits, 'some_work' is never called
|
if true || some_work() { print("done!"); } // since '||' short-circuits, 'some_work' is never called
|
||||||
|
|
||||||
if true { print("done!"); } // <- the line above is equivalent to this
|
if true { print("done!"); } // <- the line above is equivalent to this
|
||||||
|
|
||||||
print("done!"); // <- the line above is further simplified to this
|
print("done!"); // <- the line above is further simplified to this
|
||||||
// because the condition is always true
|
// because the condition is always true
|
||||||
```
|
```
|
||||||
@ -84,6 +88,8 @@ Rhai guarantees that no external function will be run (in order not to trigger s
|
|||||||
optimization process (unless the optimization level is set to [`OptimizationLevel::Full`]).
|
optimization process (unless the optimization level is set to [`OptimizationLevel::Full`]).
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
// The following is most likely generated by machine.
|
||||||
|
|
||||||
const DECISION = 1; // this is an integer, one of the standard types
|
const DECISION = 1; // this is an integer, one of the standard types
|
||||||
|
|
||||||
if DECISION == 1 { // this is optimized into 'true'
|
if DECISION == 1 { // this is optimized into 'true'
|
||||||
|
@ -26,8 +26,8 @@ more control over what a script can (or cannot) do.
|
|||||||
| `no_closure` | no | disables [capturing][automatic currying] external variables in [anonymous functions] to simulate _closures_, or [capturing the calling scope]({{rootUrl}}/language/fn-capture.md) in function calls |
|
| `no_closure` | no | disables [capturing][automatic currying] external variables in [anonymous functions] to simulate _closures_, or [capturing the calling scope]({{rootUrl}}/language/fn-capture.md) in function calls |
|
||||||
| `no_std` | no | builds for `no-std` (implies `no_closure`). Notice that additional dependencies will be pulled in to replace `std` features |
|
| `no_std` | no | builds for `no-std` (implies `no_closure`). Notice that additional dependencies will be pulled in to replace `std` features |
|
||||||
| `serde` | yes | enables serialization/deserialization via `serde`. Notice that the [`serde`](https://crates.io/crates/serde) crate will be pulled in together with its dependencies |
|
| `serde` | yes | enables serialization/deserialization via `serde`. Notice that the [`serde`](https://crates.io/crates/serde) crate will be pulled in together with its dependencies |
|
||||||
| `internals` | yes | exposes internal data structures (e.g. [`AST`] nodes). Beware that Rhai internals are volatile and may change from version to version |
|
|
||||||
| `unicode-xid-ident` | no | allows [Unicode Standard Annex #31](http://www.unicode.org/reports/tr31/) as identifiers |
|
| `unicode-xid-ident` | no | allows [Unicode Standard Annex #31](http://www.unicode.org/reports/tr31/) as identifiers |
|
||||||
|
| `internals` | yes | exposes internal data structures (e.g. [`AST`] nodes). Beware that Rhai internals are volatile and may change from version to version |
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
|
@ -1391,6 +1391,8 @@ fn get_next_token_inner(
|
|||||||
|
|
||||||
('@', _) => return Some((Token::Reserved("@".into()), start_pos)),
|
('@', _) => return Some((Token::Reserved("@".into()), start_pos)),
|
||||||
|
|
||||||
|
('$', _) => return Some((Token::Reserved("$".into()), start_pos)),
|
||||||
|
|
||||||
('\0', _) => unreachable!(),
|
('\0', _) => unreachable!(),
|
||||||
|
|
||||||
(ch, _) if ch.is_whitespace() => (),
|
(ch, _) if ch.is_whitespace() => (),
|
||||||
|
Loading…
Reference in New Issue
Block a user