forked from lep/jassdoc
/
lint
executable file
·59 lines (47 loc) · 1.3 KB
/
lint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/local/bin/perl
use 5.30.0;
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect('DBI:SQLite:jass.db');
my $stm = $dbh->prepare( 'SELECT 1 from annotations where fnname == ? limit 1' );
sub check_name {
my $name = shift;
$stm->execute( $name );
print "Missing $name\n" unless $stm->fetchrow_array;
}
open(my $fh, "<", $ARGV[0]) or die;
my $state = "nothing";
my $src = "";
my $fn = "";
my $start = 0;
my $end = 0;
while (my $line = <$fh>){
if($state eq "nothing" && $line =~ /^(?:constant\s+)?function\s+(\w+)/){
$state = "function";
$fn = $1;
check_name $fn;
}elsif($state eq "function" && $line =~ /^endfunction/){
$state = "nothing";
}elsif( $line =~ /^(?:constant\s+)?native\s+(\w+)/ && $state eq "nothing" ){
$fn = $1;
check_name $fn;
}elsif ( $state eq "nothing" && $line =~ m/^\s*globals/){
$state = "globals";
}elsif( $state eq "globals" && $line =~ m/^\s*endglobals/){
$state = "nothing";
}elsif( $state eq "nothing" && $line =~ m/^type\s+(\w+)\s+extends\s+.+/){
my $type = $1;
check_name $type;
}elsif ( $state eq "globals" ){
my $name;
given($line){
$name = $1 when /^\s*constant\s+\w+\s+(\w+)\s*=.+$/;
$name = $1 when /^\s*\w+\s+array\s+(\w+)/;
$name = $1 when /^\s*\w+\s+(\w+)/;
}
if($name){
check_name $name;
}
}
}