summaryrefslogtreecommitdiff
path: root/helpers/check_comp
blob: 58d61cdc8212755a79a2706f3a41e3be7d7d1c8d (plain)
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
59
60
#!/usr/bin/env perl
use strict;
use warnings;
use 5.012;

my ($file) = @ARGV;
my $in_arguments = 0;

open( my $fh, '<', $file ) or die("Cannot open $file: $!\n");

while ( my $line = <$fh> ) {
	chomp $line;

	if ( $line =~ m{ ^ [[:space:]]+ _arguments }x ) {
		$in_arguments = 1;
		next;
	}
	if ( not $in_arguments ) {
		next;
	}

	check_line($line);

	if ( not( $line =~ m{ \\ $ }x ) ) {
		$in_arguments = 0;
	}
}

close($fh);

sub check_line {
	my ($line) = @_;

	my $re_pair = qr{
		^ [[:space:]]+ '
		\( (?<ex_one> \S+) \s (?<ex_two> \S+) (?: \s [^)]+ )? \) '
		\{ (?<in_one> \S+) ,  (?<in_two> \S+) (?: ,  [^)]+ )? \} '
	}x;

	$line =~ $re_pair or return;

	my @ex = @+{qw{ex_one ex_two}};
	my @in = @+{qw{in_one in_two}};

	for my $param (@ex) {
		if ( not( $param ~~ \@in ) ) {
			printf( "Possible typo: %s not included in {%s,%s}\n", $param,
				@in );
		}
	}

	for my $param (@in) {
		if ( not( $param ~~ \@ex ) ) {
			printf( "Possible typo: %s not included in (%s %s)\n", $param,
				@ex );
		}
	}

	return;
}