feat: add hex literal parsing with readHexDigit and readHexNumber in wren_compiler.c

Implement hexadecimal number literal support in the Wren compiler by adding a `number` field to the Parser struct, a `readHexDigit` helper that returns -1 for invalid hex chars, and a `readHexNumber` function that skips the 'x' prefix, accumulates hex digits, converts via strtol, and emits a TOKEN_NUMBER. Update `readNumber` to remove the TODO placeholder for hex support. Include test cases for valid hex literals (0xFF, 0x09, negative -0xFF) and an invalid hex literal (2xFF) that triggers a lex error.
This commit is contained in:
Bob Nystrom
2015-01-26 01:49:05 +00:00
3 changed files with 67 additions and 30 deletions
+8
View File
@@ -0,0 +1,8 @@
var x = 0xFF
IO.print(x) // expect: 255
IO.print(x + 1) // expect: 256
IO.print(x == 255) // expect: true
IO.print(0x09 is Num) // expect: true
IO.print(x is Num) // expect: true
IO.print(-0xFF) // expect: -255
+1
View File
@@ -0,0 +1 @@
var x = 2xFF // expect error: Error at 'xFF': Expect end of file.