In an application, I basically want to have a "pre-parsing" phase where I adjust the token stream before a Qi parser can see it.
One way to do this would be to have some kind of "lexer adaptor" which is constructed from a lexer and is itself a lexer, which wraps and modifies the behavior of the inner lexer. However it would be simpler and easier to debug if instead I just lex the entire input stream with the inner lexer first and store the results in a std::vector<token_type>, then modify as desired, then pass the result to the parser.
In an email exchange from a few years back, someone described exactly this question and Hartmut said that it should be trivial. http://ift.tt/1JGcV3D
However I didn't find any code examples or instructions how to do this beyond, look at the headers in spirit::lex and figure it out. That will likely occupy me for quite a while now unless you, dear reader, can assist.
The specific question is, how can I make a "shim" lexer which wraps over a pair of std::vector<token_type>::iterator's and looks to spirit::qi just like a standard spirit::lex lexer.
Aucun commentaire:
Enregistrer un commentaire