Permalink
Browse files

Some tokens!

  • Loading branch information...
colomon committed Sep 3, 2012
1 parent a5d539e commit f0797bfc8eae01148ea6a9e790ae2bfccba3db28
Showing with 51 additions and 2 deletions.
  1. +6 −0 lib/ISO_10303_21/Grammar.pm
  2. +2 −2 t/01-character-classes.t
  3. +43 −0 t/02-tokens.t
@@ -13,4 +13,10 @@ grammar ISO_10303_21::Grammar
token reverse_solidus { '\\' }
token apostrophe { "'" }
token character { <space> | <digit> | <lower> | <upper> | <special> | <reverse_solidus> | <apostrophe> }
+
+ token standard_keyword { <upper> [ <upper> | <digit> ]* }
+ token user_defined_keyword { '!' <upper> [ <upper> | <digit> ]* }
+ token keyword { <user_defined_keyword> | <standard_keyword> }
+
+ token sign { '+' | '-' }
}
View
@@ -2,6 +2,8 @@ use v6;
use Test;
use ISO_10303_21::Grammar;
+plan 240;
+
for (0..9.Str -> $digit {
my $match = ISO_10303_21::Grammar.parse($digit, :rule<digit>);
isa_ok $match, Match, "<digit> matches $digit - 1";
@@ -31,5 +33,3 @@ for '\\!"*$%&.abc?/:AB0<=>@[]{|}^`~'.comb -> $symbol {
isa_ok $match, Match, "<character> matches $symbol - 1";
ok $match, "<character> matches $symbol - 2";
}
-
-done;
View
@@ -0,0 +1,43 @@
+use v6;
+use Test;
+use ISO_10303_21::Grammar;
+
+for <A A2 AB2 AB2A> -> $keyword {
+ my $match = ISO_10303_21::Grammar.parse($keyword, :rule<standard_keyword>);
+ isa_ok $match, Match, "<standard_keyword> matches $keyword - 1";
+ ok $match, "<standard_keyword> matches $keyword - 2";
+}
+
+for <a a2 ab2 ab2a 2AD> -> $keyword {
+ my $match = ISO_10303_21::Grammar.parse($keyword, :rule<standard_keyword>);
+ isa_ok $match, Match, "<standard_keyword> does not match $keyword - 1";
+ nok $match, "<standard_keyword> does not match $keyword - 2";
+}
+
+for <A A2 AB2 AB2A> -> $keyword {
+ my $match = ISO_10303_21::Grammar.parse("!" ~ $keyword, :rule<user_defined_keyword>);
+ isa_ok $match, Match, "<user_defined_keyword> matches !$keyword - 1";
+ ok $match, "<user_defined_keyword> matches !$keyword - 2";
+}
+
+for <a a2 ab2 ab2a 2AD !ad> -> $keyword {
+ my $match = ISO_10303_21::Grammar.parse($keyword, :rule<user_defined_keyword>);
+ isa_ok $match, Match, "<user_defined_keyword> does not match $keyword - 1";
+ nok $match, "<user_defined_keyword> does not match $keyword - 2";
+}
+
+for <A A2 AB2 AB2A !Z !D23 !AB2A> -> $keyword {
+ my $match = ISO_10303_21::Grammar.parse($keyword, :rule<keyword>);
+ isa_ok $match, Match, "<keyword> matches $keyword - 1";
+ ok $match, "<keyword> matches $keyword - 2";
+}
+
+for ("+", "-") -> $keyword {
+ my $match = ISO_10303_21::Grammar.parse($keyword, :rule<sign>);
+ isa_ok $match, Match, "<sign> matches $keyword - 1";
+ ok $match, "<sign> matches $keyword - 2";
+}
+
+
+
+done;

0 comments on commit f0797bf

Please sign in to comment.