Is it possible to reuse boost::spirit:qi
grammar in another grammar (as a rule for example)?
For example if I define a grammar to parse line of text into a structure holding street address.
template< typename iter >
struct address_grammar : qi::grammar< iter, address() >
{
...
qi::rule< iter, std::string() > street_name;
qi::rule< iter, std::string() > street_number;
qi::rule< iter, address() > address_;
}
I might want to reuse that grammar in two other grammars, for example one might be for parsing of a vector of addresses stored in a file. Another re-use might be in more complex structure where one of the fields is this street address structure.
template< typename iter >
struct company_grammar : qi::grammar< iter, company() >
{
...
qi::rule< iter, std::string() > comp_name;
// can I reuse the address grammar somehow here ???
qi::rule< iter, company() > company;
}
Instead of defining the whole grammar in one place I'm thinking to split it into smaller reusable blocks, it is fine if they are inside one header file. My data structures are slightly more complex (couple of fields inside struct with a list of other structures and so on) so I don't want to put it into one grammar.
Is it possible to reuse boost::spirit::qi
grammar in this way?
EDIT: Thinking about it, do I just define qi::rule
s in a namespace and then put together a grammar from the rules that I need?