nandi/clonimpublic Fork
⑂ c735c3d
Commits
⬇ Clone ▾
git clone https://git.rickub.com/nandi/clonim.git
git clone ssh://git@rickub.com/nandi/clonim.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

feat: read hexadecimal integer literals

nandithebull committed 2026-09-21T00:45:49-07:00 Browse files
c735c3d parent: cfb27b8
modified src/reader.nim +7 -0
@@ -93,6 +93,13 @@ proc parseAtom(r: Reader, tok: string): Value =
9393 if tok == "true": return TrueV
9494 if tok == "false": return FalseV
9595 if tok.len > 1 and tok[0] == ':': return mkKeyword(tok[1 .. ^1])
96+ # Clojure accepts hexadecimal integer literals, commonly used for bit masks
97+ # and crypto constants.
98+ let sign = (if tok.len > 0 and tok[0] == '-': -1'i64 else: 1'i64)
99+ let digits = (if tok.len > 0 and tok[0] in {'-', '+'}: tok[1 .. ^1] else: tok)
100+ if digits.len > 2 and digits[0 .. 1].toLowerAscii == "0x":
101+ try: return mkInt(sign * int64(parseHexInt(digits[2 .. ^1])))
102+ except ValueError: discard
96103 # number?
97104 let body = (if tok[0] in {'-', '+'} and tok.len > 1: tok[1 .. ^1] else: tok)
98105 if body.len > 0 and body[0] in Digits:
@@ -93,6 +93,13 @@ proc parseAtom(r: Reader, tok: string): Value =
93 if tok == "true": return TrueV93 if tok == "true": return TrueV
94 if tok == "false": return FalseV94 if tok == "false": return FalseV
95 if tok.len > 1 and tok[0] == ':': return mkKeyword(tok[1 .. ^1])95 if tok.len > 1 and tok[0] == ':': return mkKeyword(tok[1 .. ^1])
96+ # Clojure accepts hexadecimal integer literals, commonly used for bit masks
97+ # and crypto constants.
98+ let sign = (if tok.len > 0 and tok[0] == '-': -1'i64 else: 1'i64)
99+ let digits = (if tok.len > 0 and tok[0] in {'-', '+'}: tok[1 .. ^1] else: tok)
100+ if digits.len > 2 and digits[0 .. 1].toLowerAscii == "0x":
101+ try: return mkInt(sign * int64(parseHexInt(digits[2 .. ^1])))
102+ except ValueError: discard
96 # number?103 # number?
97 let body = (if tok[0] in {'-', '+'} and tok.len > 1: tok[1 .. ^1] else: tok)104 let body = (if tok[0] in {'-', '+'} and tok.len > 1: tok[1 .. ^1] else: tok)
98 if body.len > 0 and body[0] in Digits:105 if body.len > 0 and body[0] in Digits: