Damian Conway:
# > I'm still unclear as to how you implement lex-like longest
# token rule
# > with P6 regexes. If the | operator grabs the first one it matches,
# > how do I match "bacamus" out of this?:
# >
# > "bacamus" =~ / b.*a | b.*s /
#
# Borrow this trick from Parse::RecDescent:
#
# rule max (*@candidates) {{
# my $best;
# my $startpos = .pos;
# for @candidates -> $next {
# .pos = $startpos;
# $best = $0 if /<$next>/ && $best &&
# $0.length < $best.length {
# }
# fail unless $best;
# let $0 := $best;
# .pos = $best.pos;
# }}
#
# then:
#
# "bacamus" =~ / <max(/b.*a/, /b.*s/)> /;
Will that handle captures correctly? Maybe you should temporize $0...
--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)
Early in the series, Patrick Stewart came up to us and asked how warp
drive worked. We explained some of the hypothetical principles . . .
"Nonsense," Patrick declared. "All you have to do is say, 'Engage.'"
--Star Trek: The Next Generation Technical Manual