Re: [perl #133541] Grammer bug <alnum> vs <alpha>

[email protected] (Brent Laabs) Fri, 28 Sep 2018 14:54:04 -0700
Newsgroups perl.perl6.compiler
Message-ID <CAAPDpByj2MHC8ew-HhhB1=1=3sz2cr1+2Ua-Nf6Yu_7AZEAoyQ@mail.gmail.com>
--0000000000004a40800576f57f12
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Golfs to just the top grammar, which is the only one that returns Nil.

grammar Alnum1 {
    token TOP {<alnum>|<alnum>.*}
}
grammar AlnumReversed {
    token TOP {<alnum>.*|<alnum>}
}
grammar Alpha1 {
    token TOP {<alpha>|<alpha>.*}
}
my $rx =3D rx/^ [<alnum>|<alnum>.*] $/;

my $str=3D"n~";

.say for "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alnum> =3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D",
 Alnum1.parse($str),
 "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alnum> (reversed) =3D=3D=3D",
 AlnumReversed.parse($str),
 "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alpha> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D",
 Alpha1.parse($str),
 "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Regex   =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D",
 $str ~~ $rx;


On Fri, Sep 28, 2018 at 7:19 AM Patrick R. Michaud via RT <
[email protected]> wrote:

> The issue doesn't seem to be the underscore, because I get the same resul=
t
> even when converting the underscore into a letter ('b'):
>
> $ cat gentb.p6
> grammar G0 {
>         token TOP {<rport>|<ruport>.*}
>         regex rport { <type>}
>         rule ruport { <type>}
>         #token type {<alpha>+}
>         token type {<alnum>+}
> }
>
> grammar G1 {
>         token TOP {<rport>|<ruport>.*}
>         regex rport { <type>}
>         rule ruport { <type>}
>         token type {<alpha>+}
>         #token type {<alnum>+}
> }
> my $str=3D"scbin<foo> bar";
> say "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alnum> Example=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D";
> say G0.parse($str);
> say "=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alpha> Example=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D";
> say G1.parse($str);
>
> $ perl6 gentb.p6
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alnum> Example=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
> Nil
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alpha> Example=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
> =EF=BD=A2scbin<foo> bar=EF=BD=A3
>  ruport =3D> =EF=BD=A2scbin=EF=BD=A3
>   type =3D> =EF=BD=A2scbin=EF=BD=A3
>    alpha =3D> =EF=BD=A2s=EF=BD=A3
>    alpha =3D> =EF=BD=A2c=EF=BD=A3
>    alpha =3D> =EF=BD=A2b=EF=BD=A3
>    alpha =3D> =EF=BD=A2i=EF=BD=A3
>    alpha =3D> =EF=BD=A2n=EF=BD=A3
> $
>
>
> On Fri, Sep 28, 2018 at 02:26:41AM -0700, Brent Laabs wrote:
> > Are you sure about that?  Underscore has been part of the specs
> (synopses)
> > for <alpha> for at least 10 years, probably longer.
> >
> >  >  "_" ~~ /<alpha>/
> > =EF=BD=A2_=EF=BD=A3
> >  alpha =3D> =EF=BD=A2_=EF=BD=A3
> >
> > On Thu, Sep 27, 2018 at 7:52 PM Brandon Allbery <[email protected]>
> wrote:
> >
> > > "_" is not an alphabetic character. It's allowed in "alnum" because
> that
> > > is by intent what is \w in other regex implementations, which include=
s
> "_".
> > >
> > > On Thu, Sep 27, 2018 at 10:47 PM Vijayvithal <
> [email protected]>
> > > wrote:
> > >
> > >> # New Ticket Created by  Vijayvithal
> > >> # Please include the string:  [perl #133541]
> > >> # in the subject line of all future correspondence about this issue.
> > >> # <URL: https://rt.perl.org/Ticket/Display.html?id=3D133541 >
> > >>
> > >>
> > >> In the attached code, the only difference between the Grammars G0 an=
d
> G1
> > >> is the defination of token 'type' it is defined as <alpha> in one ca=
se
> > >> and as <alnum> in another.
> > >>
> > >> Since the string being matched is 'sc_in' both the alpha and alnum
> > >> tokens should have captured it. But we see the following result on
> > >> execution
> > >>
> > >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alnum> Example=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
> > >> Nil
> > >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <alpha> Example=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
> > >> =EF=BD=A2sc_in<foo> bar=EF=BD=A3
> > >> ruport =3D> =EF=BD=A2sc_in=EF=BD=A3
> > >> type =3D> =EF=BD=A2sc_in=EF=BD=A3
> > >> alpha =3D> =EF=BD=A2s=EF=BD=A3
> > >> alpha =3D> =EF=BD=A2c=EF=BD=A3
> > >> alpha =3D> =EF=BD=A2_=EF=BD=A3
> > >> alpha =3D> =EF=BD=A2i=EF=BD=A3
> > >> alpha =3D> =EF=BD=A2n=EF=BD=A3
> > >>
> > >>
> > >> Perl Version is
> > >>
> > >> This is Rakudo Star version 2018.06 built on MoarVM version 2018.06
> > >> implementing Perl 6.c.
> > >>
> > >>
> > >>
> > >> --
> > >> Vijayvithal
> > >> Dyumnin Semiconductors
> > >>
> > >
> > >
> > > --
> > > brandon s allbery kf8nh
> > > [email protected]
> > >
>
>

--0000000000004a40800576f57f12
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div>Golfs to just the top grammar, which=
 is the only one that returns Nil.<br></div><div><br></div><div>grammar Aln=
um1 {<br>=C2=A0=C2=A0=C2=A0 token TOP {&lt;alnum&gt;|&lt;alnum&gt;.*}<br>}<=
br>grammar AlnumReversed {<br>=C2=A0=C2=A0=C2=A0 token TOP {&lt;alnum&gt;.*=
|&lt;alnum&gt;}<br>}<br>grammar Alpha1 {<br>=C2=A0=C2=A0=C2=A0 token TOP {&=
lt;alpha&gt;|&lt;alpha&gt;.*}<br>}<br>my $rx =3D rx/^ [&lt;alnum&gt;|&lt;al=
num&gt;.*] $/;</div><div><br></div><div>my $str=3D&quot;n~&quot;;<br><br>.s=
ay for &quot;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D &lt;alnum&gt; =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D&quot;,<br>=C2=A0Alnum1.parse($str),<br>=C2=
=A0&quot;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D &lt;alnum&gt; (reversed) =3D=3D=
=3D&quot;,<br>=C2=A0AlnumReversed.parse($str),<br>=C2=A0&quot;=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D &lt;alpha&gt; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D&quot;,<br>=C2=A0Alpha1.parse($str),<br>=C2=A0&quot;=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D Regex=C2=A0=C2=A0 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D&quot;,<br>=C2=A0$str ~~ $rx;<br><br></div></div></div><br><div class=3D=
"gmail_quote"><div dir=3D"ltr">On Fri, Sep 28, 2018 at 7:19 AM Patrick R. M=
ichaud via RT &lt;<a href=3D"mailto:[email protected]">perl6-bug=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
The issue doesn&#39;t seem to be the underscore, because I get the same res=
ult even when converting the underscore into a letter (&#39;b&#39;):<br>
<br>
$ cat gentb.p6 <br>
grammar G0 {<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 token TOP {&lt;rport&gt;|&lt;ruport&gt;.*}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 regex rport { &lt;type&gt;}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 rule ruport { &lt;type&gt;}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 #token type {&lt;alpha&gt;+}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 token type {&lt;alnum&gt;+}<br>
}<br>
<br>
grammar G1 {<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 token TOP {&lt;rport&gt;|&lt;ruport&gt;.*}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 regex rport { &lt;type&gt;}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 rule ruport { &lt;type&gt;}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 token type {&lt;alpha&gt;+}<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 #token type {&lt;alnum&gt;+}<br>
}<br>
my $str=3D&quot;scbin&lt;foo&gt; bar&quot;;<br>
say &quot;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D &lt;alnum&gt; Example=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D&quot;;<br>
say G0.parse($str);<br>
say &quot;=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D &lt;alpha&gt; Example=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D&quot;;<br>
say G1.parse($str);<br>
<br>
$ perl6 gentb.p6<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D &lt;alnum&gt; Example=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D<br>
Nil<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D &lt;alpha&gt; Example=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D<br>
=EF=BD=A2scbin&lt;foo&gt; bar=EF=BD=A3<br>
=C2=A0ruport =3D&gt; =EF=BD=A2scbin=EF=BD=A3<br>
=C2=A0 type =3D&gt; =EF=BD=A2scbin=EF=BD=A3<br>
=C2=A0 =C2=A0alpha =3D&gt; =EF=BD=A2s=EF=BD=A3<br>
=C2=A0 =C2=A0alpha =3D&gt; =EF=BD=A2c=EF=BD=A3<br>
=C2=A0 =C2=A0alpha =3D&gt; =EF=BD=A2b=EF=BD=A3<br>
=C2=A0 =C2=A0alpha =3D&gt; =EF=BD=A2i=EF=BD=A3<br>
=C2=A0 =C2=A0alpha =3D&gt; =EF=BD=A2n=EF=BD=A3<br>
$ <br>
<br>
<br>
On Fri, Sep 28, 2018 at 02:26:41AM -0700, Brent Laabs wrote:<br>
&gt; Are you sure about that?=C2=A0 Underscore has been part of the specs (=
synopses)<br>
&gt; for &lt;alpha&gt; for at least 10 years, probably longer.<br>
&gt; <br>
&gt;=C2=A0 &gt;=C2=A0 &quot;_&quot; ~~ /&lt;alpha&gt;/<br>
&gt; =EF=BD=A2_=EF=BD=A3<br>
&gt;=C2=A0 alpha =3D&gt; =EF=BD=A2_=EF=BD=A3<br>
&gt; <br>
&gt; On Thu, Sep 27, 2018 at 7:52 PM Brandon Allbery &lt;<a href=3D"mailto:=
[email protected]" target=3D"_blank">[email protected]</a>&gt; wrote:<b=
r>
&gt; <br>
&gt; &gt; &quot;_&quot; is not an alphabetic character. It&#39;s allowed in=
 &quot;alnum&quot; because that<br>
&gt; &gt; is by intent what is \w in other regex implementations, which inc=
ludes &quot;_&quot;.<br>
&gt; &gt;<br>
&gt; &gt; On Thu, Sep 27, 2018 at 10:47 PM Vijayvithal &lt;<a href=3D"mailt=
o:[email protected]" target=3D"_blank">perl6-bugs-followup@perl.=
org</a>&gt;<br>
&gt; &gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt;&gt; # New Ticket Created by=C2=A0 Vijayvithal<br>
&gt; &gt;&gt; # Please include the string:=C2=A0 [perl #133541]<br>
&gt; &gt;&gt; # in the subject line of all future correspondence about this=
 issue.<br>
&gt; &gt;&gt; # &lt;URL: <a href=3D"https://rt.perl.org/Ticket/Display.html=
?id=3D133541" rel=3D"noreferrer" target=3D"_blank">https://rt.perl.org/Tick=
et/Display.html?id=3D133541</a> &gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; In the attached code, the only difference between the Grammar=
s G0 and G1<br>
&gt; &gt;&gt; is the defination of token &#39;type&#39; it is defined as &l=
t;alpha&gt; in one case<br>
&gt; &gt;&gt; and as &lt;alnum&gt; in another.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Since the string being matched is &#39;sc_in&#39; both the al=
pha and alnum<br>
&gt; &gt;&gt; tokens should have captured it. But we see the following resu=
lt on<br>
&gt; &gt;&gt; execution<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D &lt;alnum&gt; Example=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
&gt; &gt;&gt; Nil<br>
&gt; &gt;&gt; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D &lt;alpha&gt; Example=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
&gt; &gt;&gt; =EF=BD=A2sc_in&lt;foo&gt; bar=EF=BD=A3<br>
&gt; &gt;&gt; ruport =3D&gt; =EF=BD=A2sc_in=EF=BD=A3<br>
&gt; &gt;&gt; type =3D&gt; =EF=BD=A2sc_in=EF=BD=A3<br>
&gt; &gt;&gt; alpha =3D&gt; =EF=BD=A2s=EF=BD=A3<br>
&gt; &gt;&gt; alpha =3D&gt; =EF=BD=A2c=EF=BD=A3<br>
&gt; &gt;&gt; alpha =3D&gt; =EF=BD=A2_=EF=BD=A3<br>
&gt; &gt;&gt; alpha =3D&gt; =EF=BD=A2i=EF=BD=A3<br>
&gt; &gt;&gt; alpha =3D&gt; =EF=BD=A2n=EF=BD=A3<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Perl Version is<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; This is Rakudo Star version 2018.06 built on MoarVM version 2=
018.06<br>
&gt; &gt;&gt; implementing Perl 6.c.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; --<br>
&gt; &gt;&gt; Vijayvithal<br>
&gt; &gt;&gt; Dyumnin Semiconductors<br>
&gt; &gt;&gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; --<br>
&gt; &gt; brandon s allbery kf8nh<br>
&gt; &gt; <a href=3D"mailto:[email protected]" target=3D"_blank">allbery.=
[email protected]</a><br>
&gt; &gt;<br>
<br>
</blockquote></div>

--0000000000004a40800576f57f12--