Permalink
Browse files

Add chords by supporting the "stem" element.

  • Loading branch information...
1 parent 8a49830 commit c78d0e228dfae563460ab4f13fd0be3822e1a37a @LastOfTheCarelessMen committed Jan 22, 2010
Showing with 23 additions and 22 deletions.
  1. +3 −2 lib/ABC.pm
  2. +20 −20 t/01-regexes.t
View
@@ -15,6 +15,7 @@ grammar ABC
regex tie { '-' }
regex note_length { [\d* ['/' \d*]? ] | '/' }
regex note { <pitch> <note_length>? <tie>? }
+ regex stem { <note> | [ '[' <note>+ ']' ] }
regex rest_type { <[x..z]> }
regex rest { <rest_type> <note_length>? }
@@ -30,14 +31,14 @@ grammar ABC
regex spacing { \h+ }
regex broken_rhythm_bracket { ['<'+ | '>'+] }
- regex broken_rhythm { <note> <g1=gracing>* <broken_rhythm_bracket> <g2=gracing>* <note> }
+ regex broken_rhythm { <stem> <g1=gracing>* <broken_rhythm_bracket> <g2=gracing>* <stem> }
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>
+ regex element { <broken_rhythm> | <stem> | <rest> | <gracing> | <grace_notes>
| <nth_repeat> | <end_nth_repeat> | <spacing> }
regex barline { ':|:' | '|:' | '|' | ':|' | '::' }
View
@@ -106,42 +106,42 @@ plan *;
{
my $match = "_D,5/4" ~~ m/ <ABC::element> /;
isa_ok $match, Match, '"_D,5/4" is an element';
- is $match<ABC::element><note><pitch><basenote>, "D", '"_D,5/4" has base note D';
- is $match<ABC::element><note><pitch><octave>, ",", '"_D,5/4" has octave ","';
- is $match<ABC::element><note><pitch><accidental>, "_", '"_D,5/4" is flat';
- is $match<ABC::element><note><note_length>, "5/4", '"_D,5/4" has note length 5/4';
+ is $match<ABC::element><stem><note><pitch><basenote>, "D", '"_D,5/4" has base note D';
+ is $match<ABC::element><stem><note><pitch><octave>, ",", '"_D,5/4" has octave ","';
+ is $match<ABC::element><stem><note><pitch><accidental>, "_", '"_D,5/4" is flat';
+ is $match<ABC::element><stem><note><note_length>, "5/4", '"_D,5/4" has note length 5/4';
}
{
my $match = "A>^C'" ~~ m/ <ABC::broken_rhythm> /;
isa_ok $match, Match, '"A>^C" is a broken rhythm';
- is $match<ABC::broken_rhythm><note>[0]<pitch><basenote>, "A", 'first note is A';
- is $match<ABC::broken_rhythm><note>[0]<pitch><octave>, "", 'first note has no octave';
- is $match<ABC::broken_rhythm><note>[0]<pitch><accidental>, "", 'first note has no accidental';
- is $match<ABC::broken_rhythm><note>[0]<note_length>, "", 'first note has no length';
+ is $match<ABC::broken_rhythm><stem>[0]<note><pitch><basenote>, "A", 'first note is A';
+ is $match<ABC::broken_rhythm><stem>[0]<note><pitch><octave>, "", 'first note has no octave';
+ is $match<ABC::broken_rhythm><stem>[0]<note><pitch><accidental>, "", 'first note has no accidental';
+ is $match<ABC::broken_rhythm><stem>[0]<note><note_length>, "", 'first note has no length';
is $match<ABC::broken_rhythm><broken_rhythm_bracket>, ">", 'angle is >';
- is $match<ABC::broken_rhythm><note>[1]<pitch><basenote>, "C", 'second note is C';
- is $match<ABC::broken_rhythm><note>[1]<pitch><octave>, "'", 'second note has octave tick';
- is $match<ABC::broken_rhythm><note>[1]<pitch><accidental>, "^", 'second note is sharp';
- is $match<ABC::broken_rhythm><note>[1]<note_length>, "", 'second note has no length';
+ is $match<ABC::broken_rhythm><stem>[1]<note><pitch><basenote>, "C", 'second note is C';
+ is $match<ABC::broken_rhythm><stem>[1]<note><pitch><octave>, "'", 'second note has octave tick';
+ is $match<ABC::broken_rhythm><stem>[1]<note><pitch><accidental>, "^", 'second note is sharp';
+ is $match<ABC::broken_rhythm><stem>[1]<note><note_length>, "", 'second note has no length';
}
{
my $match = "d'+p+<<<+accent+_B" ~~ m/ <ABC::broken_rhythm> /;
isa_ok $match, Match, '"d+p+<<<+accent+_B" is a broken rhythm';
given $match<ABC::broken_rhythm>
{
- is .<note>[0]<pitch><basenote>, "d", 'first note is d';
- is .<note>[0]<pitch><octave>, "'", 'first note has an octave tick';
- is .<note>[0]<pitch><accidental>, "", 'first note has no accidental';
- is .<note>[0]<note_length>, "", 'first note has no length';
+ is .<stem>[0]<note><pitch><basenote>, "d", 'first note is d';
+ is .<stem>[0]<note><pitch><octave>, "'", 'first note has an octave tick';
+ is .<stem>[0]<note><pitch><accidental>, "", 'first note has no accidental';
+ is .<stem>[0]<note><note_length>, "", 'first note has no length';
is .<g1>[0], "+p+", 'first gracing is +p+';
is .<broken_rhythm_bracket>, "<<<", 'angle is <<<';
is .<g2>[0], "+accent+", 'second gracing is +accent+';
- is .<note>[1]<pitch><basenote>, "B", 'second note is B';
- is .<note>[1]<pitch><octave>, "", 'second note has no octave';
- is .<note>[1]<pitch><accidental>, "_", 'second note is flat';
- is .<note>[1]<note_length>, "", 'second note has no length';
+ is .<stem>[1]<note><pitch><basenote>, "B", 'second note is B';
+ is .<stem>[1]<note><pitch><octave>, "", 'second note has no octave';
+ is .<stem>[1]<note><pitch><accidental>, "_", 'second note is flat';
+ is .<stem>[1]<note><note_length>, "", 'second note has no length';
}
}

0 comments on commit c78d0e2

Please sign in to comment.