|
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
queries:
[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
<
T1,
kleene_star< difference< CompositeT, T2 > >,
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
<
boost::spirit::space_parser,
boost::spirit::line_comment,
boost::spirit::range_comment
>::type start_t;
If there is interest, I shall create a proper submission for them.
Regards,
Reece
_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger
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