nitely / nim-regex

Pure Nim regex engine. Guarantees linear time matching
https://nitely.github.io/nim-regex/
MIT License
225 stars 20 forks source link

solve https://github.com/nitely/nim-regex/issues/123 #127

Closed Ethosa closed 10 months ago

Ethosa commented 11 months ago

So, I just remove distinct keyword. Also I created procedures toRegex(Regex2) and toRegex2(Regex) for convert.

nitely commented 11 months ago

this makes copies, though

Ethosa commented 11 months ago

this makes copies, though

Maybe Nim allows to destruct object? 🤔

Ethosa commented 11 months ago

cast[Regex](regex2) is also forbidden by Nim VM image

Ethosa commented 10 months ago

@nitely please see changes

Ethosa commented 10 months ago

@nitely please check again

nitely commented 10 months ago

I think the point of using converters is you don't need to call them. There is an implicit call, like here. If you are calling them, then just use a template.

FYI, one way to avoid copies when there are two compatible types like this, is to define something like type RegexT = Regex | Regex2 and use it internally, so you can pass any of those two types. But I see you are only copying on JS, which I don't mind because JS is slow anyway, and if someone cares about performance in JS they should use the native JS regex.

Also, this is really a Nim regression, and it would be better if the compiler gets fixed/backported. But if tests pass, I'll merge it.