Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Init/Meta/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions tests/lean/run/hexnum.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading