0

The rule to parse something like "a.b.c" and "a().b"

postfix = 
     primary  [_val=_1] >> *(
                (lit('(') > paralistopt  > lit(')'))  [_val = construct<common_node>(type_cmd_fnc_call,key_this, construct<common_node>(_val), key_parameter, construct<std::vector<common_node> >(_1))]
              | (lit('.') > name_pure)                [_val = construct<common_node>(type_cmd_dot_call,key_this, construct<common_node>(_val), key_propname, construct<std::wstring>(_1))]
       )
    ;        

The annotation code for the rule (common_node is the AST entry)

void annotateNode(parserDataS & data,const std::wstring::const_iterator & pos1, const std::wstring::const_iterator & pos2, common_node & node)
 {
   // calc pos
   int p1=std::distance(data.init_pos, pos1);
   int p2=std::distance(data.init_pos, pos2);
   // range is from  >=p1 <=p2
   node.makeLocation(std::make_pair(p1, p2-1));
 }

handler Setup

  on_success(postfix, phoenix::bind(&annotateNode, phoenix::ref(parserData),_1, _3,_val))

So far no problem, using "a.b" the annotation is called on the node. But when using a.b.c.d the "on_success" is only called on the first node "a" for each member (b,c,d) How to code the "on_succcess" for each member .. "a.b" "(a.b).c" "(a.b.c).d" separate ?

Markus
  • 373
  • 1
  • 11

1 Answers1

1

You'd do better to just amend the semantic action to do the extra work, as you clearly intend. Otherwise, split out subrules (looks like you already have) and make the on_success handler run for those too.

If you need more help, I suggest posting a self-contained example. If you have trouble making one, perhaps you can build off the one I wrote in boost::spirit access position iterator from semantic actions

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Oh PS, if you're "just" looking for source location annotating tokens like `name_pure` you can have it automatic [with e.g. `string_ref`/`string_view`](https://stackoverflow.com/a/47334796/85371) or a semantic-action approach like https://stackoverflow.com/questions/8358975/cross-platform-way-to-get-line-number-of-an-ini-file-where-given-option-was-foun/8365427#8365427 – sehe Jan 29 '18 at 16:52