File Coverage

blib/lib/Spp/LintAst.pm
Criterion Covered Total %
statement 14 80 17.5
branch 0 14 0.0
condition n/a
subroutine 5 9 55.5
pod 0 4 0.0
total 19 107 17.7


line stmt bran cond sub pod time code
1             package Spp::LintAst;
2              
3 2     2   34 use 5.012;
  2         6  
4 2     2   10 no warnings 'experimental';
  2         4  
  2         52  
5              
6 2     2   9 use Exporter;
  2         3  
  2         115  
7             our @ISA = qw(Exporter);
8             our @EXPORT =
9             qw(lint_spp_ast lint_spp_token lint_spp_rule lint_spp_atoms);
10              
11 2     2   28 use Spp::Builtin;
  2         3  
  2         315  
12 2     2   11 use Spp::Tools;
  2         3  
  2         962  
13              
14             sub lint_spp_ast {
15 0     0 0   my $ast = shift;
16 0           my $ns = ast_to_table($ast);
17 0           lint_spp_token('door', $ns);
18 0           for my $name (keys %{$ns}) {
  0            
19 0 0         next if $name eq 'text';
20 0 0         next if start_with($name, ":");
21 0           my $lint_name = add(":", $name);
22 0 0         if (not(exists $ns->{$lint_name})) {
23 0 0         next if $name eq 'door';
24 0           say "warn! rule: <$name> not used!";
25             }
26             }
27             }
28              
29             sub lint_spp_token {
30 0     0 0   my ($name, $ns) = @_;
31 0 0         if (not(exists $ns->{$name})) {
32 0           say "not exists token: <$name>";
33             }
34             else {
35 0           my $rule = $ns->{$name};
36 0           my $lint_name = add(":", $name);
37 0 0         if (not(exists $ns->{$lint_name})) {
38 0           $ns->{$lint_name} = 'yes';
39 0           lint_spp_rule($rule, $ns);
40             }
41             }
42             }
43              
44             sub lint_spp_rule {
45 0     0 0   my ($rule, $ns) = @_;
46 0 0         if (is_str($rule)) { return True }
  0            
47 0           my ($name, $atoms) = flat($rule);
48 0           given ($name) {
49 0           when ('Ctoken') { lint_spp_token($atoms, $ns) }
  0            
50 0           when ('Ntoken') { lint_spp_token($atoms, $ns) }
  0            
51 0           when ('Rtoken') { lint_spp_token($atoms, $ns) }
  0            
52 0           when ('Not') { lint_spp_rule($atoms, $ns) }
  0            
53 0           when ('Till') { lint_spp_rule($atoms, $ns) }
  0            
54 0           when ('Rept') { lint_spp_atoms($atoms, $ns) }
  0            
55 0           when ('Look') { lint_spp_atoms($atoms, $ns) }
  0            
56 0           when ('Rules') { lint_spp_atoms($atoms, $ns) }
  0            
57 0           when ('Group') { lint_spp_atoms($atoms, $ns) }
  0            
58 0           when ('Branch') { lint_spp_atoms($atoms, $ns) }
  0            
59 0           when ('Any') { return True }
  0            
60 0           when ('Str') { return True }
  0            
61 0           when ('Char') { return True }
  0            
62 0           when ('Cclass') { return True }
  0            
63 0           when ('Assert') { return True }
  0            
64 0           when ('Chclass') { return True }
  0            
65 0           when ('Nclass') { return True }
  0            
66 0           default { say "miss rule: <$name> check" }
  0            
67             }
68 0           return True;
69             }
70              
71             sub lint_spp_atoms {
72 0     0 0   my ($atoms, $ns) = @_;
73 0           for my $atom (@{ atoms($atoms) }) {
  0            
74 0           lint_spp_rule($atom, $ns);
75             }
76 0           return True;
77             }
78             1;