Permalink
Browse files

Start to sketch in ABC::Duration.

  • Loading branch information...
1 parent 7f72e30 commit 23bdd44aedd472ee986c53c2c011601b0647c2cd @colomon committed Sep 30, 2010
Showing with 35 additions and 17 deletions.
  1. +3 −0 lib/ABC/Actions.pm
  2. +15 −0 lib/ABC/Duration.pm
  3. +2 −17 lib/ABC/Grammar.pm
  4. +15 −0 t/06-duration.t
View
@@ -1,5 +1,8 @@
use v6;
+use ABC::Header;
+use ABC::Tune;
+
class ABC::Actions {
method header_field($/) {
make ~$<header_field_name> => ~$<header_field_data>;
View
@@ -0,0 +1,15 @@
+use v6;
+
+role ABC::Duration {
+ has $.ticks;
+
+ our sub duration-from-parse($top, $bottom) is export {
+ if +$top == 0 && +$bottom == 0 {
+ ABC::Duration.new(:ticks(1/2));
+ } else {
+ ABC::Duration.new(:ticks(($top.Int || 1) / ($bottom.Int || 1)));
+ }
+ }
+
+ # MUST: function to convert Duration to string
+}
View
@@ -13,7 +13,8 @@ grammar ABC::Grammar
regex pitch { <accidental>? <basenote> <octave>? }
regex tie { '-' }
- regex note_length { [\d* ['/' \d*]? ] | '/' }
+ regex number { <digit>+ }
+ regex note_length { [<top=number>? ['/' <bottom=number>?]? ] | '/' }
regex mnote { <pitch> <note_length>? <tie>? }
regex stem { <mnote> | [ '[' <mnote>+ ']' ] }
@@ -146,19 +147,3 @@ sub header_hash($header_match)
}
}
-class ABCHeader
-{
-
-}
-
-class ABCBody
-{
-
-}
-
-class ABCTune
-{
- has $.header;
- has $.body;
-
-}
View
@@ -0,0 +1,15 @@
+use v6;
+use Test;
+use ABC::Duration;
+
+plan *;
+
+is duration-from-parse("2", "3").ticks.perl, (2/3).perl, "2/3 works properly";
+ok duration-from-parse("2", "3") ~~ ABC::Duration, "2/3 generates an object which does Duration";
+is duration-from-parse("", "").ticks.perl, (1/2).perl, "/ works properly";
+ok duration-from-parse("", "") ~~ ABC::Duration, "/ generates an object which does Duration";
+
+is duration-from-parse("1", "").ticks.perl, (1/1).perl, "1 works properly";
+is duration-from-parse("", "2").ticks.perl, (1/2).perl, "/2 works properly";
+
+done_testing;

0 comments on commit 23bdd44

Please sign in to comment.