my @matches = $*IN.slurp.comb(m/ <ABC::tune> /, :match);
Actually, that's a lie. I just came up with that a second ago, when I said to myself, "Wait a minute, maybe slurp works on
$*IN?" Previously I was using
jointo get the same effect.
The scary thing is, that's just the cleanest way I've been able to find to do it in Rakudo. In ideal Perl 6, I believe you could just say
my @matches = slurp.comb(m/ <ABC::tune> /, :match);
I believe in ideal Perl 6 that would be lazy, too, using the
Catclass internally to get a lazy string.
Anyway, that gives you an array of
Matchobjects, one for each ABC tune in the file. But there is one big gotcha with this formulation: if something happens to abort parsing the
ABC::tuneearly (say it hits an ABC directive we haven't implemented yet), comb will merrily skip the rest of the tune without any warning. So this is probably a less than ideal approach in the long run. But my attempts to make a regex for the entire file have failed so far, and this works quite nicely on my sample data.