> 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/)> /; Damian