I have a simple configuration parser built from spirit :: lex and spirit :: qi. When the lexer reaches the include "path"
template, I want the text of the file to be included. As you know, the spirit :: lexer :: begin () starts the scanning process:
My idea is to have a stack that stores the lexer state, represented as a struct:
struct LexerState { const char* first; const char* last; std::string contents; };
The lexer will be created to recognize the template for include "path"
and in a semantic action will extract the path to the included file. Then the current lexer state is pushed onto the stack, the contents of the file are loaded into the string, and the new state is initialized, as indicated above, using lexer :: begin ().
When the lexer finds the EOF character, the stack is popped, and the lexer :: begin () method is called using the previous lexer state variables.
Is it possible to repeatedly call lexer :: begin () like this? How to get lex :: lexer to recognize the include "path"
pattern and the EOF character without returning the marker in the qi parser?
Finally, are there any alternative or better ways to do this?
source share