Browse files

Minor tweaks to grammar, add bin/keywords.

  • Loading branch information...
1 parent 0972762 commit 69225486b05f941f2e243a64b0345141bb8aee20 @colomon committed Mar 12, 2013
Showing with 36 additions and 1 deletion.
  1. +33 −0 bin/keywords
  2. +3 −1 lib/ISO_10303_21/Grammar.pm
View
33 bin/keywords
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl6
+
+use v6;
+use ISO_10303_21::Grammar;
+
+class KeywordActions {
+ has $.keyword-bag;
+
+ method new() {
+ self.bless(*, :keyword-bag(KeyBag.new));
+ }
+
+ method keyword($/) {
+ $.keyword-bag{~$/}++;
+ }
+}
+
+for @*ARGS -> $file {
+ say "Reading $file";
+ my $actions = KeywordActions.new;
+ my $file-data = slurp($file);
+ $file-data .= subst(/"/*" .*? "*/"/, " ", :global);
+ my $match = ISO_10303_21::LooseGrammar.parse($file-data, :rule<exchange_file>, :$actions);
+ if $match ~~ Match && $match {
+ say " read correctly!";
+ } else {
+ say " failed!!!!";
+ }
+
+ for $actions.keyword-bag.pairs.sort -> $keyword {
+ say $keyword.key ~ ": " ~ $keyword.value;
+ }
+}
View
4 lib/ISO_10303_21/Grammar.pm
@@ -71,12 +71,14 @@ grammar ISO_10303_21::Grammar
}
rule exchange_file {
+ ^
"ISO-10303-21;"
<header_section> <data_section>+
"END-ISO-10303-21;"
+ $
}
}
grammar ISO_10303_21::LooseGrammar is ISO_10303_21::Grammar {
- token non_q_char { <special> | <digit> | <space> | <lower> | <upper> | \v }
+ token non_q_char { <.special> | <.digit> | <.space> | <.lower> | <.upper> | \w | \v }
}

0 comments on commit 6922548

Please sign in to comment.