
Do you think Wave could be used for adding some syntatic sugar that would allow easy compile time programming of strings? If I remember the main issue with such thoughts it was the clumsiness of the typelist of characters. A little non-standard sugar from Wave might solve that. Been thinking about a compile time packet parser and how something like a spirit-like but at compile time would fit the bill. Thoughts? Matt. matthurd@acm.org

Matt Hurd wrote:
Do you think Wave could be used for adding some syntatic sugar that would allow easy compile time programming of strings?
What concretely do you have in mind?
If I remember the main issue with such thoughts it was the clumsiness of the typelist of characters. A little non-standard sugar from Wave might solve that.
Been thinking about a compile time packet parser and how something like a spirit-like but at compile time would fit the bill.
Generally Wave provides you with the tokenised and preprocessed C++ input stream. This may be used to drive some kind of parser (a spirit parser will do). But Wave doesn't do any C++ related semantic analysis of the input stream. For instance you'll get the information that there was an identifier found in the input stream at a certain point, but you won't get any information about whether this is a variable, a class name, a typedef'd name, or perhaps a function name etc. I'm not quite sure if it is sufficient to have Wave around to solve the problem you've mentioned. Probably you'll need some kind of C++ semantic analysis for that (i.e. a parser for C++ or a significant subset). HTH Regards Hartmut

On Apr 8, 2005 9:49 PM, Hartmut Kaiser <HartmutKaiser@t-online.de> wrote:
Matt Hurd wrote:
Do you think Wave could be used for adding some syntatic sugar that would allow easy compile time programming of strings?
What concretely do you have in mind?
I've been toying with some thoughts of writing some compile time parsing functionality. To do this I need compile time strings which aren't in the standard. I think the closest thing is probably using a mpl::vector_c< char... The definitions of such are a bit unwieldy to say the least. E.g. typedef mpl::vector_c< char, 'h', 'e', 'l', 'l', 'o' > cts_hello; typedef mpl::vector_c< char, 'w', 'o', 'r', 'l', 'd' > cts_world; I could localise such things in a resource file and have a little program transform it into an appropriate hpp or perhaps use a little preprocessor extension to do the same if it was straightforward. For example, a quick hack of a compile time string doo-dad: #include <iostream> #include <string> #include <boost/mpl/vector_c.hpp> #include <boost/mpl/size.hpp> #include <boost/mpl/front.hpp> #include <boost/mpl/copy.hpp> #include <boost/mpl/back_inserter.hpp> #include <boost/mpl/pop_front.hpp> namespace mpl = boost::mpl; typedef mpl::vector_c< char, 'h', 'e', 'l', 'l', 'o' > cts_hello; typedef mpl::vector_c< char, ' ', 'w', 'o', 'r', 'l', 'd' > cts_world; template < class CTS > struct cts_to_rts { char value[ mpl::size< CTS >::value ] ; cts_to_rts() { write_string< mpl::size< CTS >::value, CTS >::apply( value ); } std::string string_copy() { return std::string( value, mpl::size< CTS >::value ); } private: template< int N, class CTS > struct write_string { static void apply( char * p ) { *p = mpl::front< CTS >::type::value; write_string<N-1, typename mpl::pop_front< CTS >::type
::apply( ++p ); } };
template< class CTS > struct write_string< 0, typename CTS > { static void apply( char * p ) { } }; }; typedef mpl::copy < cts_world , mpl::back_inserter< cts_hello >
::type cts_hello_world;
int main() { cts_to_rts< cts_hello_world > rts_hello_world; std::cout << rts_hello_world.string_copy() << "\n"; system("pause"); return 0; }
I'm not quite sure if it is sufficient to have Wave around to solve the problem you've mentioned. Probably you'll need some kind of C++ semantic analysis for that (i.e. a parser for C++ or a significant subset).
was thinking perhaps a __cts"hello" could be translated to typedef mpl::vector_c< char, 'h', 'e', 'l', 'l', 'o' > cts_hello by wave or something more appropriate. Simple enough to do my own preprocessor pass for this as it is a fairly straight forward manipulation. Just wondering out loud as I can imagine all sorts of nice regex, parsing and state machine things I'd like to be able to do at compile time. Any better thoughts on pseudo string manipulation at compile time? matt. matthurd@acm.org
participants (2)
-
Hartmut Kaiser
-
Matt Hurd