0

As recommended here: How to benchmark Boost Spirit Parser? I want to make my grammar stateless, static and const. Therefore I have to store the current column, row and result somewhere and I thought locals would be the right place. Unfortunately, I cannot access locals of the parent rule in a sub rule to modify them:

  qi::rule<Iterator, qi::locals<Slk::Table::size_type, Slk::Table::size_type, Slk::Table> > cells;
cells =
            eps[ref(_b) = 1][ref(_a) = 1]

now I want to change the locals in a sub rule:

f_record =
            lit('F')
            >> +(
                skipped_field
                | y_field[ref(_a) = _1]
                | x_field[ref(_b) = _1]
            )
        ;

but how can I access the locals from the parent rule? Do I have to store them in the attribute?! What's the best way to make the grammar stateless? Where do I store variables of the current state which might be modified by ANY sub rule anywhere in the grammar at any time?

Community
  • 1
  • 1
Baradé
  • 1,290
  • 1
  • 15
  • 35
  • 2
    You can pass references to attributes/locals down to subrules using _inherited attributes_. – K-ballo Sep 14 '14 at 23:06
  • What are you trying to achieve? And no, your prose above does not make that clear. Consider showing a simple minimalist example instead. – sehe Sep 15 '14 at 07:42
  • thx passing references using inherited attributes was exactly what I was looking for. I am trying to achieve to pass locals of a rule to a sub rule. f_record is a sub sub rule of cells. Replacing ref(_a) in f_record by ref(_r1) and adding a inherited attribute of the type Slk::Table::size_type was what I was looking for. – Baradé Sep 15 '14 at 11:41

0 Answers0