Skip to content

Commit 73b6709

Browse files
committed
fix
1 parent f9e1408 commit 73b6709

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Init/Meta/Defs.lean

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,10 +1210,16 @@ def getHexNumVal (s : Syntax.HexNum) : Nat :=
12101210
isHexNum? s.raw |>.getD 0
12111211

12121212
/-- Returns the number of hexadecimal digits. -/
1213-
def getHexNumSize (s : Syntax.HexNum) : Nat :=
1213+
partial def getHexNumSize (s : Syntax.HexNum) : Nat :=
12141214
match Syntax.isLit? hexnumKind s.raw with
1215-
| some val => val.utf8ByteSize
1215+
| some val => go val 0 0
12161216
| _ => 0
1217+
where
1218+
go (s : String) (p : String.Pos.Raw) (n : Nat) : Nat :=
1219+
if String.Internal.atEnd s p then
1220+
n
1221+
else
1222+
go s (String.Internal.next s p) (if String.Internal.get s p = '_' then n else n + 1)
12171223

12181224
/--
12191225
Extracts the parsed name from the syntax of an identifier.

tests/lean/run/hexnum.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ macro_rules
2222
/-- info: (3, 10) : Nat × Nat -/
2323
#guard_msgs in
2424
#check #00a
25+
26+
/-- info: (8, 65536) : Nat × Nat -/
27+
#guard_msgs in
28+
#check #0001_0000

0 commit comments

Comments
 (0)