From cf70e859f0d1d70815175c5e13c5ac47e34264c8 Mon Sep 17 00:00:00 2001 From: Miraculous Ladybugreport <3642643+PeyTy@users.noreply.github.com> Date: Mon, 13 Jan 2025 00:21:31 +0200 Subject: [PATCH] [Lexer] Store raw 0b supermagically --- source/compiler/lexer.hexa | 2 +- source/compiler/parser.hexa | 3 ++- source/data/token.hexa | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/compiler/lexer.hexa b/source/compiler/lexer.hexa index 5ee37f0..ebd8a76 100644 --- a/source/compiler/lexer.hexa +++ b/source/compiler/lexer.hexa @@ -457,7 +457,7 @@ class Lexer { } } - let string = parseInt(bytes.toString('ascii', position + 2, p), 2).toString() + let string = bytes.toString('ascii', position, p) addMeta(Token.Integer, string, m) position = p + offset diff --git a/source/compiler/parser.hexa b/source/compiler/parser.hexa index fbdf200..c673dd7 100644 --- a/source/compiler/parser.hexa +++ b/source/compiler/parser.hexa @@ -795,7 +795,8 @@ class Parser { // TODO rename `Default` token to `Empty` case Default: let at = i - let v = parseInt(value) + // TODO encode 0b flag into Meta + let v = value.startsWith('0b') ? parseInt(value.substr(2), 2) : parseInt(value) if v > 2147483647 || v < -2147483647 { i = at - 1 fail('Integer `\(value)` is too large for *signed* 32 bit, use `\(value)u32` or `\(value)n`') diff --git a/source/data/token.hexa b/source/data/token.hexa index a952905..4178fc4 100644 --- a/source/data/token.hexa +++ b/source/data/token.hexa @@ -217,11 +217,11 @@ enum Token : Int { return '"string"' } - if meta == Meta.SingleQuote { - return "'\(param)'" + if meta == Meta.DoubleQuote { + return '"\(param)"' } - return '"\(param)"' + return "'\(param)'" case Backtick: return (param == null)? '`backtick`' : '`\(param)`' case Identifier: return (param == null)? 'identifier' : param