Auto attributes propagation in directives with lazy arguments
Nikita Kniazev <[email protected]> Fri, 13 Feb 2015 15:05:05 +0300
| Newsgroups | gmane.comp.parsers.spirit.devel |
|---|---|
| Message-ID | <CAPFiOxYfeXxtnUifQqhMAfrS3UtRM9BtQP7ana82X1SVUjpytg@mail.gmail.com> |
--===============1728330279908765193==
Content-Type: multipart/alternative; boundary=001a11c2162e0d2b80050ef70cad
--001a11c2162e0d2b80050ef70cad
Content-Type: text/plain; charset=UTF-8
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).
--001a11c2162e0d2b80050ef70cad
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I hit problem with attributes propagation when using =
semantic actions, even with using enforcing operator %=3D.</div><div>Follow=
ing test case shows inconsistent in behavior of directives with lazy parame=
ters vs normal.</div><div><br></div><div><pre style=3D"margin-top:0px;margi=
n-bottom:0px"><span style=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)"><boost/s=
pirit/include/phoenix_core.hpp></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)"><boost/s=
pirit/include/qi.hpp></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)"><</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)">></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)">&</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)">"123"</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)"><</span><span style=3D"color:rgb(128,128,0)">int</span><spa=
n 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><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)"><<</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)"><<<=
/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)">&&</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'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>
--001a11c2162e0d2b80050ef70cad--
--===============1728330279908765193==
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/
--===============1728330279908765193==
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
--===============1728330279908765193==--