Re: Auto attributes propagation in directives with lazy arguments

Lee Clagett <[email protected]> Fri, 13 Feb 2015 11:19:30 -0500
Newsgroups gmane.comp.parsers.spirit.devel
Message-ID <CALD9dK3xY3X3c=pHV1AOeqz6eD90FafvfHK+nMjhDOPu0+Q9vA@mail.gmail.com>
--===============5577914645860305888==
Content-Type: multipart/alternative; boundary=f46d043be1b0ebedb1050efa9909

--f46d043be1b0ebedb1050efa9909
Content-Type: text/plain; charset=UTF-8

On Fri, Feb 13, 2015 at 7:05 AM, Nikita Kniazev <[email protected]> wrote:

> I hit problem with attributes propagation when using semantic actions,
> even with using enforcing operator %=.
> Following test case shows inconsistent in behavior of directives with lazy
> parameters vs normal.
>
> /******************************************************************************/
>
> #include <boost/spirit/include/phoenix_core.hpp>
>
> #include <boost/spirit/include/qi.hpp>
>
>
> namespace qi = boost::spirit::qi;
>
>
> template <typename T>
>
> void test(const T& rule)
>
> {
>
>   const std::string in = "123";
>
>   std::vector<int> out;
>
>
>   std::string::const_iterator iter = in.begin();
>
>   const std::string::const_iterator end = in.end();
>
>
>   const bool r = qi::parse(iter, end, rule, out);
>
>
>   std::cout << out.size() << std::endl;
>
>
>   BOOST_ASSERT(r && iter == end);
>
> }
>
>
> int main()
>
> {
>
>     using qi::int_;
>
>     using qi::_1;
>
>     using boost::phoenix::val;
>
>                                          //       Lazy  Semantic
>
>     test(qi::repeat(1)[int_]);           // OK    No    No
>
>     test(qi::repeat(1)[int_[_1]]);       // OK    No    Yes
>
>     test(qi::repeat(val(1))[int_]);      // OK    Yes   No
>
>     test(qi::repeat(val(1))[int_[_1]]);  // FAIL  Yes   Yes
>
>
>     return 0;
>
> }
>
> /******************************************************************************/
>
>
> I'm not sure, but as for me this is a bug (which interfere me at using my
> own custom directive).
>

The expression int_[_1] creates an integer parser with an attached semantic
action that does nothing, so its not exactly clear to me what you are
trying to do. Did you mean to do a push_back(ref(vector), _1) or something?

Lee

--f46d043be1b0ebedb1050efa9909
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On F=
ri, Feb 13, 2015 at 7:05 AM, Nikita Kniazev <span dir=3D"ltr">&lt;<a href=
=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>&g=
t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>I =
hit problem with attributes propagation when using semantic actions, even w=
ith using enforcing operator %=3D.</div><div>Following test case shows inco=
nsistent in behavior of directives with lazy parameters vs normal.</div><di=
v><br></div><div><pre style=3D"margin-top:0px;margin-bottom:0px"><span styl=
e=3D"color:rgb(128,128,128)">/*********************************************=
*********************************/</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(84=
,84,255)">#include</span> <span style=3D"color:rgb(165,194,97)">&lt;boost/s=
pirit/include/phoenix_core.hpp&gt;</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(84=
,84,255)">#include</span> <span style=3D"color:rgb(165,194,97)">&lt;boost/s=
pirit/include/qi.hpp&gt;</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(20=
4,120,50)">namespace</span> qi <span style=3D"color:rgb(137,148,161)">=3D</=
span> <span style=3D"color:rgb(152,118,170)">boost</span><span style=3D"col=
or:rgb(137,148,161)">::</span><span style=3D"color:rgb(152,118,170)">spirit=
</span><span style=3D"color:rgb(137,148,161)">::</span><span style=3D"color=
:rgb(152,118,170)">qi</span><span style=3D"color:rgb(137,148,161)">;</span>=
</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(20=
4,120,50)">template</span> <span style=3D"color:rgb(137,148,161)">&lt;</spa=
n><span style=3D"color:rgb(204,120,50)">typename</span> <span style=3D"colo=
r:rgb(152,118,170)">T</span><span style=3D"color:rgb(137,148,161)">&gt;</sp=
an></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(12=
8,128,0)">void</span> <span style=3D"color:rgb(255,198,109)">test</span><sp=
an style=3D"color:rgb(137,148,161)">(</span><span style=3D"color:rgb(204,12=
0,50)">const</span> <span style=3D"color:rgb(152,118,170)">T</span><span st=
yle=3D"color:rgb(137,148,161)">&amp;</span> <span style=3D"color:rgb(195,19=
5,195)">rule</span><span style=3D"color:rgb(137,148,161)">)</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(13=
7,148,161)">{</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">  <span style=3D"color:rgb(=
204,120,50)">const</span> <span style=3D"color:rgb(152,118,170)">std</span>=
<span style=3D"color:rgb(137,148,161)">::</span><span style=3D"color:rgb(15=
2,118,170)">string</span> <span style=3D"color:rgb(195,195,195)">in</span> =
<span style=3D"color:rgb(137,148,161)">=3D</span> <span style=3D"color:rgb(=
165,194,97)">&quot;123&quot;</span><span style=3D"color:rgb(137,148,161)">;=
</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">  <span style=3D"color:rgb(=
152,118,170)">std</span><span style=3D"color:rgb(137,148,161)">::</span><sp=
an style=3D"color:rgb(152,118,170)">vector</span><span style=3D"color:rgb(1=
37,148,161)">&lt;</span><span style=3D"color:rgb(128,128,0)">int</span><spa=
n style=3D"color:rgb(137,148,161)">&gt;</span> <span style=3D"color:rgb(195=
,195,195)">out</span><span style=3D"color:rgb(137,148,161)">;</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">  <span style=3D"color:rgb(=
152,118,170)">std</span><span style=3D"color:rgb(137,148,161)">::</span><sp=
an style=3D"color:rgb(152,118,170)">string</span><span style=3D"color:rgb(1=
37,148,161)">::</span><span style=3D"color:rgb(152,118,170)">const_iterator=
</span> <span style=3D"color:rgb(195,195,195)">iter</span> <span style=3D"c=
olor:rgb(137,148,161)">=3D</span> <span style=3D"color:rgb(195,195,195)">in=
</span><span style=3D"color:rgb(137,148,161)">.</span><span style=3D"color:=
rgb(255,198,109)">begin</span><span style=3D"color:rgb(137,148,161)">();</s=
pan></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">  <span style=3D"color:rgb(=
204,120,50)">const</span> <span style=3D"color:rgb(152,118,170)">std</span>=
<span style=3D"color:rgb(137,148,161)">::</span><span style=3D"color:rgb(15=
2,118,170)">string</span><span style=3D"color:rgb(137,148,161)">::</span><s=
pan style=3D"color:rgb(152,118,170)">const_iterator</span> <span style=3D"c=
olor:rgb(195,195,195)">end</span> <span style=3D"color:rgb(137,148,161)">=
=3D</span> <span style=3D"color:rgb(195,195,195)">in</span><span style=3D"c=
olor:rgb(137,148,161)">.</span><span style=3D"color:rgb(255,198,109)">end</=
span><span style=3D"color:rgb(137,148,161)">();</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">  <span style=3D"color:rgb(=
204,120,50)">const</span> <span style=3D"color:rgb(128,128,0)">bool</span> =
<span style=3D"color:rgb(195,195,195)">r</span> <span style=3D"color:rgb(13=
7,148,161)">=3D</span> <span style=3D"color:rgb(152,118,170)">qi</span><spa=
n style=3D"color:rgb(137,148,161)">::</span><span style=3D"color:rgb(255,19=
8,109)">parse</span><span style=3D"color:rgb(137,148,161)">(</span><span st=
yle=3D"color:rgb(195,195,195)">iter</span><span style=3D"color:rgb(137,148,=
161)">,</span> <span style=3D"color:rgb(195,195,195)">end</span><span style=
=3D"color:rgb(137,148,161)">,</span> <span style=3D"color:rgb(195,195,195)"=
>rule</span><span style=3D"color:rgb(137,148,161)">,</span> <span style=3D"=
color:rgb(195,195,195)">out</span><span style=3D"color:rgb(137,148,161)">);=
</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">  <span style=3D"color:rgb(=
152,118,170)">std</span><span style=3D"color:rgb(137,148,161)">::</span>cou=
t <span style=3D"color:rgb(137,148,161)">&lt;&lt;</span> <span style=3D"col=
or:rgb(195,195,195)">out</span><span style=3D"color:rgb(137,148,161)">.</sp=
an><span style=3D"color:rgb(255,198,109)">size</span><span style=3D"color:r=
gb(137,148,161)">()</span> <span style=3D"color:rgb(137,148,161)">&lt;&lt;<=
/span> <span style=3D"color:rgb(152,118,170)">std</span><span style=3D"colo=
r:rgb(137,148,161)">::</span>endl<span style=3D"color:rgb(137,148,161)">;</=
span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">  <span style=3D"color:rgb(=
84,84,255)">BOOST_ASSERT</span><span style=3D"color:rgb(137,148,161)">(</sp=
an><span style=3D"color:rgb(195,195,195)">r</span> <span style=3D"color:rgb=
(137,148,161)">&amp;&amp;</span> <span style=3D"color:rgb(195,195,195)">ite=
r</span> <span style=3D"color:rgb(137,148,161)">=3D=3D</span> <span style=
=3D"color:rgb(195,195,195)">end</span><span style=3D"color:rgb(137,148,161)=
">);</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(13=
7,148,161)">}</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(12=
8,128,0)">int</span> <span style=3D"color:rgb(255,198,109)">main</span><spa=
n style=3D"color:rgb(137,148,161)">()</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(13=
7,148,161)">{</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">    <span style=3D"color:rg=
b(204,120,50)">using</span> <span style=3D"color:rgb(152,118,170)">qi</span=
><span style=3D"color:rgb(137,148,161)">::</span><span style=3D"font-style:=
italic;color:rgb(152,118,170)">int_</span><span style=3D"color:rgb(137,148,=
161)">;</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">    <span style=3D"color:rg=
b(204,120,50)">using</span> <span style=3D"color:rgb(152,118,170)">qi</span=
><span style=3D"color:rgb(137,148,161)">::</span>_1<span style=3D"color:rgb=
(137,148,161)">;</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">    <span style=3D"color:rg=
b(204,120,50)">using</span> <span style=3D"color:rgb(152,118,170)">boost</s=
pan><span style=3D"color:rgb(137,148,161)">::</span><span style=3D"color:rg=
b(152,118,170)">phoenix</span><span style=3D"color:rgb(137,148,161)">::</sp=
an>val<span style=3D"color:rgb(137,148,161)">;</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">                           =
              <span style=3D"color:rgb(128,128,128)">//</span>       <span =
