Re: Spirit-devel Digest, Vol 56, Issue 1
Nikita Kniazev <[email protected]> Fri, 13 Feb 2015 22:46:21 +0300
| Newsgroups | gmane.comp.parsers.spirit.devel |
|---|---|
| Message-ID | <CAPFiOxbWK2eMb8K6hfBYAoo0okwK1XmirKhQQDsZffuxnuooJQ@mail.gmail.com> |
--===============2938882028771060320==
Content-Type: multipart/alternative; boundary=001a11c2162ea6b4ea050efd7df7
--001a11c2162ea6b4ea050efd7df7
Content-Type: text/plain; charset=UTF-8
Reason of using [_1] is simplicity (I just want to enable semantic actions
for showing bug while having minimal code). Replace _1 with whatever you
want (_1 *= 2 for example), but it will not change type of underlying lazy
parser attribute from unused_type (as semantic action disables attribute
propagation for it). As for me all test cases should have same effect, but
for now any directive with lazy arguments yields no result if semantic
action presented.
Test case can be altered to show bug for any directive (if it uses
use_lazy_directive enabler)
/***********************************************************
*******************/
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/repository/include/qi_distinct.hpp>
namespace qi = boost::spirit::qi;
template <typename T>
void test(const T& rule)
{
const std::string in = "str";
boost::optional<std::string> 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);
BOOST_ASSERT(r && iter == end);
std::cout << (out ? "OK" : "FAIL") << std::endl;
}
int main()
{
using qi::_1;
using boost::phoenix::val;
using boost::spirit::repository::qi::distinct;
using qi::alnum;
// Lazy
Semantic
test(distinct(alnum) [qi::string("str")]); // OK No No
test(distinct(alnum) [qi::string("str")[_1]]); // OK No Yes
test(distinct(val(alnum))[qi::string("str")]); // OK Yes No
test(distinct(val(alnum))[qi::string("str")[_1]]); // FAIL Yes Yes
return 0;
}
/***********************************************************
*******************/
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
>
--001a11c2162ea6b4ea050efd7df7
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Reason of using [_1] is simplicity (I just want to en=
able semantic actions for showing bug while having minimal code). Replace _=
1 with whatever you want (_1 *=3D 2 for example), but it will not change ty=
pe of underlying lazy parser attribute from unused_type (as semantic action=
disables attribute propagation for it). As for me all test cases should ha=
ve same effect, but for now any directive with lazy arguments yields no res=
ult if semantic action presented.</div><div>Test case can be altered to sho=
w bug for any directive (if it uses use_lazy_directive enabler)</div><div><=
br></div><div><font face=3D"monospace, monospace"><span style=3D"font-size:=
12.8000001907349px">/*****************************</span><span style=3D"fon=
t-size:12.8000001907349px">******************************</span><span style=
=3D"font-size:12.8000001907349px">*******************/</span></font></div><=
div><span style=3D"font-size:12.8000001907349px"><font face=3D"monospace, m=
onospace">#include <boost/spirit/include/phoenix_core.hpp></font></sp=
an></div><div><span style=3D"font-size:12.8000001907349px"><font face=3D"mo=
nospace, monospace">#include <boost/spirit/include/qi.hpp></font></sp=
an></div><div><span style=3D"font-size:12.8000001907349px"><font face=3D"mo=
nospace, monospace">#include <boost/spirit/repository/include/qi_distinc=
t.hpp></font></span></div><div><span style=3D"font-size:12.8000001907349=
px"><font face=3D"monospace, monospace"><br></font></span></div><div><span =
style=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace">=
namespace qi =3D boost::spirit::qi;</font></span></div><div><span style=3D"=
font-size:12.8000001907349px"><font face=3D"monospace, monospace"><br></fon=
t></span></div><div><span style=3D"font-size:12.8000001907349px"><font face=
=3D"monospace, monospace">template <typename T></font></span></div><d=
iv><span style=3D"font-size:12.8000001907349px"><font face=3D"monospace, mo=
nospace">void test(const T& rule)</font></span></div><div><span style=
=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace">{</fo=
nt></span></div><div><span style=3D"font-size:12.8000001907349px"><font fac=
e=3D"monospace, monospace">=C2=A0 const std::string in =3D "str";=
</font></span></div><div><span style=3D"font-size:12.8000001907349px"><font=
face=3D"monospace, monospace">=C2=A0 boost::optional<std::string> ou=
t;</font></span></div><div><span style=3D"font-size:12.8000001907349px"><fo=
nt face=3D"monospace, monospace"><br></font></span></div><div><span style=
=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace">=C2=
=A0 std::string::const_iterator iter =3D in.begin();</font></span></div><di=
v><span style=3D"font-size:12.8000001907349px"><font face=3D"monospace, mon=
ospace">=C2=A0 const std::string::const_iterator end =3D in.end();</font></=
span></div><div><span style=3D"font-size:12.8000001907349px"><font face=3D"=
monospace, monospace"><br></font></span></div><div><span style=3D"font-size=
:12.8000001907349px"><font face=3D"monospace, monospace">=C2=A0 const bool =
r =3D qi::parse(iter, end, rule, out);</font></span></div><div><div><span s=
tyle=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace">=
=C2=A0 BOOST_ASSERT(r && iter =3D=3D end);</font></span></div></div=
><div><span style=3D"font-size:12.8000001907349px"><font face=3D"monospace,=
monospace"><br></font></span></div><div><span style=3D"font-size:12.800000=
1907349px"><font face=3D"monospace, monospace">=C2=A0 std::cout << (o=
ut ? "OK" : "FAIL") << std::endl;</font></span></=
div><div><span style=3D"font-family:monospace,monospace;font-size:12.800000=
1907349px">}</span><br></div><div><span style=3D"font-size:12.8000001907349=
px"><font face=3D"monospace, monospace"><br></font></span></div><div><span =
style=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace">=
int main()</font></span></div><div><span style=3D"font-size:12.800000190734=
9px"><font face=3D"monospace, monospace">{</font></span></div><div><span st=
yle=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace">=
=C2=A0 =C2=A0 using qi::_1;</font></span></div><div><span style=3D"font-siz=
e:12.8000001907349px"><font face=3D"monospace, monospace">=C2=A0 =C2=A0 usi=
ng boost::phoenix::val;</font></span></div><div><span style=3D"font-size:12=
.8000001907349px"><font face=3D"monospace, monospace">=C2=A0 =C2=A0 using b=
oost::spirit::repository::qi::distinct;</font></span></div><div><span style=
=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace">=C2=
=A0 =C2=A0 using qi::alnum;</font></span></div><div><span style=3D"font-siz=
e:12.8000001907349px"><font face=3D"monospace, monospace">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // =C2=A0 =C2=A0 =C2=A0 Lazy =C2=A0Semantic=
</font></span></div><div><span style=3D"font-size:12.8000001907349px"><font=
face=3D"monospace, monospace">=C2=A0 =C2=A0 test(distinct(alnum) =C2=A0 =
=C2=A0 [qi::string("str")]); =C2=A0 =C2=A0 =C2=A0// OK =C2=A0 =C2=
=A0No =C2=A0 =C2=A0No</font></span></div><div><span style=3D"font-size:12.8=
000001907349px"><font face=3D"monospace, monospace">=C2=A0 =C2=A0 test(dist=
inct(alnum) =C2=A0 =C2=A0 [qi::string("str")[_1]]); =C2=A0// OK =
=C2=A0 =C2=A0No =C2=A0 =C2=A0Yes</font></span></div><div><span style=3D"fon=
t-size:12.8000001907349px"><font face=3D"monospace, monospace">=C2=A0 =C2=
=A0 test(distinct(val(alnum))[qi::string("str")]); =C2=A0 =C2=A0 =
=C2=A0// OK =C2=A0 =C2=A0Yes =C2=A0 No</font></span></div><div><span style=
=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace">=C2=
=A0 =C2=A0 test(distinct(val(alnum))[qi::string("str")[_1]]); =C2=
=A0// FAIL =C2=A0Yes =C2=A0 Yes</font></span></div><div><span style=3D"font=
-size:12.8000001907349px"><font face=3D"monospace, monospace"><br></font></=
span></div><div><span style=3D"font-size:12.8000001907349px"><font face=3D"=
monospace, monospace">=C2=A0 =C2=A0 return 0;</font></span></div><div><span=
style=3D"font-size:12.8000001907349px"><font face=3D"monospace, monospace"=
>}</font></span></div><div><font face=3D"monospace, monospace"><span style=
=3D"font-size:12.8000001907349px">/*****************************</span><spa=
n style=3D"font-size:12.8000001907349px">******************************</sp=
an><span style=3D"font-size:12.8000001907349px">*******************/</span>=
</font><span style=3D"font-size:12.8000001907349px"><br></span><div class=
=3D"gmail_extra"><br><div class=3D"gmail_quote"><blockquote class=3D"gmail_=
quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-=
color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The expres=
sion int_[_1] creates an integer parser with an attached semantic<br>
action that does nothing, so its not exactly clear to me what you are<br>
trying to do. Did you mean to do a push_back(ref(vector), _1) or something?=
<br>
<br>
Lee<br>
</blockquote></div><br></div></div></div>
--001a11c2162ea6b4ea050efd7df7--
--===============2938882028771060320==
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/
--===============2938882028771060320==
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
--===============2938882028771060320==--