Live data from Hacker News

Compile time regular expression in C++

github.com

11–20 of 30 posts

Re: Compile time regular expression in C++

#16

This has been available in Lisp since at least 2004. https://github.com/edicl/cl-ppcre/

C++ has had run-time regular expressions in its standard library since C++11, but this is about compile-time regular expressions

I've never used cl-ppcre myself, but its docs[1] claim that it provides compile-time regexes:

> CL-PPCRE uses compiler macros to pre-compile scanners at load time if possible. This happens if the compiler can determine that the regular expression (no matter if it's a string or an S-expression) is constant at compile time and is intended to save the time for creating scanners at execution time (probably creating the same scanner over and over in a loop).

[1]: https://edicl.github.io/cl-ppcre/

Re: Compile time regular expression in C++

#17
Since people is posting other lang implementations... someone did it for zig too (probably less polished than this C++ lib) [0]. It is nice that the regexes can be used at compile time too [1].

--

0: https://github.com/alexnask/ctregex.zig

1: I think the difference between C++ template language and Zig comptime is that Zig's comptime is almost equal as Zig's regular language, whereas the experience of programming C++ templates almost feels like learning a separate, equally complex language.

Re: Compile time regular expression in C++

#18

I'd love for someone to add this to rebar[1] so that we can get a good sense of how well it does against other general purpose regex engines. It will be a little tricky to add (since the build step will require emitting a C++ program and compiling it), but it should be possible. [1]: https://github.com/BurntSushi/rebar

The C++ standard library "general regex engine" is crap (at speed), so there's no competition on that front at least...

Re: Compile time regular expression in C++

#19

Earlier quoted context omitted.

C++ has had run-time regular expressions in its standard library since C++11, but this is about compile-time regular expressions

I've never used cl-ppcre myself, but its docs[1] claim that it provides compile-time regexes: > CL-PPCRE uses compiler macros to pre-compile scanners at load time if possible. This happens if the compiler can determine that the regular expression (no matter if it's a string or an S-expression) is constant at compile time and is intended to save the time for creating scanners at execution time (probably creating the s…

I think this is more like caching the regex than creating it at compile time? Load time I think is basically runtime. I think lisp can be loaded and then rehydrated later, but I'm not sure how common that is.
Post reply on HN