style=3D"color:rgb(128,128,128)">Lazy</span>  <span style=3D"color:rgb(128,=
128,128)">Semantic</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">    <span style=3D"color:rg=
b(255,198,109)">test</span><span style=3D"color:rgb(137,148,161)">(</span><=
span style=3D"color:rgb(152,118,170)">qi</span><span style=3D"color:rgb(137=
,148,161)">::</span>repeat<span style=3D"color:rgb(137,148,161)">(</span><s=
pan style=3D"color:rgb(73,133,139)">1</span><span style=3D"color:rgb(137,14=
8,161)">)[</span>int_<span style=3D"color:rgb(137,148,161)">]);</span>     =
      <span style=3D"color:rgb(128,128,128)">//</span> <span style=3D"color=
:rgb(128,128,128)">OK</span>    <span style=3D"color:rgb(128,128,128)">No</=
span>    <span style=3D"color:rgb(128,128,128)">No</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">    <span style=3D"color:rg=
b(255,198,109)">test</span><span style=3D"color:rgb(137,148,161)">(</span><=
span style=3D"color:rgb(152,118,170)">qi</span><span style=3D"color:rgb(137=
,148,161)">::</span>repeat<span style=3D"color:rgb(137,148,161)">(</span><s=
pan style=3D"color:rgb(73,133,139)">1</span><span style=3D"color:rgb(137,14=
8,161)">)[</span>int_<span style=3D"color:rgb(137,148,161)">[</span>_1<span=
 style=3D"color:rgb(137,148,161)">]]);</span>       <span style=3D"color:rg=
