Re: X3: Alternative operator doesn't reduce?
Michael Powell <[email protected]> Fri, 10 Jul 2020 18:33:05 -0400
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CAM=aUXpWabQqN+=dBKf4b0o9ksiZhA16Lb23Bc0+ZLdgJmk4tQ@mail.gmail.com> |
--===============7084255152745967323== Content-Type: multipart/alternative; boundary="00000000000059c7e205aa1ded72" --00000000000059c7e205aa1ded72 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jul 10, 2020 at 6:09 PM Aaron Graham <[email protected]> wrote: > > > On Fri, Jul 10, 2020 at 2:43 PM Michael Powell <[email protected]> > wrote: > >> >> >> On Fri, Jul 10, 2020 at 5:38 PM Aaron Graham <[email protected]> >> wrote: >> >>> X3 compound attribute rules >>> <https://www.boost.org/doc/libs/1_73_0/libs/spirit/doc/x3/html/spirit_x= 3/quick_reference/compound_attribute_rules.html> >>> say this: >>> >>> a: A, b: A --> (a | b): A >>> >>> >>> However, when I write this simple bit of code (exposition purposes only= ): >>> >>> #include <boost/spirit/home/x3.hpp> >>> int main() { >>> using namespace boost::spirit::x3; >>> auto const quoted_string =3D lexeme['"' >> *(char_ - '"') >> '"']; >>> auto value =3D std::string{}; >>> auto assign_string =3D [&](auto& ctx){ value =3D _attr(ctx); }; >>> auto const any_string =3D (quoted_string | quoted_string) >>> [assign_string]; >>> auto val =3D std::string_view{"\"Test\""}; >>> phrase_parse(val.begin(), val.end(), any_string, space); >>> } >>> >>> >>> I get this error: >>> >>> error: no match for =E2=80=98operator=3D=E2=80=99 (operand types are = =E2=80=98std::__cxx11::b >>> asic_string<char>=E2=80=99 and =E2=80=98 >>> boost::variant<boost::detail::variant::over_sequence<boo >>> st::mpl::l_item<mpl_::long_<2>, std::__cxx11::basic_string<char>, >>> boost::mpl::l_ >>> item<mpl_::long_<1>, std::__cxx11::basic_string<char>, >>> boost::mpl::l_end> > > >=E2=80=99 >>> ) >>> 7 | auto assign_string =3D [&](auto& ctx){ value =3D _attr(ctx);= }; >>> | >>> >>> Why is the attribute a variant instead of a string? >>> >> >> AFAIK, this is the way alternatives have always worked since even before >> X3. >> > > I've written a lot of very complicated qi parsers and I don't remember > ever running across this problem. It's possible it just never came up, bu= t > I doubt it. > In the past, I've identified a couple of areas in the docs that stated one way, but in reality it was something else. Perhaps this is one of them for you? I cannot say. But it doesn't matter. The documentation I linked in my previous email says= : > > a: A, b: A --> (a | b): A > > and not: > > a: A, b: A --> (a | b): variant<A, A> > > But the error message from the compiler clearly expresses that that's wha= t > I'm getting. I'll dig into the x3 code when I have some time and try to > figure it out. > > Which being said, I'm not sure it makes a whole lot of sense, even in an >> academic sense, to alternative, (qs | qs), does it? >> > > I knew someone would answer that way, which is why I had the disclaimer > "exposition purposes only". My real code looks a little different. But th= e > attribute type is the same. The point in this example is to present code > that's alternating between two clearly identical attribute types. > _______________________________________________ > Spirit-general mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/spirit-general > --00000000000059c7e205aa1ded72 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">= <div dir=3D"ltr" class=3D"gmail_attr">On Fri, Jul 10, 2020 at 6:09 PM Aaron= Graham <<a href=3D"mailto:[email protected]">[email protected]<= /a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0= px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><= div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote"><= div dir=3D"ltr" class=3D"gmail_attr">On Fri, Jul 10, 2020 at 2:43 PM Michae= l Powell <<a href=3D"mailto:[email protected]" target=3D"_blank">mwp= [email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote= " style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);= padding-left:1ex"><div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div clas= s=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Jul 10, 202= 0 at 5:38 PM Aaron Graham <<a href=3D"mailto:[email protected]" targ= et=3D"_blank">[email protected]</a>> wrote:<br></div><blockquote cla= ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid = rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">X3 <a href=3D"https://w= ww.boost.org/doc/libs/1_73_0/libs/spirit/doc/x3/html/spirit_x3/quick_refere= nce/compound_attribute_rules.html" target=3D"_blank">compound attribute rul= es</a> say this:<blockquote style=3D"margin:0px 0px 0px 40px;border:none;pa= dding:0px"><div><span style=3D"color:rgb(0,0,0);font-size:12px">a</span><sp= an style=3D"font-size:12px;color:rgb(112,112,112)">:</span><span style=3D"c= olor:rgb(0,0,0);font-size:12px"> </span><span style=3D"color:rgb(0,0,0);fon= t-size:12px">A</span><span style=3D"font-size:12px;color:rgb(112,112,112)">= ,</span><span style=3D"color:rgb(0,0,0);font-size:12px"> </span><span style= =3D"color:rgb(0,0,0);font-size:12px">b</span><span style=3D"font-size:12px;= color:rgb(112,112,112)">:</span><span style=3D"color:rgb(0,0,0);font-size:1= 2px"> </span><span style=3D"color:rgb(0,0,0);font-size:12px">A</span><span = style=3D"color:rgb(0,0,0);font-size:12px"> </span><span style=3D"font-size:= 12px;color:rgb(112,112,112)">--></span><span style=3D"color:rgb(0,0,0);f= ont-size:12px"> </span><span style=3D"font-size:12px;color:rgb(112,112,112)= ">(</span><span style=3D"color:rgb(0,0,0);font-size:12px">a</span><span sty= le=3D"color:rgb(0,0,0);font-size:12px"> </span><span style=3D"font-size:12p= x;color:rgb(112,112,112)">|</span><span style=3D"color:rgb(0,0,0);font-size= :12px"> </span><span style=3D"color:rgb(0,0,0);font-size:12px">b</span><spa= n style=3D"font-size:12px;color:rgb(112,112,112)">):</span><span style=3D"c= olor:rgb(0,0,0);font-size:12px"> </span><span style=3D"color:rgb(0,0,0);fon= t-size:12px">A</span></div></blockquote><div><br></div><div>However, when I= write this simple bit of code (exposition purposes only):</div><blockquote= style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div>#include &l= t;boost/spirit/home/x3.hpp></div><div>int main() {</div><div>=C2=A0 =C2= =A0 using namespace boost::spirit::x3;</div><div>=C2=A0 =C2=A0 auto const q= uoted_string =3D lexeme['"' >> *(char_ - '"'= ;) >> '"'];</div><div>=C2=A0 =C2=A0 auto value =3D std::= string{};</div><div>=C2=A0 =C2=A0 auto assign_string =3D [&](auto& = ctx){ value =3D _attr(ctx); };</div><div>=C2=A0 =C2=A0 auto const any_strin= g =3D (quoted_string | quoted_string) [assign_string];</div><div>=C2=A0 =C2= =A0 auto val =3D std::string_view{"\"Test\""};</div><di= v>=C2=A0 =C2=A0 phrase_parse(val.begin(), val.end(), any_string, space);</d= iv><div>}</div></blockquote><div><br></div><div>I get this error:</div><blo= ckquote style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div><spa= n style=3D"font-family:monospace;font-weight:bold;color:rgb(255,84,84)">err= or: </span><span style=3D"font-family:monospace;color:rgb(0,0,0)">no match = for =E2=80=98</span><span style=3D"font-family:monospace;font-weight:bold;c= olor:rgb(0,0,0)">operator=3D</span><span style=3D"font-family:monospace;col= or:rgb(0,0,0)">=E2=80=99 (operand types are =E2=80=98</span><span style=3D"= font-family:monospace;font-weight:bold;color:rgb(0,0,0)">std::__cxx11::b</s= pan></div><div><span style=3D"font-family:monospace">asic_string<char>= ;<span style=3D"color:rgb(0,0,0)">=E2=80=99 and =E2=80=98</span><span style= =3D"font-weight:bold;color:rgb(0,0,0)">boost::variant<boost::detail::var= iant::over_sequence<boo</span></span></div><div><span style=3D"font-fami= ly:monospace">st::mpl::l_item<mpl_::long_<2>, std::__cxx11::basic_= string<char>, boost::mpl::l_</span></div><div><span style=3D"font-fam= ily:monospace">item<mpl_::long_<1>, std::__cxx11::basic_string<= char>, boost::mpl::l_end> > > ><span style=3D"color:rgb(0,0,= 0)">=E2=80=99</span></span></div><div><span style=3D"font-family:monospace"= >) </span></div><div><span style=3D"font-family:monospace"> =C2=A0=C2=A0=C2=A0= 7 | =C2=A0=C2=A0=C2=A0=C2=A0auto assign_string =3D [&](auto& ctx){ = <span style=3D"font-weight:bold;color:rgb(255,84,84)">value =3D _attr(ctx)<= /span><span style=3D"color:rgb(0,0,0)">; }; </span></span></div><div><span style=3D"font-family:monospace"> =C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0|</span></div><div><br></div></blockquote><div>Why is = the attribute a variant instead of a string?</div></div></blockquote><div><= br></div><div>AFAIK, this is the way alternatives have always worked since = even before X3.</div></div></div></blockquote><div><br></div><div>I've = written a lot of very complicated qi parsers and I don't remember ever = running across this problem. It's possible it just never came up, but I= doubt it.</div></div></div></blockquote><div><br></div><div>In the past, I= 've identified a couple of areas in the docs that stated one way, but i= n reality it was something else. Perhaps this is one of them for you? I can= not say.=C2=A0</div><div><br></div><blockquote class=3D"gmail_quote" style= =3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding= -left:1ex"><div dir=3D"ltr"><div class=3D"gmail_quote"><div>But it doesn= 9;t matter. The documentation I linked in my previous email says:<br></div>= </div><blockquote style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"= ><div class=3D"gmail_quote"><div><pre style=3D"color:rgb(0,0,0);font-size:1= 2px"><span>a: A</span><span style=3D"color:rgb(112,112,112)">,</span> <span= >b</span><span style=3D"color:rgb(112,112,112)">:</span> <span>A</span> <sp= an style=3D"color:rgb(112,112,112)">--></span> <span style=3D"color:rgb(= 112,112,112)">(</span><span>a</span> <span style=3D"color:rgb(112,112,112)"= >|</span> <span>b</span><span style=3D"color:rgb(112,112,112)">):</span> <s= pan>A</span></pre></div></div></blockquote><div class=3D"gmail_quote"><div>= and not:</div></div><blockquote style=3D"margin:0px 0px 0px 40px;border:non= e;padding:0px"><div class=3D"gmail_quote"><div><pre style=3D"color:rgb(0,0,= 0);font-size:12px"><span>a: A</span><span style=3D"color:rgb(112,112,112)">= ,</span> <span>b</span><span style=3D"color:rgb(112,112,112)">:</span> A <s= pan style=3D"color:rgb(112,112,112)">--></span> <span style=3D"color:rgb= (112,112,112)">(</span><span>a</span> <span style=3D"color:rgb(112,112,112)= ">|</span> <span>b</span><span style=3D"color:rgb(112,112,112)">):</span> <= span>variant</span><span style=3D"color:rgb(112,112,112)"><</span><span>= A</span><span style=3D"color:rgb(112,112,112)">,</span> A<span style=3D"col= or:rgb(112,112,112)">></span></pre></div></div></blockquote><div class= =3D"gmail_quote"><div>But the error message from the compiler clearly expre= sses that that's what I'm getting. I'll dig into the x3 code wh= en I have some time and try to figure it out.</div><div><br></div><blockquo= te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px = solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div class=3D"gma= il_quote"><div>Which being said, I'm not sure it makes a whole lot of s= ense, even in an academic sense, to alternative, (qs | qs), does it?=C2=A0<= br></div></div></div></blockquote><div><br></div><div>I knew someone would = answer that way, which is why I had the disclaimer "exposition purpose= s only". My real code looks a little different. But the attribute type= is the same. The point in this example is to present code that's alter= nating between two clearly identical attribute types.</div></div></div> _______________________________________________<br> Spirit-general mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">S= [email protected]</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/spirit-general" rel= =3D"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listi= nfo/spirit-general</a><br> </blockquote></div></div> --00000000000059c7e205aa1ded72-- --===============7084255152745967323== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============7084255152745967323== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Spirit-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spirit-general --===============7084255152745967323==--