Boost logo

Boost :

Subject: Re: [boost] compile time parser generator
From: Ábel Sinkovics (abel_at_[hidden])
Date: 2012-01-09 15:11:46


Hi Luke,

> Syntax example:
>
> printf<_S("John %d, %s %d\n")>(11, "Joe", 13);
>
> Yay! That syntax doesn't suck. The _S would be BOOST_S if it were a boost library, I guess, or perhaps BOOST_MPL_STRING if we want to be very descriptive. Too bad we need the macro. It would be nice to jet get a variadic template instantiation from the language if we wrote printf<"John %d, %s, %d\n"> directly. It is pretty obvious that we can take this idea and run with it to do something really evil like:
>
> ruby<_S("_1.each {|item| puts item }")>(my_array);
>
> or
>
> perl<_S("foreach $item (@_1){ print "$item\n"; }")>(my_array);
>
> Man is that evil. Right up there with overloading the comma operator evilness. Ok, now, hands please, who wants to implement a Ruby interpreter as a template metaprogram?
If you look at
https://github.com/sabel83/mpllibs/blob/master/mpllibs/metaparse/string.hpp
I call this macro MPLLIBS_METAPARSE_STRING (given that the library is
called that at the moment - we can change it to BOOST_* when it goes
in). _S is just an "alias" of it to simplify its usage. The shorter the
name, the less disturbing it is.

If not for Perl, but for small EDSLs it may worth writing a parser (with
some TMP tricks these compile-time strings could be compiled into C++
functions - no example for it yet). Given the error reporting
capabilities of the parsers built using the library (demonstrated in
https://github.com/sabel83/mpllibs/tree/master/libs/metaparse/example/parsing_error)
it may be useful/helpful.

Regards,
   Ãbel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk