-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
gen_keywords.pl
71 lines (54 loc) · 1.42 KB
/
gen_keywords.pl
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
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl -w
# original source: https://gist.github.com/don/5748655
# Run this from the Arduino library directory to generate keywords.txt
# Optionally pass the name of the library as the first argument
# $ gen_keywords.pl Foo > keywords.txt
use strict;
use File::Find::Rule qw( );
my $in_public = 0;
my %class;
my %func;
my $curr_class;
my @h_files = File::Find::Rule->name('*.h')->in("src");
print <<EOF;
#######################################
# Syntax Coloring Map For Arduino_GFX
#######################################
EOF
for my $header (@h_files) {
open(my $fh, $header) or die "Couldn't open $header: $!";
while (<$fh>) {
if (/^class (\w+)/) {
$class{$1}++;
$curr_class = $1;
}
if (/public:/) {
$in_public = 1;
}
if ($in_public) {
if (/private:/ || /};/) {
$in_public = 0;
} elsif (/(\w+)\(/) {
if ($1 ne $curr_class) {
$func{$1}++;
}
}
}
}
}
print <<EOF;
#######################################
# Datatypes (KEYWORD1)
#######################################
EOF
foreach (sort keys %class) {
print "$_ KEYWORD1\n";
}
print <<EOF;
#######################################
# Methods and Functions (KEYWORD2)
#######################################
EOF
foreach (sort keys %func) {
print "$_ KEYWORD2\n";
}