Re: X3: Alternative operator doesn't reduce?

Michael Powell <[email protected]> Fri, 10 Jul 2020 17:43:26 -0400
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <CAM=aUXpGErgd_J+pkAXJmh-v=MDE9sZ5i+g8HUvPuAMmL+hRpg@mail.gmail.com>
--===============0474694486418559860==
Content-Type: multipart/alternative; boundary="000000000000cfeb5a05aa1d3b45"

--000000000000cfeb5a05aa1d3b45
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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=
.

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?


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

--000000000000cfeb5a05aa1d3b45
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 5:38 PM Aaron=
 Graham &lt;<a href=3D"mailto:[email protected]">[email protected]<=
/a>&gt; 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">X3 <a href=3D"https://www.boost.org/doc/libs/1_73_0/libs/sp=
irit/doc/x3/html/spirit_x3/quick_reference/compound_attribute_rules.html" t=
arget=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);font-size:12px"> </s=
pan><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);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><spa=
n style=3D"color:rgb(0,0,0);font-size:12px"> </span><span style=3D"color:rg=
b(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)">--&gt;<=
/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);font-size:12px">a</span><span style=3D"color:rgb(0,0,0);font-size:1=
2px"> </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"colo=
r:rgb(0,0,0);font-size:12px">b</span><span style=3D"font-size:12px;color:rg=
b(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">A</span></div></block=
quote><div><br></div><div>However, when I write this simple bit of code (ex=
position purposes only):</div><blockquote style=3D"margin:0px 0px 0px 40px;=
border:none;padding:0px"><div>#include &lt;boost/spirit/home/x3.hpp&gt;</di=
v><div>int main() {</div><div>=C2=A0 =C2=A0 using namespace boost::spirit::=
x3;</div><div>=C2=A0 =C2=A0 auto const quoted_string =3D lexeme[&#39;&quot;=
&#39; &gt;&gt; *(char_ - &#39;&quot;&#39;) &gt;&gt; &#39;&quot;&#39;];</div=
><div>=C2=A0 =C2=A0 auto value =3D std::string{};</div><div>=C2=A0 =C2=A0 a=
uto assign_string =3D [&amp;](auto&amp; ctx){ value =3D _attr(ctx); };</div=
><div>=C2=A0 =C2=A0 auto const any_string =3D (quoted_string | quoted_strin=
g) [assign_string];</div><div>=C2=A0 =C2=A0 auto val =3D std::string_view{&=
quot;\&quot;Test\&quot;&quot;};</div><div>=C2=A0 =C2=A0 phrase_parse(val.be=
gin(), val.end(), any_string, space);</div><div>}</div></blockquote><div><b=
r></div><div>I get this error:</div><blockquote style=3D"margin:0px 0px 0px=
 40px;border:none;padding:0px"><div><span style=3D"font-family:monospace;fo=
nt-weight:bold;color:rgb(255,84,84)">error: </span><span style=3D"font-fami=
ly:monospace;color:rgb(0,0,0)">no match for =E2=80=98</span><span style=3D"=
font-family:monospace;font-weight:bold;color:rgb(0,0,0)">operator=3D</span>=
<span style=3D"font-family:monospace;color:rgb(0,0,0)">=E2=80=99 (operand t=
ypes are =E2=80=98</span><span style=3D"font-family:monospace;font-weight:b=
old;color:rgb(0,0,0)">std::__cxx11::b</span></div><div><span style=3D"font-=
family:monospace">asic_string&lt;char&gt;<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&lt;boost::detail::variant::over_sequence&lt;boo</span><=
/span></div><div><span style=3D"font-family:monospace">st::mpl::l_item&lt;m=
pl_::long_&lt;2&gt;, std::__cxx11::basic_string&lt;char&gt;, boost::mpl::l_=
</span></div><div><span style=3D"font-family:monospace">item&lt;mpl_::long_=
&lt;1&gt;, std::__cxx11::basic_string&lt;char&gt;, boost::mpl::l_end&gt; &g=
t; &gt; &gt;<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 [&amp;](auto&amp; 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><br></div><div>Which being said, I&#39;m not sure=
 it makes a whole lot of sense, even in an academic sense, to alternative, =
(qs | qs), does it?</div><div>=C2=A0</div><blockquote class=3D"gmail_quote"=
 style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex">
_______________________________________________<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>

--000000000000cfeb5a05aa1d3b45--


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


--===============0474694486418559860==
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

--===============0474694486418559860==--