i want to share a data within all semantic actions of the grammer rules.
the reason for this question is the runtime issue while construction the parser objects. This takes too long and i need them very frequently ..
Currently i use this schema to get access on shared variables inside the rules action (just as pseudo code below)
struct my_grammar : public qi::grammar<Iterator, common_node(), eol_skipper >
{
int myLocalVar;
int localFunction(parameter)
{
return myLocalVar;
}
myRule1 = (...)[_val = phoenix::bind(&localFunction,this,_1)]
myRule2 = (...)[_val = phoenix::bind(&localFunction,this,_1)]
}
my_grammar worker;
boost::spirit::qi::phrase_parse(first, last, worker, eolSkipper, ret);
so is there a common way to provide a struct/class to the parse call and than access this data within any rule and their corresponding sematic action expect using the full instance of the grammer object?
goal should be something like this
struct myLocalData
{
int myLocalVar;
int localFunction(parameter)
{
return myLocalVar;
}
} ;
struct my_grammar : public qi::grammar<Iterator, common_node(), eol_skipper >
{ // no more local variables here
myRule1 = (...)[_val = phoenix::bind(&localFunction,_ptr_to_instance_object, _1)]
myRule2 = (...)[_val = phoenix::bind(&localFunction,_ptr_to_instance_object, _1)]
}
myLocalData instance; // share this data in all rules
my_grammer worker;
boost::spirit::qi::phrase_parse(first, last, worker, eolSkipper, ret,instance);