import sets
import re
discard toHashSet([re"a"])
.../nim-1.4.4/lib/pure/collections/hashcommon.nim(69, 12) Error: type mismatch: got <Regex> but expected one of: proc hash(sBuf: string; sPos, ePos: int): Hash first type mismatch at position: 1 ...
Looks like there is no proc hash(x: Regex) defined..Probably no == either. You need those and note that it may not be trivial if you want equivalent expressions to report as equal. Then you need to concoct a proc hash honoring that.
You might think "oh, I just want the string used to build the regex", but that is not saved in a Regex and so may be long gone. You may be able to just use the string spelling of the original expression (after the re), not the compiled Regex , but it's hard to say without more context.
The "interface" is really just in-scope proc hash and proc == overloads for the type in question. proc $ is also undefined:
import re
let x = re"hi"
# echo x # fails, no `$`
echo x.repr # a hint why above fails :)
Sounds like you have a solution, though. Good luck!If you want regexes to save the original string, you can do it:
type RegexWithOriginalString = (Regex, string)