Properly handle unary operators at beginning of statement.

This commit is contained in:
Stephen Chung 2021-11-03 09:11:20 +08:00
parent 7c6b444616
commit 231584824a
2 changed files with 30 additions and 28 deletions

View File

@ -8,6 +8,7 @@ Bug fixes
--------- ---------
* `0.0` now prints correctly (used to print `0e0`). * `0.0` now prints correctly (used to print `0e0`).
* Unary operators are now properly recognized as an expression statement.
Version 1.1.1 Version 1.1.1

View File

@ -805,55 +805,56 @@ impl Token {
match self { match self {
LexError(_) | LexError(_) |
LeftBrace | // {+expr} - is unary SemiColon | // ; - is unary
Comma | // ( ... , -expr ) - is unary
//Period |
LeftBrace | // { -expr } - is unary
// RightBrace | { expr } - expr not unary & is closing // RightBrace | { expr } - expr not unary & is closing
LeftParen | // ( -expr ) - is unary LeftParen | // ( -expr ) - is unary
// RightParen | (expr) - expr not unary & is closing // RightParen | // ( expr ) - expr not unary & is closing
LeftBracket | // [ -expr ] - is unary LeftBracket | // [ -expr ] - is unary
// RightBracket | [expr] - expr not unary & is closing // RightBracket | // [ expr ] - expr not unary & is closing
Plus | Plus |
PlusAssign |
UnaryPlus | UnaryPlus |
Minus | Minus |
MinusAssign |
UnaryMinus | UnaryMinus |
Multiply | Multiply |
MultiplyAssign |
Divide | Divide |
Comma | DivideAssign |
Period | Modulo |
ModuloAssign |
PowerOf |
PowerOfAssign |
LeftShift |
LeftShiftAssign |
RightShift |
RightShiftAssign |
Equals | Equals |
EqualsTo |
NotEqualsTo |
LessThan | LessThan |
GreaterThan | GreaterThan |
Bang | Bang |
LessThanEqualsTo | LessThanEqualsTo |
GreaterThanEqualsTo | GreaterThanEqualsTo |
EqualsTo |
NotEqualsTo |
Pipe | Pipe |
Or |
Ampersand | Ampersand |
And |
If | If |
Do | //Do |
While | While |
Until | Until |
PlusAssign | In |
MinusAssign | And |
MultiplyAssign |
DivideAssign |
LeftShiftAssign |
RightShiftAssign |
PowerOf |
PowerOfAssign |
AndAssign | AndAssign |
Or |
OrAssign | OrAssign |
XOrAssign |
LeftShift |
RightShift |
XOr | XOr |
Modulo | XOrAssign |
ModuloAssign |
Return | Return |
Throw | Throw => true,
In => true,
_ => false, _ => false,
} }