line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Highlife::AST; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
5
|
use Parse::Highlife::Utils qw(params); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
801
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $ASTElementCounter = 0; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new |
9
|
|
|
|
|
|
|
{ |
10
|
0
|
|
|
0
|
0
|
|
my( $class, @args ) = @_; |
11
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
12
|
0
|
|
|
|
|
|
return $self -> _init( @args ); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _init |
16
|
|
|
|
|
|
|
{ |
17
|
0
|
|
|
0
|
|
|
my( $self, $category, $rulename, $value ) = @_; |
18
|
0
|
|
|
|
|
|
$ASTElementCounter ++; |
19
|
0
|
|
|
|
|
|
$self->{'category'} = $category; |
20
|
0
|
|
|
|
|
|
$self->{'id'} = $ASTElementCounter; |
21
|
0
|
|
|
|
|
|
$self->{'children'} = $value; |
22
|
0
|
|
|
|
|
|
$self->{'parent'} = undef; |
23
|
0
|
|
|
|
|
|
$self->{'parent-id'} = 0; |
24
|
0
|
|
|
|
|
|
$self->{'rulename'} = $rulename; |
25
|
0
|
|
|
|
|
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# returns the first leaf value |
29
|
|
|
|
|
|
|
sub value |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
32
|
0
|
|
|
|
|
|
my @values = $self->values(); |
33
|
0
|
0
|
|
|
|
|
return ( scalar @values ? $values[0] : '' ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# returns all leaf values |
37
|
|
|
|
|
|
|
sub values |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
40
|
0
|
|
|
|
|
|
my @values; |
41
|
0
|
0
|
|
|
|
|
if( $self->{'category'} eq 'leaf' ) { |
42
|
0
|
|
|
|
|
|
push @values, $self->{'children'}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { # group |
45
|
0
|
|
|
|
|
|
map { push @values, $_->values() } @{$self->{'children'}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
return @values; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub has_ancestor |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
0
|
0
|
|
my( $self, $rulename ) = @_; |
53
|
0
|
|
|
|
|
|
return ref $self->ancestor( $rulename ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub ancestor |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
0
|
0
|
|
my( $self, $rulename ) = @_; |
59
|
0
|
|
|
|
|
|
my @asts = $self->ancestors( $rulename ); |
60
|
0
|
0
|
|
|
|
|
return scalar @asts ? $asts[0] : 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub ancestors |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
0
|
0
|
|
my( $self, $rulename ) = @_; |
66
|
0
|
0
|
|
|
|
|
if( $self->{'rulename'} eq $rulename ) { |
|
|
0
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return ($self); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
elsif( $self->{'category'} eq 'group' ) { |
70
|
0
|
|
|
|
|
|
return map { $_->ancestors( $rulename ) } @{$self->{'children'}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
return (); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub nth_child |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
0
|
0
|
|
my( $self, $n ) = @_; |
78
|
0
|
0
|
|
|
|
|
if( $self->{'category'} eq 'group' ) { |
|
|
0
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if( scalar @{$self->{'children'}} >= $n ) { |
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return $self->{'children'}->[$n-1]; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif( $self->{'category'} eq 'leaf' ) { |
87
|
0
|
|
|
|
|
|
return $self->{'children'}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub children |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
94
|
0
|
0
|
|
|
|
|
if( $self->{'category'} eq 'group' ) { |
95
|
0
|
|
|
|
|
|
return @{$self->{'children'}}; |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
return (); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub first_child |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
103
|
0
|
|
|
|
|
|
return $self->nth_child(1); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub second_child |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
109
|
0
|
|
|
|
|
|
return $self->nth_child(2); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub third_child |
113
|
|
|
|
|
|
|
{ |
114
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
115
|
0
|
|
|
|
|
|
return $self->nth_child(3); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |