Re: Teaching Rakudo the tricks of Perl 5's regex optimiser
[email protected] ("Patrick R. Michaud") Tue, 13 Aug 2019 10:15:10 -0500
| Newsgroups | perl.perl6.compiler |
|---|---|
| Message-ID | <[email protected]> |
FWIW, at one time there was discussion that "<before>" and "<after>"=20
are actually keywords and not typical method calls that can be overridden=
,
precisely so optimizations can be made. They're that important to
efficient running of the regexes.
I'm not sure that a formal decision was ever made on this, however.
(I'd be okay with declaring them as keywords that cannot be overridden.)
Pm
On Tue, Aug 13, 2019 at 05:01:06PM +0200, Timo Paulssen wrote:
>=20
> > =A0 =A0 use v6;
> > =A0 =A0 'abcd' ~~ / . <.before( /c/ )> .=A0 / # "bc"
> > =A0 =A0 'abcd' ~~ / . <.before=A0 =A0c=A0 =A0> .=A0 / # "bc" # (exact=
ly identical)
> >
> > A person could change the code in the `before` method to have it do
> > something different
>=20
>=20
> At least at the moment, that's not 100% accurate (only by virtue of
> leaving out a piece):
>=20
> 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
> =A0 in regex before at -e line 1
> =A0 in regex TOP at -e line 1
> =A0 in block <unit> at -e line 1
>=20
> 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
> =A0 in regex before at -e line 1
> =A0 in regex TOP at -e line 1
> =A0 in block <unit> at -e line 1
>=20
> timo@schmand ~ [1]> perl6 -e 'grammar test { regex before($re) { { say
> "yo" } }; regex TOP { <?before "hi"> } }; test.parse("hi")'
>=20
> As you can see, using <?before> gives you the "real" lookahead assertio=
n.
>=20
> I'm not sure if that's part of the language yet, but should probably
> made to be.
>=20
>=20
> This will allow more optimization efforts.