Live data from Hacker News

Implementing Regular Expressions in TypeScript Types (Badly)

skalt.github.io

11–13 of 13 posts

Re: Implementing Regular Expressions in TypeScript Types (Badly)

#11

Having compile-time RegEx's would certainly fix some issues I've had with them in Python. As they are just buried in plain strings, there's no validation of their syntax until you hit the line of code that tried to use them only to discover that Python 3.12 has changed the syntax and what was once working is now broken. I'd love to see this validated at compile-time/load-time of any language to avoid those unexpected…

If you compile them outside the functions they will throw when imported

Re: Implementing Regular Expressions in TypeScript Types (Badly)

#12

It's regular expressions via derivatives which is sanely representable in functional programming fashion. Matching a single string doesn't need the caching layers for termination, you could do this in C++ templates if you have the patience. Nice to see it in typescript syntax.

Hana Dusikova did this in C++ several years ago, with her CTRE library.

https://github.com/hanickadot/compile-time-regular-expressio...

Of course, it has all the usual tradeoffs of compile-time template programming.

Re: Implementing Regular Expressions in TypeScript Types (Badly)

#13

It's regular expressions via derivatives which is sanely representable in functional programming fashion. Matching a single string doesn't need the caching layers for termination, you could do this in C++ templates if you have the patience. Nice to see it in typescript syntax.

Hana Dusikova did this in C++ several years ago, with her CTRE library. https://github.com/hanickadot/compile-time-regular-expressio... Of course, it has all the usual tradeoffs of compile-time template programming.

Also relevant Boost.Expressive, by Eric Niebler, from 2007.
Post reply on HN