Boost logo

Boost Users :

Subject: Re: [Boost-users] [xpressive] questions about semantic actions
From: Eric Niebler (eric_at_[hidden])
Date: 2012-08-05 03:12:02


On 8/4/2012 11:57 PM, Nathan Ridge wrote:
> Hello,
>
> I am trying to use semantic actions in Boost.Xpressive, and I have a
> couple of questions:
>
> 1. When a semantic action is attached to a subexpression of a regex, what
> is the meaning of _, s1, s2 etc. in the semantic action? For example,
> suppose you have the following regex:
> ((s1 = xpr1)[action]) >> (s2 = xpr2)
> Inside 'action':
> - is it valid to use '_'?
> - if so does it refer to just the portion matched by xpr1?
> - is it valid to use 's1'?
> - is it valid to use 's2'?

Yes, this is all described in the docs.

http://www.boost.org/doc/libs/1_50_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.semantic_actions_and_user_defined_assertions

> 2. Is there a way to access the regex_id of the regex to which a semantic
> action belongs from the semantic action? More generally, can a semantic
> action be written as a custom function object that takes as argument
> some sort of environment (perhaps a match_results<>)?

Please see the sections in the docs on refering to local and non-local
variables from within semantic actions. Non-local variables will do what
you want, I think.

http://www.boost.org/doc/libs/1_50_0/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.semantic_actions_and_user_defined_assertions.referring_to_non_local_variables

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net