Permalink
Browse files

Add nth repeat regexes.

  • Loading branch information...
1 parent fb0b7d2 commit 0f17a2635a791794cf3523ceaaddb0081402f2bc @LastOfTheCarelessMen committed Jan 16, 2010
Showing with 17 additions and 1 deletion.
  1. +7 −1 lib/ABC.pm
  2. +10 −0 t/01-regexes.t
View
@@ -32,7 +32,13 @@ grammar ABC
regex broken_rhythm_bracket { ['<'+ | '>'+] }
regex broken_rhythm { <note> <g1=gracing>* <broken_rhythm_bracket> <g2=gracing>* <note> }
- regex element { <broken_rhythm> | <note> | <rest> | <gracing> | <spacing> }
+ regex nth_repeat_num { <digit>+ [[',' | '-'] <digit>+]* }
+ regex nth_repeat_text { '"' .*? '"' }
+ regex nth_repeat { '[' [ <nth_repeat_num> | <nth_repeat_text> ] }
+ regex end_nth_repeat { ']' }
+
+ regex element { <broken_rhythm> | <note> | <rest> | <gracing> | <grace_notes>
+ | <nth_repeat> | <end_nth_repeat> | <spacing> }
regex barline { ':|:' | '|:' | '|' | ':|' | '::' }
View
@@ -190,6 +190,16 @@ for ':|:', '|:', '|', ':|', '::'
}
{
+ my $line = 'g>ecg ec e/f/g/e/ |[2-3 d/c/B/A/ {Gd} BG B/c/d/B/ |';
+ my $match = $line ~~ m/ <ABC::line_of_music> /;
+ isa_ok $match, Match, 'line of music recognized';
+ is $match<ABC::line_of_music>, $line, "Entire line was matched";
+ is $match<ABC::line_of_music><bar>[0], "g>ecg ec e/f/g/e/ |", "First bar is correct";
+ is $match<ABC::line_of_music><bar>[1], '[2-3 d/c/B/A/ {Gd} BG B/c/d/B/ |', "Second bar is correct";
+ # say $match<ABC::line_of_music>.perl;
+}
+
+{
my $music = q«A/B/c/A/ +trill+c>d e>deg | GG +trill+B>c d/B/A/G/ B/c/d/B/ |
A/B/c/A/ c>d e>deg | dB/A/ gB +trill+A2 +trill+e2 ::
g>ecg ec e/f/g/e/ | d/c/B/A/ Gd BG B/c/d/B/ |

0 comments on commit 0f17a26

Please sign in to comment.