Boost logo

Boost :

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

Hartmut Kaiser wrote:
>Reece Dunn wrote:

> > [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:
> > If there is interest, I shall create a proper submission for them.
>Nice idea. Do you want to submit a patch for the
>libs/spirit/doc/techniques.html file?

I am not sure about a patch to the techniques.html file, maybe you or Joel
want to add a comment. The idea was to have the type constructors as a
helper file to be used in conjunction with sub_grammar, or when building any
non-rule<> (explicitly typed) rule.

It contains some of the more common combinations, and can be used (using the
skip_parser example) like:

   typedef boost::spirit::alternative_t
>::type start_t;

Including the entire set into the HTML file would be too distracting. A link
would probably be best with a few of the classes as an example.

NOTE: I have made a revision to alternative3_t so it is now a 2-4 -ary
construct (it is easy to extend this to support more if there is a need)
using mpl :). I have also added some more constructs that might be useful.

Here is a more complex example using my helpers:

      struct number_parser: public boost::spirit::sub_grammar< number_parser
            typedef boost::spirit::contiguous_sequence_t
boost::spirit::chset_nocase_t<>::type >
>::type start_t;
            start_t start;
            inline number_parser():
                        boost::spirit::as_lower_d[ "0x" ] >>
                     | '0' >> boost::spirit::oct_p
                     | boost::spirit::real_p
>> *boost::spirit::as_lower_d[ boost::spirit::chset_p(
"ldfu" )]
      } number;


It's fast, it's easy and it's free. Get MSN Messenger today!

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