Image

Imagexil wrote in Imagecpp

boost.spirit semantic actions.

I've recently started a project using boost.spirit. I've read through the manual quite a bit, scouraged through google to try to find the answer to my question with no luck. Here's the idea.

With Spirit, for certain built-in classes, the semantic action can take in the logical representation of the data (instead of the standard char iterators):


void outreal(const double &r)
{ cout << r << endl; }

rule<> r = real_p[&outreal];


Now, my project is quite modular, and a bunch of different classes are involved in the logical representation of the data for my input. I have no problem implementing the spirit code to read in the data, but the problem is that there doesn't seem to be a way to call a function like real_p did above. For example, let's say I'm making a rational grammar:


void outrational(const rational_class &r)
{ cout << r << endl; }
rational_grammar<> rat;
rule<> r = rat[&outrational];


is what I want to be able to do. I've done all of the spirit stuff for the grammar in definition::definition like we're supposed to, and that sorta thing. I also know I can implement operator[] of the rational_grammar class, but it never gives me a chance to take the rational data which I've interpreted in my rules, and pass it on to the parameters of operator[]. Where do I store the data as I interpret it? Where do I put the code to call the functor passed into operator[] (especially since this code is supposed to be valid: real_p[&func1][&func2][&func3])?

Thanks a lot, I appreciate the help.