aboutsummaryrefslogtreecommitdiffstats
path: root/docs/buildsig2.pl
blob: b1c7268d0e4c7023c567f076e3bc5a15f76ae5ea (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env perl

use strict;
use warnings;
#use Pod::Simple::Debug (3);
use Data::Dumper;
use Pod::Simple::SimpleTree;
use Carp qw/croak/;
$|++;

#package Pod::Simple::Tree;


#package main;

my $input_file = $ARGV[0] // 'General/Signals.pod';
my $parser = Pod::Simple::SimpleTree->new;

$parser->accept_targets('irssi_signal_defs', 'irssi_signal_types');
my $root = $parser->parse_file($input_file)->root;

#print Dumper($root);
my @sig_tree;

my $in_list = 0;
foreach my $node (get_children($root)) {
    #print name($node), "\n";

    if (name($node) eq 'for') {

        if (attr($node)->{target} eq 'irssi_signal_defs') {
            print "Found For\n";
            my $text = text(get_children($node));

            if ($text =~ /START OF SIGNAL DEFINITIONS/) {
                print "start of defs\n";
                $in_list = 1;
                next;
            } elsif ($text =~ /END OF SIGNAL DEFINITIONS/) {
                print "end of defs\n";
                $in_list = 0;
                next;
            }
        }

    }
    push @sig_tree, $node if $in_list;

}
# we've got what we came for
undef $root;
undef $parser;

my $module = '';
my $file = '';


print Dumper(\@sig_tree), "\n\n";

foreach my $node (@sig_tree) {
    my $name = name($node);

    if ($name eq 'head2') {
        $module = text($node);
        print "Module: $module\n";
    } elsif ($name eq 'head3') {
        $file = text(get_children($node));
        print "File: $file\n";
    } elsif ($name eq 'over-text') {
        my @children = get_children($node);
        while (@children) {

            # fetch in pairs $sig => $parameter list
            my ($signal, $params) = (shift @children, shift @children);
            print "Signal: ", Dumper($signal), $/;
            print "Params: ", Dumper($params), $/;

            my $sig_name = text(get_children($signal));

            print "Sig: $sig_name\n";

            my @param_list = get_children($params);
            foreach my $param (@param_list) {
                $param = get_children($param);
                print "Param: ", Dumper($param), "\n";
                my $type = '';
                my $var = '';
                if (!ref $param->[0]) {
                    $type = $param->[0];
                    my @param_array = @$param;
                    foreach my $thing (@param_array) {
                        $var = text($thing);
                        last if $var =~ m/\$\w+/;
                    }
                } elsif (name($param->[0]) eq 'B') {
                    # skip
                    next;
                } elsif (name($param->[0]) eq 'L') {
                    $type = text($param->[0]);
                    #$var = text($param->[1]);
                    my @param_array = @$param;
                    foreach my $thing (@param_array) {
                        $var = text($thing);
                        last if $var =~ m/\$\w+/;
                    }
                } else {
                    $var = text($param->[0]);
                }
                $type =~ s/\s*(\w+)\s*/$1/;
                $var  =~ s/\s*(\w+)\s*/$1/;

                print "Type: $type, Var: >$var<\n";
            }
        }
    }
}

sub attr {
    my $node = shift;
    return $node->[1];
}
sub name {
    my $node = shift;
    return $node->[0];
}

sub text {
    my $node = shift;
    my $text = ref $node ? $node->[2] : '' ;
    croak("text() called on non-terminal: " . Dumper($node)) if ref($text);
    return $text;
}

sub get_children {
    my $node = shift;

    my @node_arr = ref $node ? @$node : ();
    my @child_slice = @node_arr[2..$#node_arr];
    return wantarray ? @child_slice : \@child_slice;
}