Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add the ability to have complete line comments in either the header s…

…ection or the tune body.
  • Loading branch information...
commit dda7786b11a57efea75b15ff9638b5d43841fcb1 1 parent dc43ec8
@colomon authored
Showing with 21 additions and 4 deletions.
  1. +5 −3 lib/ABC/Grammar.pm
  2. +16 −1 t/01-regexes.t
View
8 lib/ABC/Grammar.pm
@@ -3,10 +3,12 @@ use v6;
grammar ABC::Grammar
{
+ regex comment_line { ^^ \h* '%' \N* $$ }
+
token header_field_name { \w }
token header_field_data { \N* }
token header_field { ^^ <header_field_name> ':' \s* <header_field_data> $$ }
- token header { [<header_field> \v+]+ }
+ token header { [[<header_field> | <comment_line>] \v+]+ }
token basenote { <[a..g]+[A..G]> }
token octave { "'"+ | ","+ }
@@ -80,8 +82,8 @@ grammar ABC::Grammar
token interior_header_field_name { < K M L > }
token interior_header_field_data { \N* }
token interior_header_field { ^^ <interior_header_field_name> ':' \s* <interior_header_field_data> $$ }
-
- token music { [[<line_of_music> | <interior_header_field>] \s*]+ }
+
+ token music { [[<line_of_music> | <interior_header_field> | <comment_line> ] \s*]+ }
token tune { <header> <music> }
View
17 t/01-regexes.t
@@ -338,6 +338,20 @@ for ':|:', '|:', '|', ':|', '::', '|]'
}
{
+ my $match = ABC::Grammar.parse(" % this is a comment", :rule<comment_line>);
+ isa_ok $match, Match, 'Got a match';
+ ok $match, 'comment line recognized';
+ is $match, " % this is a comment", "Entire string was matched";
+}
+
+{
+ my $match = ABC::Grammar.parse("% this is a comment", :rule<comment_line>);
+ isa_ok $match, Match, 'Got a match';
+ ok $match, 'comment line recognized';
+ is $match, "% this is a comment", "Entire string was matched";
+}
+
+{
my $line = "g>ecg ec e/f/g/e/ | d/c/B/A/ [K:F] Gd BG B/c/d/B/ |";
my $match = ABC::Grammar.parse($line, :rule<line_of_music>);
isa_ok $match, Match, 'Got a match';
@@ -392,7 +406,8 @@ for ':|:', '|:', '|', ':|', '::', '|]'
}
{
- my $music = q«X:64
+ my $music = q«% Comment
+X:64
T:Cuckold Come Out o' the Amrey
S:Northumbrian Minstrelsy
M:4/4
Please sign in to comment.
Something went wrong with that request. Please try again.