
Reece Dunn wrote:
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...
Yes, this is possible. The only thing you'll have to respect is, that your token type should be implicitly convertible to an integer type, which isn't an limitation though, because a token always has a token id, which may returned by the corresponding operator. This technique is used by Wave, which uses a lexer component for token building and the preprocessor (and the related grammars) take the generated token stream as its input.
[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.
Yes, this is possible. Wave exposes an interator interface, where the corresponding dereferencing operator returns the preprocessed tokens. You may use this token stream for any subsequent parsing (simply pass the pair of Wave iterators to your parse() function).
[3] Is it possible to combine the file_iterator with the position_iterator to provide error reporting on that?
Yes. The position iterator is simply a wrapper, which takes any other input iterator, from where it gets its 'input'.
[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? Regards Hartmut