That's a great concise implementation! I'm glad you also went with the parse-and-interpret-an-AST approach: it seems like the right design. Your `Reconstruct` type is a great idea! I might copy that.
penguin359 1 days ago [-]
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 surprises.
asicsp 1 days ago [-]
If you need to detect syntax issues, you can use `re.compile()`. For example, before Python 3.11, you'll get an error:
>>> re.compile(r'\w++')
re.error: multiple repeat at position 3
To use such a compiled pattern, you can call the method on this object instead of `re`. For example:
>>> word = re.compile(r'\w+')
>>> word.findall('hello-there!')
['hello', 'there']
hombre_fatal 20 hours ago [-]
The existent of re.compile is compatible with and doesn’t address their complaint.
ygra 1 days ago [-]
C# has compile-time regex, which are turned into fairly reasonable code doing the matching you can even inspect. The main goal isn't to have the syntax verified during compilation (technically it happens even during editing the code), but rather to reduce either dependencies on complex code at runtime, while still maintaining good performance by using the complex regex.
nsonha 1 days ago [-]
This article isn't about compile-time regex (which is in many languages, including javascript) though? It's compile-time regex MATCHING.
drowsspa 19 hours ago [-]
If you compile them outside the functions they will throw when imported
JonChesterfield 23 hours ago [-]
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.
jonstewart 18 hours ago [-]
Hana Dusikova did this in C++ several years ago, with her CTRE library.
Of course, it has all the usual tradeoffs of compile-time template programming.
gpderetta 14 hours ago [-]
Also relevant Boost.Expressive, by Eric Niebler, from 2007.
clarkdale 20 hours ago [-]
Derivatives approach is great and works if you're matching on some pattern like \w+, but could it work with "or" characters like (abc|def) or patterns like [a-z]+\d+
https://github.com/hanickadot/compile-time-regular-expressio...
Of course, it has all the usual tradeoffs of compile-time template programming.