diff --git a/RELEASES.md b/RELEASES.md index e3daa084..ad29d3af 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -15,6 +15,7 @@ Breaking changes * The following `EvalAltResult` variants are removed and merged into `EvalAltResult::ErrorMismatchDataType`: `ErrorCharMismatch`, `ErrorNumericIndexExpr`, `ErrorStringIndexExpr`, `ErrorImportExpr`, `ErrorLogicGuard`, `ErrorBooleanArgMismatch` * `Scope::iter_raw` returns an iterator with an additional field indicating whether the variable is constant or not. * `rhai::ser` and `rhai::de` namespaces are merged into `rhai::serde`. +* New reserved symbols: `++`, `--`, `..`, `...`. New features ------------ diff --git a/doc/src/appendix/operators.md b/doc/src/appendix/operators.md index c0fa4292..7f20f003 100644 --- a/doc/src/appendix/operators.md +++ b/doc/src/appendix/operators.md @@ -56,6 +56,10 @@ Symbols and Patterns | `/*` .. `*/` | comment | block comment | | `(*` .. `*)` | comment | _reserved_ | | `<` .. `>` | angular brackets | _reserved_ | +| `++` | increment | _reserved_ | +| `--` | decrement | _reserved_ | +| `..` | range | _reserved_ | +| `...` | range | _reserved_ | | `#` | hash | _reserved_ | | `@` | at | _reserved_ | | `$` | dollar | _reserved_ | diff --git a/src/token.rs b/src/token.rs index 40555217..181524cc 100644 --- a/src/token.rs +++ b/src/token.rs @@ -1205,6 +1205,10 @@ fn get_next_token_inner( eat_next(stream, pos); return Some((Token::PlusAssign, start_pos)); } + ('+', '+') => { + eat_next(stream, pos); + return Some((Token::Reserved("++".into()), start_pos)); + } ('+', _) if !state.non_unary => return Some((Token::UnaryPlus, start_pos)), ('+', _) => return Some((Token::Plus, start_pos)), @@ -1218,6 +1222,10 @@ fn get_next_token_inner( eat_next(stream, pos); return Some((Token::Reserved("->".into()), start_pos)); } + ('-', '-') => { + eat_next(stream, pos); + return Some((Token::Reserved("--".into()), start_pos)); + } ('-', _) if !state.non_unary => return Some((Token::UnaryMinus, start_pos)), ('-', _) => return Some((Token::Minus, start_pos)), @@ -1282,12 +1290,22 @@ fn get_next_token_inner( (';', _) => return Some((Token::SemiColon, start_pos)), (',', _) => return Some((Token::Comma, start_pos)), + + ('.', '.') => { + eat_next(stream, pos); + + if stream.peek_next() == Some('.') { + eat_next(stream, pos); + return Some((Token::Reserved("...".into()), start_pos)); + } else { + return Some((Token::Reserved("..".into()), start_pos)); + } + } ('.', _) => return Some((Token::Period, start_pos)), ('=', '=') => { eat_next(stream, pos); - // Warn against `===` if stream.peek_next() == Some('=') { eat_next(stream, pos); return Some((Token::Reserved("===".into()), start_pos));