fix: consider underscores in getHexNumSize (#10719)

This PR fixes `getHexNumSize` to consider underscores. Previously, only
the amount of bytes was counted, making it output 9 for `1234_abcd`
instead of the actual number of digits, which is 8.
This commit is contained in:
Rob23oba 2025-10-16 15:57:58 +02:00 committed by GitHub
parent 10d6232594
commit b7ea66d8d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -1210,10 +1210,16 @@ def getHexNumVal (s : Syntax.HexNum) : Nat :=
isHexNum? s.raw |>.getD 0
/-- Returns the number of hexadecimal digits. -/
def getHexNumSize (s : Syntax.HexNum) : Nat :=
partial def getHexNumSize (s : Syntax.HexNum) : Nat :=
match Syntax.isLit? hexnumKind s.raw with
| some val => val.utf8ByteSize
| some val => go val 0 0
| _ => 0
where
go (s : String) (p : String.Pos.Raw) (n : Nat) : Nat :=
if String.Internal.atEnd s p then
n
else
go s (String.Internal.next s p) (if String.Internal.get s p = '_' then n else n + 1)
/--
Extracts the parsed name from the syntax of an identifier.

View file

@ -22,3 +22,7 @@ macro_rules
/-- info: (3, 10) : Nat × Nat -/
#guard_msgs in
#check #00a
/-- info: (8, 65536) : Nat × Nat -/
#guard_msgs in
#check #0001_0000