Skip to content
Browse files

Directories.

  • Loading branch information...
1 parent c21a314 commit 9d64d20bfb7c004ca0b2779182898932766b944d @colomon committed
Showing with 45 additions and 0 deletions.
  1. +16 −0 lib/ISO_10303_21/Grammar.pm
  2. +29 −0 t/01-character-classes.t
View
16 lib/ISO_10303_21/Grammar.pm
@@ -0,0 +1,16 @@
+use v6;
+
+grammar ISO_10303_21::Grammar
+{
+ token space { " " }
+ token digit { <[0..9]> }
+ token lower { <[a..z]> }
+ token upper { <[A..Z]> }
+ token special { '!' | '"' | '*' | '$' | '%' | '&' | '.' | '#'
+ | '+' | ',' | '-' | '(' | ')' | '?' | '/' | ':'
+ | ';' | '<' | '=' | '>' | '@' | '[' | ']' | '{'
+ | '|' | '}' | '^' | '`' | '~' }
+ token reverse_solidus { '\\' }
+ token apostrophe { "'" }
+ token character { <space> | <digit> | <lower> | <upper> | <special> | <reverse_solidus> | <apostrophe> }
+}
View
29 t/01-character-classes.t
@@ -0,0 +1,29 @@
+use v6;
+use Test;
+use ISO_10303_21::Grammar;
+
+for (0..9)».Str -> $digit {
+ my $match = ISO_10303_21::Grammar.parse($digit, :rule<digit>);
+ isa_ok $match, Match, "<digit> matches $digit - 1";
+ ok $match, "<digit> matches $digit - 2";
+}
+
+for 'a'..'z' -> $lower {
+ my $match = ISO_10303_21::Grammar.parse($lower, :rule<lower>);
+ isa_ok $match, Match, "<lower> matches $lower - 1";
+ ok $match, "<lower> matches $lower - 2";
+}
+
+for 'A'..'Z' -> $upper {
+ my $match = ISO_10303_21::Grammar.parse($upper, :rule<upper>);
+ isa_ok $match, Match, "<upper> matches $upper - 1";
+ ok $match, "<upper> matches $upper - 2";
+}
+
+for '!"*$%&.#+,-()?/:;<=>@[]{|}^`~'.comb -> $symbol {
+ my $match = ISO_10303_21::Grammar.parse($symbol, :rule<special>);
+ isa_ok $match, Match, "<special> matches $symbol - 1";
+ ok $match, "<special> matches $symbol - 2";
+}
+
+done;

0 comments on commit 9d64d20

Please sign in to comment.
Something went wrong with that request. Please try again.