From 231584824a01f2d57a19ae3fa911fa60ce697241 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 3 Nov 2021 09:11:20 +0800 Subject: [PATCH] Properly handle unary operators at beginning of statement. --- CHANGELOG.md | 1 + src/token.rs | 57 ++++++++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad096ea5..6aa4c0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Bug fixes --------- * `0.0` now prints correctly (used to print `0e0`). +* Unary operators are now properly recognized as an expression statement. Version 1.1.1 diff --git a/src/token.rs b/src/token.rs index 1ffef163..b473babe 100644 --- a/src/token.rs +++ b/src/token.rs @@ -805,55 +805,56 @@ impl Token { match self { LexError(_) | - LeftBrace | // {+expr} - is unary - // RightBrace | {expr} - expr not unary & is closing - LeftParen | // (-expr) - is unary - // RightParen | (expr) - expr not unary & is closing - LeftBracket | // [-expr] - is unary - // RightBracket | [expr] - expr not unary & is closing + SemiColon | // ; - is unary + Comma | // ( ... , -expr ) - is unary + //Period | + LeftBrace | // { -expr } - is unary + // RightBrace | { expr } - expr not unary & is closing + LeftParen | // ( -expr ) - is unary + // RightParen | // ( expr ) - expr not unary & is closing + LeftBracket | // [ -expr ] - is unary + // RightBracket | // [ expr ] - expr not unary & is closing Plus | + PlusAssign | UnaryPlus | Minus | + MinusAssign | UnaryMinus | Multiply | + MultiplyAssign | Divide | - Comma | - Period | + DivideAssign | + Modulo | + ModuloAssign | + PowerOf | + PowerOfAssign | + LeftShift | + LeftShiftAssign | + RightShift | + RightShiftAssign | Equals | + EqualsTo | + NotEqualsTo | LessThan | GreaterThan | Bang | LessThanEqualsTo | GreaterThanEqualsTo | - EqualsTo | - NotEqualsTo | Pipe | - Or | Ampersand | - And | If | - Do | + //Do | While | Until | - PlusAssign | - MinusAssign | - MultiplyAssign | - DivideAssign | - LeftShiftAssign | - RightShiftAssign | - PowerOf | - PowerOfAssign | + In | + And | AndAssign | + Or | OrAssign | - XOrAssign | - LeftShift | - RightShift | XOr | - Modulo | - ModuloAssign | + XOrAssign | Return | - Throw | - In => true, + Throw => true, _ => false, }