views:

62

answers:

1

Hello :)

I'd like to support something like C++'s #include mechanism in a boost spirit parser. Essentially, I have a script command that asks my parser to load a sub script from a file. I'd like to be able to report error messages as described in the tracking input position while parsing post, but they don't cover parsing for multiple inputs.

Can this be reasonably accomplished using boost::spirit::qi?

I've worked around getting the differing inputs in using a smarter iterator type. I'd still like to see accurate positioning though.

+1  A: 

IMHO, using a smart iterator is the way to go. What needs to be done is to have a stack of input contexts maintained by the iterator. Each input context stores the information related to a specific file.

Whenever a new file needs to be read (i.e. after seeing an #include statement) a new input context is created. The current input context gets pushed onto the stack, while the new context gets to be the active one. On EOF you pop the next input context from the stack, returning to the point right after the #include. If the stack is empty you reached the EOF of the main file.

In any case, the iterator only gets its input from the active input context.

hkaiser
That's what I'm currently doing. But if you do that, spirit does not know, and as a result there's no way to track the current location.
Billy ONeal
I thought you could store the current filename and position in the corresponding input context, making it available to Qi.
hkaiser
@hkaiser: I'd like to use Spirit's own position tracking goodies if at all possible.
Billy ONeal