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????..` |
|
||||
| `FLOAT` | `42.0`, `-123.456`, `0.0` |
|
||||
| [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`] | `[ ???, ???, ??? ]` |
|
||||
| [Object map] | `#{ a: ???, b: ???, c: ???, "def": ??? }` |
|
||||
| Boolean true | `true` |
|
||||
|
@ -8,18 +8,19 @@ Operators
|
||||
---------
|
||||
|
||||
| Operator | Description | Binary? | Binding direction |
|
||||
| :---------------: | ------------------------------ | :-----: | :---------------: |
|
||||
| :-----------------------------------------------------------------------------------------: | -------------------------------------- | :--------: | :---------------: |
|
||||
| `+` | add | yes | left |
|
||||
| `-` | subtract, Minus | yes/no | left |
|
||||
| `-` | 1) subtract<br/>2) negative | yes<br/>no | left<br/>right |
|
||||
| `*` | multiply | yes | left |
|
||||
| `/` | divide | yes | left |
|
||||
| `%` | modulo | yes | left |
|
||||
| `~` | power | yes | left |
|
||||
| `>>` | right bit-shift | yes | left |
|
||||
| `<<` | left bit-shift | yes | left |
|
||||
| `&` | bit-wise _And_, boolean _And_ | yes | left |
|
||||
| <code>\|</code> | bit-wise _Or_, boolean _Or_ | yes | left |
|
||||
| `^` | bit-wise _Xor_, boolean _Xor_ | yes | left |
|
||||
| `&` | 1) bit-wise _And_<br/>2) boolean _And_ | yes | left |
|
||||
| <code>\|</code> | 1) bit-wise _Or_<br/>2) boolean _Or_ | yes | left |
|
||||
| `^` | 1) bit-wise _Xor_<br/>2) boolean _Xor_ | yes | left |
|
||||
| `=`, `+=`, `-=`, `*=`, `/=`,<br/>`~=`, `%=`, `<<=`, `>>=`, `&=`,<br/><code>\|=</code>, `^=` | assignments | yes | right |
|
||||
| `==` | equals to | yes | left |
|
||||
| `~=` | not equals to | yes | left |
|
||||
| `>` | greater than | yes | left |
|
||||
@ -30,23 +31,38 @@ Operators
|
||||
| <code>\|\|</code> | boolean _Or_ (short-circuits) | yes | left |
|
||||
| `!` | boolean _Not_ | no | left |
|
||||
| `[` .. `]` | indexing | yes | right |
|
||||
| `.` | property access, method call | yes | right |
|
||||
| `.` | 1) property access<br/>2) method call | yes | right |
|
||||
|
||||
|
||||
Symbols
|
||||
-------
|
||||
Symbols and Patterns
|
||||
--------------------
|
||||
|
||||
| Symbol | Description |
|
||||
| ------------ | ------------------------ |
|
||||
| `:` | property value separator |
|
||||
| `::` | module path separator |
|
||||
| `#` | _reserved_ |
|
||||
| `=>` | _reserved_ |
|
||||
| `->` | _reserved_ |
|
||||
| `<-` | _reserved_ |
|
||||
| `===` | _reserved_ |
|
||||
| `!==` | _reserved_ |
|
||||
| `:=` | _reserved_ |
|
||||
| `::<` .. `>` | _reserved_ |
|
||||
| `@` | _reserved_ |
|
||||
| `(*` .. `*)` | _reserved_ |
|
||||
| Symbol | Name | Description |
|
||||
| ---------------------------------- | :------------------: | ------------------------------------- |
|
||||
| `;` | semicolon | statement separator |
|
||||
| `,` | comma | list separator |
|
||||
| `:` | colon | [object map] property value separator |
|
||||
| `::` | path | module path separator |
|
||||
| `#{` .. `}` | hash map | [object map] literal |
|
||||
| `"` .. `"` | double quote | [string] |
|
||||
| `'` .. `'` | single quote | [character][string] |
|
||||
| `\` | escape | escape character literal |
|
||||
| `(` .. `)` | parentheses | expression grouping |
|
||||
| `{` .. `}` | braces | block statement |
|
||||
| <code>\|</code> .. <code>\|</code> | pipes | closure |
|
||||
| `[` .. `]` | 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
|
||||
const ABC = 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 { print("done!"); } // <- the line above is equivalent to this
|
||||
|
||||
print("done!"); // <- the line above is further simplified to this
|
||||
// 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`]).
|
||||
|
||||
```rust
|
||||
// The following is most likely generated by machine.
|
||||
|
||||
const DECISION = 1; // this is an integer, one of the standard types
|
||||
|
||||
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_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 |
|
||||
| `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 |
|
||||
| `internals` | yes | exposes internal data structures (e.g. [`AST`] nodes). Beware that Rhai internals are volatile and may change from version to version |
|
||||
|
||||
|
||||
Example
|
||||
|
@ -1391,6 +1391,8 @@ fn get_next_token_inner(
|
||||
|
||||
('@', _) => return Some((Token::Reserved("@".into()), start_pos)),
|
||||
|
||||
('$', _) => return Some((Token::Reserved("$".into()), start_pos)),
|
||||
|
||||
('\0', _) => unreachable!(),
|
||||
|
||||
(ch, _) if ch.is_whitespace() => (),
|
||||
|
Loading…
Reference in New Issue
Block a user