Skip to content

Commit

Permalink
Move the grammar to the ABC.pm file.
Browse files Browse the repository at this point in the history
  • Loading branch information
LastOfTheCarelessMen committed Dec 16, 2009
1 parent a0e8c61 commit c08cd27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
17 changes: 17 additions & 0 deletions lib/ABC.pm
@@ -1,5 +1,22 @@
use v6;

grammar ABC
{
regex header_field_name { \w }
regex header_field_data { \N* }
regex header_field { ^^ <header_field_name> ':' \s* <header_field_data> $$ }
regex header { [<header_field> \n]+ }

regex basenote { <[a..g]+[A..G]> }
regex octave { \'+ | \,+ }
regex accidental { '^' | '^^' | '_' | '__' | '=' }
regex pitch { <accidental>? <basenote> <octave>? }

regex tie { '-' }
regex note_length { [\d* ['/' \d*] ] | '/' }
regex note { <pitch> <note_length>? <tie>? }
}

class ABCHeader
{

Expand Down
20 changes: 3 additions & 17 deletions playing.pl
@@ -1,5 +1,8 @@
use v6;

BEGIN { push @*INC, "lib" }
use ABC;

my $abc = q«X:64
T:Cuckold Come Out o' the Amrey
S:Northumbrian Minstrelsy
Expand All @@ -11,23 +14,6 @@
g>ecg ec e/f/g/e/ | d/c/B/A/ Gd BG B/c/d/B/ |
g/f/e/d/ c/d/e/f/ gc e/f/g/e/ | dB/A/ gB +trill+A2 +trill+e2 :|»;

grammar ABC
{
regex header_field_name { \w }
regex header_field_data { \N* }
regex header_field { ^^ <header_field_name> ':' \s* <header_field_data> $$ }
regex header { [<header_field> \n]+ }

regex basenote { <[a..g]+[A..G]> }
regex octave { \'+ | \,+ }
regex accidental { '^' | '^^' | '_' | '__' | '=' }
regex pitch { <accidental>? <basenote> <octave>? }

regex tie { '-' }
regex note_length { [\d* ['/' \d*] ] | '/' }
regex note { <pitch> <note_length>? <tie>? }
}

if $abc ~~ m/ <ABC::header> /
{
for $<ABC::header><header_field> -> $line
Expand Down

0 comments on commit c08cd27

Please sign in to comment.