|
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:
>
>[snip]
>
> > 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
<
boost::spirit::space_parser,
boost::spirit::line_comment,
boost::spirit::range_comment
>::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
>
{
public:
typedef boost::spirit::contiguous_sequence_t
<
boost::spirit::alternative_t
<
boost::spirit::sequence
<
boost::spirit::strlit_nocase_t<>::type,
boost::spirit::hex_t
>,
boost::spirit::sequence
<
boost::spirit::chlit<>,
boost::spirit::oct_t
>,
boost::spirit::real_t<>::type
>::type,
boost::spirit::kleene_star<
boost::spirit::chset_nocase_t<>::type >
>::type start_t;
public:
start_t start;
public:
inline number_parser():
start
(
boost::spirit::lexeme_d
[
(
boost::spirit::as_lower_d[ "0x" ] >>
boost::spirit::hex_p
| '0' >> boost::spirit::oct_p
| boost::spirit::real_p
)
>> *boost::spirit::as_lower_d[ boost::spirit::chset_p(
"ldfu" )]
]
)
{
}
} number;
Regards,
Reece
_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk