modified src/reader.nim +7 -0
| @@ -93,6 +93,13 @@ proc parseAtom(r: Reader, tok: string): Value = |
| 93 | 93 | if tok == "true": return TrueV |
| 94 | 94 | if tok == "false": return FalseV |
| 95 | 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 | 103 | # number? |
| 97 | 104 | let body = (if tok[0] in {'-', '+'} and tok.len > 1: tok[1 .. ^1] else: tok) |
| 98 | 105 | 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 TrueV | 93 | if tok == "true": return TrueV |
| 94 | if tok == "false": return FalseV | 94 | 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: |