Am I evil for this?

Walter Bright newshound2 at digitalmars.com
Fri Oct 14 06:59:43 UTC 2022


On 10/13/2022 7:44 PM, H. S. Teoh wrote:
>> and also a project he saw in the past that overloaded C++ operators to
>> make a regex DSL.
> [...]
> 
> That would be Boost.Xpressive, I think.

Here it is:

#include <boost/spirit.hpp>
using namespace boost;
int main() {
     spirit::rule<> group, fact, term, expr;
     group   = '(' >> expr >> ')';
     fact    = spirit::int_p   | group;
     term    = fact >> *(('*' >> fact) | ('/' >> fact));
     expr    = term >> *(('+' >> term) | ('-' >> term));
     assert( spirit::parse("2*(3+4)", expr).full );
     assert( ! spirit::parse("2*(3+4", expr).full );
}

https://studylib.net/doc/10029968/text-processing-with-boost---northwest-c---users--group

slide 40

It's a technical marvel, but the embedded DSL looks like C++ expressions yet 
does something completely different. One cannot distinguish the C++ code from 
the DSL code. It's in the same category as macros, and I can't recommend it.



More information about the Digitalmars-d mailing list