Re: Teaching Rakudo the tricks of Perl 5's regex optimiser
[email protected] (Timo Paulssen) Tue, 13 Aug 2019 17:01:06 +0200
| Newsgroups | perl.perl6.compiler |
|---|---|
| Message-ID | <[email protected]> |
> =C2=A0 =C2=A0 use v6;
> =C2=A0 =C2=A0 'abcd' ~~ / . <.before( /c/ )> .=C2=A0 / # "bc"
> =C2=A0 =C2=A0 'abcd' ~~ / . <.before=C2=A0 =C2=A0c=C2=A0 =C2=A0> .=C2=A0=
/ # "bc" # (exactly identical)
>
> A person could change the code in the `before` method to have it do
> something different
At least at the moment, that's not 100% accurate (only by virtue of
leaving out a piece):
timo@schmand ~> perl6 -e 'grammar test { regex before($re) { { say "yo"
} }; regex TOP { <.before "hi"> } }; test.parse("hi")'
yo
Too few positionals passed; expected 2 arguments but got 1
=C2=A0 in regex before at -e line 1
=C2=A0 in regex TOP at -e line 1
=C2=A0 in block <unit> at -e line 1
timo@schmand ~ [1]> perl6 -e 'grammar test { regex before($re) { { say
"yo" } }; regex TOP { <before "hi"> } }; test.parse("hi")'
yo
Too few positionals passed; expected 2 arguments but got 1
=C2=A0 in regex before at -e line 1
=C2=A0 in regex TOP at -e line 1
=C2=A0 in block <unit> at -e line 1
timo@schmand ~ [1]> perl6 -e 'grammar test { regex before($re) { { say
"yo" } }; regex TOP { <?before "hi"> } }; test.parse("hi")'
As you can see, using <?before> gives you the "real" lookahead assertion.
I'm not sure if that's part of the language yet, but should probably
made to be.
This will allow more optimization efforts.