fix: stop lexing negative numbers as single tokens to fix parsing of subtraction
Previously, the lexer greedily consumed a `-` followed by a digit as a single negative number token, causing "1 -1" to be lexed as two number tokens instead of a minus operator and a positive literal. This broke parsing of subtraction expressions without spaces. Now `-` always emits a TOKEN_MINUS, and the parser handles unary negation. This is a breaking change: `-16.sqrt` is now parsed as `-(16.sqrt)` instead of `(-16).sqrt`, requiring parentheses for negative method receivers. All number method tests (abs, ceil, floor, sqrt, toString) are updated to use explicit parentheses for negative receivers.
This commit is contained in:
@@ -25,6 +25,12 @@ IO.print(false == 1 >= 2) // expect: true
|
||||
// Unary - has lower precedence than ..
|
||||
IO.print(-"abc".count) // expect: -3
|
||||
|
||||
// 1 - 1 is not space-sensitive.
|
||||
IO.print(1 - 1) // expect: 0
|
||||
IO.print(1 -1) // expect: 0
|
||||
IO.print(1- 1) // expect: 0
|
||||
IO.print(1-1) // expect: 0
|
||||
|
||||
// TODO: %, associativity.
|
||||
|
||||
// Using () for grouping.
|
||||
|
||||
Reference in New Issue
Block a user