Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-03-20 14:03:10

I have been learning Boost.Spirit over the past few days and here are a few

[1] Is it possible to process a token stream rather than a character stream?
If so, are there any examples? The reason I am asking is...

[2] Is it possible to cascade spirit grammars, e.g.

   wave.parse() >> cpp.parse(); // hypothetical

where the output of the wave grammar feeds the token stream of the cpp
grammar. I am not propsing that the above is how this would be expressed.

[3] Is it possible to combine the file_iterator with the position_iterator
to provide error reporting on that?

[4] I am now making use of boost::spirit::sub_grammar from
libs/spirit/doc/techniques.html. One thing I get from this is that the
typedef for the grammar type can be very difficult to read, especially for
non-trivial grammars! I have started writing a set of type helpers to
simplify the process:

   namespace boost { namespace spirit
      template< typename T1, typename T2, typename T3 >
      struct alternative3_t
         typedef alternative< alternative< T1, T2 >, T3 > type;

      template< typename T1, typename T2, typename T3 >
      struct sequence3_t
         typedef sequence< sequence< T1, T2 >, T3 > type;

      // confix_type = T1 >> *( CompositeT - T2 ) >> T2

      template< typename CompositeT, typename T1 = strlit< const char * >,
typename T2 = T1 >
      struct confix_t
         typedef typename sequence3_t
            kleene_star< difference< CompositeT, T2 > >,
>::type type;

      template< typename T2 = strlit< const char * >, typename T1 = strlit<
const char * > >
      struct comment_t
         typedef typename confix_t< anychar_parser, T1, T2 >::type type;

      typedef comment_t< chlit< char > >::type line_comment;
      typedef comment_t<>::type range_comment;

using these, the typedef for the skip_grammar example becomes:

   typedef typename boost::spirit::alternative3_t
>::type start_t;

If there is interest, I shall create a proper submission for them.


Stay in touch with absent friends - get MSN Messenger

Boost list run by bdawes at, gregod at, cpdaniel at, john at