> use v6; > 'abcd' ~~ / . <.before( /c/ )> . / # "bc" > 'abcd' ~~ / . <.before c > . / # "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 in regex before at -e line 1 in regex TOP at -e line 1 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 in regex before at -e line 1 in regex TOP at -e line 1 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.