I am trying to understand what "attaching" a semantic action to a parser exactly means, and more precisely I would like to understand when, and for what duration the semantic action is bound to the parser.
For this, I modified slightly the employee.cpp example of the boost spirit library in the following manner:
1°/ Added a print()
function whose output is only to trace when it is called:
void print(const struct employee & e) { std::cout << e.surname << "\n"}
2°/ At the end of the constructor of the class employee_parser
, I bound the print()
function to the start
parser:
employee_parser() : employee_parser::base_type(start)
{
using qi::int_;
using qi::lit;
using qi::double_;
using qi::lexeme;
using ascii::char_;
quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
start %=
lit("employee")
>> '{'
>> int_ >> ','
>> quoted_string >> ','
>> quoted_string >> ','
>> double_
>> '}'
;
start[&print];
}
Although it seams to me that I have attached the start
parser with the semantic action print
, as indicated in the documentation, the print()
function is never called. It seams the semantic action needs to be attached within the right end side of a parser definition, as many time as the parser appears in that same definition. Can anybody elaborate a little bit more on this ?