Skip to content

Commit

Permalink
[Lexer] Store raw 0b supermagically
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed Jan 12, 2025
1 parent 73fe7d5 commit cf70e85
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/compiler/lexer.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion source/compiler/parser.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -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`')
Expand Down
6 changes: 3 additions & 3 deletions source/data/token.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf70e85

Please sign in to comment.