b(128,128,128)">//</span> <span style=3D"color:rgb(128,128,128)">OK</span> =
   <span style=3D"color:rgb(128,128,128)">No</span>    <span style=3D"color=
:rgb(128,128,128)">Yes</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">    <span style=3D"color:rg=
b(255,198,109)">test</span><span style=3D"color:rgb(137,148,161)">(</span><=
span style=3D"color:rgb(152,118,170)">qi</span><span style=3D"color:rgb(137=
,148,161)">::</span>repeat<span style=3D"color:rgb(137,148,161)">(</span>va=
l<span style=3D"color:rgb(137,148,161)">(</span><span style=3D"color:rgb(73=
,133,139)">1</span><span style=3D"color:rgb(137,148,161)">))[</span>int_<sp=
an style=3D"color:rgb(137,148,161)">]);</span>      <span style=3D"color:rg=
b(128,128,128)">//</span> <span style=3D"color:rgb(128,128,128)">OK</span> =
   <span style=3D"color:rgb(128,128,128)">Yes</span>   <span style=3D"color=
:rgb(128,128,128)">No</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">    <span style=3D"color:rg=
b(255,198,109)">test</span><span style=3D"color:rgb(137,148,161)">(</span><=
span style=3D"color:rgb(152,118,170)">qi</span><span style=3D"color:rgb(137=
,148,161)">::</span>repeat<span style=3D"color:rgb(137,148,161)">(</span>va=
l<span style=3D"color:rgb(137,148,161)">(</span><span style=3D"color:rgb(73=
,133,139)">1</span><span style=3D"color:rgb(137,148,161)">))[</span>int_<sp=
an style=3D"color:rgb(137,148,161)">[</span>_1<span style=3D"color:rgb(137,=
148,161)">]]);</span>  <span style=3D"color:rgb(128,128,128)">//</span> <sp=
an style=3D"color:rgb(128,128,128)">FAIL</span>  <span style=3D"color:rgb(1=
28,128,128)">Yes</span>   <span style=3D"color:rgb(128,128,128)">Yes</span>=
</pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><br></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px">    <span style=3D"color:rg=
b(204,120,50)">return</span> <span style=3D"color:rgb(73,133,139)">0</span>=
<span style=3D"color:rgb(137,148,161)">;</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(13=
7,148,161)">}</span></pre>
<pre style=3D"margin-top:0px;margin-bottom:0px"><span style=3D"color:rgb(12=
8,128,128)">/**************************************************************=
****************/</span></pre></div><div><br></div><div>I&#39;m not sure, b=
ut as for me this is a bug (which interfere me at using my own custom direc=
tive).<br></div></div>
</blockquote></div><br></div><div class=3D"gmail_extra">The expression int_=
[_1] creates an integer parser with an attached semantic action that does n=
othing, so its not exactly clear to me what you are trying to do. Did you m=
ean to do a push_back(ref(vector), _1) or something?<br><br></div><div clas=
s=3D"gmail_extra">Lee<br></div></div>

--f46d043be1b0ebedb1050efa9909--


--===============5577914645860305888==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
--===============5577914645860305888==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Spirit-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-devel

--===============5577914645860305888==--