Re: X3: Alternative operator doesn't reduce?
Aaron Graham <[email protected]> Fri, 10 Jul 2020 15:00:40 -0700
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <CADXX4PRsXzvrx5=m4NfUJVW35gUe-RyC7-rFf7SSRjNciH2t8w@mail.gmail.com> |
--===============7641108187147454226== Content-Type: multipart/alternative; boundary="000000000000671f2205aa1d79fb" --000000000000671f2205aa1d79fb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_x3= /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, but I doubt it. 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 what 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 the attribute type is the same. The point in this example is to present code that's alternating between two clearly identical attribute types. --000000000000671f2205aa1d79fb 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 2:43 PM Micha= el Powell <<a href=3D"mailto:[email protected]">[email protected]= m</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 class=3D"gmail_quote"= ><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Jul 10, 2020 at 5:38 PM Aaro= n Graham <<a href=3D"mailto:[email protected]" target=3D"_blank">aar= [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">X3 <a href=3D"https://www.boost.org/doc/= libs/1_73_0/libs/spirit/doc/x3/html/spirit_x3/quick_reference/compound_attr= ibute_rules.html" target=3D"_blank">compound attribute rules</a> say this:<= blockquote style=3D"margin:0px 0px 0px 40px;border:none;padding:0px"><div><= span style=3D"color:rgb(0,0,0);font-size:12px">a</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"color:rgb(0,0,0);font-size:12px">A</s= pan><span style=3D"font-size:12px;color:rgb(112,112,112)">,</span><span sty= le=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:12px"> </span><spa= n style=3D"color:rgb(0,0,0);font-size:12px">A</span><span style=3D"color:rg= b(0,0,0);font-size:12px"> </span><span style=3D"font-size:12px;color:rgb(11= 2,112,112)">--></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 s= tyle=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,1= 12,112)">|</span><span style=3D"color:rgb(0,0,0);font-size:12px"> </span><s= pan style=3D"color:rgb(0,0,0);font-size:12px">b</span><span style=3D"font-s= ize:12px;color:rgb(112,112,112)">):</span><span style=3D"color:rgb(0,0,0);f= ont-size:12px"> </span><span style=3D"color:rgb(0,0,0);font-size:12px">A</s= pan></div></blockquote><div><br></div><div>However, when I write this simpl= e bit of code (exposition purposes only):</div><blockquote style=3D"margin:= 0px 0px 0px 40px;border:none;padding:0px"><div>#include <boost/spirit/ho= me/x3.hpp></div><div>int main() {</div><div>=C2=A0 =C2=A0 using namespac= e boost::spirit::x3;</div><div>=C2=A0 =C2=A0 auto const quoted_string =3D l= exeme['"' >> *(char_ - '"') >> '&= quot;'];</div><div>=C2=A0 =C2=A0 auto value =3D std::string{};</div><di= v>=C2=A0 =C2=A0 auto assign_string =3D [&](auto& ctx){ value =3D _a= ttr(ctx); };</div><div>=C2=A0 =C2=A0 auto const any_string =3D (quoted_stri= ng | quoted_string) [assign_string];</div><div>=C2=A0 =C2=A0 auto val =3D s= td::string_view{"\"Test\""};</div><div>=C2=A0 =C2=A0 ph= rase_parse(val.begin(), val.end(), any_string, space);</div><div>}</div></b= lockquote><div><br></div><div>I get this error:</div><blockquote style=3D"m= argin:0px 0px 0px 40px;border:none;padding:0px"><div><span style=3D"font-fa= mily:monospace;font-weight:bold;color:rgb(255,84,84)">error: </span><span s= tyle=3D"font-family:monospace;color:rgb(0,0,0)">no match for =E2=80=98</spa= n><span style=3D"font-family:monospace;font-weight:bold;color:rgb(0,0,0)">o= perator=3D</span><span style=3D"font-family:monospace;color:rgb(0,0,0)">=E2= =80=99 (operand types are =E2=80=98</span><span style=3D"font-family:monosp= ace;font-weight:bold;color:rgb(0,0,0)">std::__cxx11::b</span></div><div><sp= an style=3D"font-family:monospace">asic_string<char><span style=3D"co= lor:rgb(0,0,0)">=E2=80=99 and =E2=80=98</span><span style=3D"font-weight:bo= ld;color:rgb(0,0,0)">boost::variant<boost::detail::variant::over_sequenc= e<boo</span></span></div><div><span style=3D"font-family:monospace">st::= mpl::l_item<mpl_::long_<2>, std::__cxx11::basic_string<char>= , boost::mpl::l_</span></div><div><span style=3D"font-family:monospace">ite= m<mpl_::long_<1>, std::__cxx11::basic_string<char>, boost::m= pl::l_end> > > ><span style=3D"color:rgb(0,0,0)">=E2=80=99</spa= n></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><br></div><div>But it doesn't matter. The document= ation I linked in my previous email says:</div></div><blockquote style=3D"m= argin:0 0 0 40px;border:none;padding:0px"><div class=3D"gmail_quote"><div><= pre class=3D"gmail-table-programlisting" style=3D"color:rgb(0,0,0);font-siz= e:12px"><span class=3D"gmail-identifier">a: A</span><span class=3D"gmail-sp= ecial" style=3D"color:rgb(112,112,112)">,</span> <span class=3D"gmail-ident= ifier">b</span><span class=3D"gmail-special" style=3D"color:rgb(112,112,112= )">:</span> <span class=3D"gmail-identifier">A</span> <span class=3D"gmail-= special" style=3D"color:rgb(112,112,112)">--></span> <span class=3D"gmai= l-special" style=3D"color:rgb(112,112,112)">(</span><span class=3D"gmail-id= entifier">a</span> <span class=3D"gmail-special" style=3D"color:rgb(112,112= ,112)">|</span> <span class=3D"gmail-identifier">b</span><span class=3D"gma= il-special" style=3D"color:rgb(112,112,112)">):</span> <span class=3D"gmail= -identifier">A</span></pre></div></div></blockquote><div class=3D"gmail_quo= te"><div>and not:</div></div><blockquote style=3D"margin:0 0 0 40px;border:= none;padding:0px"><div class=3D"gmail_quote"><div><pre class=3D"gmail-table= -programlisting" style=3D"color:rgb(0,0,0);font-size:12px"><span class=3D"g= mail-identifier">a: A</span><span class=3D"gmail-special" style=3D"color:rg= b(112,112,112)">,</span> <span class=3D"gmail-identifier">b</span><span cla= ss=3D"gmail-special" style=3D"color:rgb(112,112,112)">:</span> A <span clas= s=3D"gmail-special" style=3D"color:rgb(112,112,112)">--></span> <span cl= ass=3D"gmail-special" style=3D"color:rgb(112,112,112)">(</span><span class= =3D"gmail-identifier">a</span> <span class=3D"gmail-special" style=3D"color= :rgb(112,112,112)">|</span> <span class=3D"gmail-identifier">b</span><span = class=3D"gmail-special" style=3D"color:rgb(112,112,112)">):</span> <span cl= ass=3D"gmail-identifier">variant</span><span class=3D"gmail-special" style= =3D"color:rgb(112,112,112)"><</span><span class=3D"gmail-identifier">A</= span><span class=3D"gmail-special" style=3D"color:rgb(112,112,112)">,</span= > A<span class=3D"gmail-special" style=3D"color:rgb(112,112,112)">></spa= n></pre></div></div></blockquote><div class=3D"gmail_quote"><div>But the er= ror message from the compiler clearly expresses that that's what I'= m getting. I'll dig into the x3 code when I have some time and try to f= igure it out.</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>Which being sai= d, I'm not sure it makes a whole lot of sense, even in an academic sens= e, to alternative, (qs | qs), does it?=C2=A0<br></div></div></div></blockqu= ote><div><br></div><div>I knew someone would answer that way, which is why = I had the disclaimer "exposition purposes only". My real code loo= ks a little different. But the attribute type is the same. The point in thi= s example is to present code that's alternating between two clearly ide= ntical attribute types.</div></div></div> --000000000000671f2205aa1d79fb-- --===============7641108187147454226== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============7641108187147454226== 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 --===============7641108187147454226==--