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`).
* Unary operators are now properly recognized as an expression statement.
Version 1.1.1

View File

@ -805,55 +805,56 @@ impl Token {
match self {
LexError(_) |
LeftBrace | // {+expr} - is unary
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
// RightParen | // ( expr ) - expr not unary & is closing
LeftBracket | // [ -expr ] - is unary
// RightBracket | [expr] - expr not unary & is closing
// 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,
}