Skip to content

Instantly share code, notes, and snippets.

@Xliff
Created February 15, 2018 23:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Xliff/7ec03064abe5b061cc8dd0e5d4c26a7d to your computer and use it in GitHub Desktop.

Just for the hell of it, I wrote the following to help me keep track of the rules that have been used, and whether or not they have an associated rule or token block.

Feel free to use for your own projects;

use v6.c;

# Replace with name of your own file, here.
my $script = "DDLGrammar.pm6".IO.open.slurp-rest;

my @used_rules = $script ~~ m:g/ '<' ( <[ _ \w ]>+ ) '>'/;
my @defined_rules = $script ~~ m:g/ [ 'token' || 'rule' ] \s+ ( \w+ ) \s+ '{'/;

@used_rules = @used_rules.map( *[0].Str ).unique.sort;
@defined_rules = @defined_rules.map( *[0].Str ).sort;

#say "USED\n----\n{ @used_rules.join("\n") }\n";
#say "DEF\n---\n{ @defined_rules.join("\n") }";

for @used_rules {
  say "$_ not defined" if @defined_rules.none eq $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment