line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Node -- generic parse tree node ("abstract class")
|
2
|
|
|
|
|
|
|
# lineno (scalar): corresponding line number in source code (for debugging)
|
3
|
|
|
|
|
|
|
package Text::PORE::Node;
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
870
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
1
|
|
30
|
use Exporter;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@Text::PORE::Node::ISA = qw(Exporter);
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$Text::PORE::Node::debug = 0;
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
657
|
use Text::PORE::Node::Attr;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
13
|
1
|
|
|
1
|
|
789
|
use Text::PORE::Node::Container;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
14
|
1
|
|
|
1
|
|
696
|
use Text::PORE::Node::Freetext;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
15
|
1
|
|
|
1
|
|
675
|
use Text::PORE::Node::If;
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
49
|
|
16
|
1
|
|
|
1
|
|
802
|
use Text::PORE::Node::Standalone;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
17
|
1
|
|
|
1
|
|
715
|
use Text::PORE::Node::Queue;
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
730
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new {
|
20
|
146
|
|
|
146
|
0
|
236
|
my $type = shift;
|
21
|
146
|
|
|
|
|
267
|
my $lineno = shift;
|
22
|
|
|
|
|
|
|
|
23
|
146
|
|
|
|
|
201
|
my ($self) = { };
|
24
|
|
|
|
|
|
|
|
25
|
146
|
|
66
|
|
|
486
|
bless $self, ref($type) || $type;
|
26
|
|
|
|
|
|
|
|
27
|
146
|
|
|
|
|
327
|
$self->setLineNo($lineno);
|
28
|
|
|
|
|
|
|
|
29
|
146
|
|
|
|
|
273
|
$self->{'errors'} = [ ];
|
30
|
|
|
|
|
|
|
|
31
|
146
|
|
|
|
|
783
|
$self;
|
32
|
|
|
|
|
|
|
}
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub setLineNo {
|
35
|
146
|
|
|
146
|
0
|
151
|
my $self = shift;
|
36
|
146
|
|
|
|
|
149
|
my $lineno = shift;
|
37
|
|
|
|
|
|
|
|
38
|
146
|
|
|
|
|
399
|
$self->{'lineno'} = $lineno;
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# a 'final' method
|
42
|
|
|
|
|
|
|
sub setDebug {
|
43
|
0
|
|
|
0
|
0
|
0
|
my $self = shift;
|
44
|
0
|
|
|
|
|
0
|
my $value = shift;
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
$Node::debug = $value;
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# a 'final' method
|
50
|
|
|
|
|
|
|
sub getDebug {
|
51
|
328
|
|
|
328
|
0
|
410
|
my $self = shift;
|
52
|
|
|
|
|
|
|
|
53
|
328
|
|
|
|
|
962
|
$Node::debug;
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# a 'final' method
|
57
|
|
|
|
|
|
|
sub setOutput {
|
58
|
6
|
|
|
6
|
0
|
10
|
my $self = shift;
|
59
|
6
|
|
|
|
|
13
|
my $output = shift;
|
60
|
|
|
|
|
|
|
|
61
|
6
|
|
|
|
|
15
|
$Node::output = $output;
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# a 'final' method
|
65
|
|
|
|
|
|
|
sub output {
|
66
|
128
|
|
|
128
|
0
|
272
|
my $self = shift;
|
67
|
128
|
|
|
|
|
138
|
my $output = shift;
|
68
|
|
|
|
|
|
|
|
69
|
128
|
|
|
|
|
378
|
$Node::output->print($output);
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# A "virtual" method
|
74
|
|
|
|
|
|
|
sub traverse {
|
75
|
0
|
|
|
0
|
0
|
0
|
my $self = shift;
|
76
|
0
|
|
|
|
|
0
|
my $context = shift;
|
77
|
0
|
|
|
|
|
0
|
my $globals = shift;
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# need to return an empty list of error messages
|
80
|
0
|
|
|
|
|
0
|
[ ];
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub error {
|
84
|
205
|
|
|
205
|
0
|
275
|
my $self = shift;
|
85
|
205
|
|
|
|
|
430
|
my $text = join('',@_); # not always needed, but it's easy enough to do
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# push onto the error list; if it's an array ref, push the array,
|
88
|
|
|
|
|
|
|
# else push the string prepended by the line number
|
89
|
|
|
|
|
|
|
# note - we would rather just use push, but it won't work on anon arrays
|
90
|
205
|
|
|
|
|
527
|
$self->{'errors'} =
|
91
|
|
|
|
|
|
|
[
|
92
|
205
|
|
|
|
|
917
|
@{$self->{'errors'}} ,
|
93
|
205
|
50
|
|
|
|
223
|
(ref $_[0] eq 'ARRAY' ? @{$_[0]} : "$self->{'lineno'}: $text\n"),
|
94
|
|
|
|
|
|
|
];
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub errorDump {
|
98
|
211
|
|
|
211
|
0
|
248
|
my $self = shift;
|
99
|
|
|
|
|
|
|
|
100
|
211
|
|
|
|
|
280
|
my $errors = $self->{'errors'};
|
101
|
|
|
|
|
|
|
|
102
|
211
|
|
|
|
|
313
|
$self->{'errors'} = [ ];
|
103
|
|
|
|
|
|
|
|
104
|
211
|
|
|
|
|
635
|
$errors;
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub retrieveSlot {
|
108
|
80
|
|
|
80
|
0
|
92
|
my $self = shift; # operating node
|
109
|
80
|
|
|
|
|
84
|
my $globals = shift; # global objects to assist in lookup
|
110
|
80
|
|
|
|
|
138
|
my $slot = shift; # name of slot to lookup
|
111
|
|
|
|
|
|
|
|
112
|
80
|
|
|
|
|
290
|
my ($lineno) = $self->{'lineno'};
|
113
|
80
|
|
|
|
|
150
|
my ($obj);
|
114
|
|
|
|
|
|
|
my (@attr_list);
|
115
|
|
|
|
|
|
|
|
116
|
80
|
100
|
|
|
|
159
|
unless (defined($slot)) {
|
117
|
28
|
|
|
|
|
85
|
return undef;
|
118
|
|
|
|
|
|
|
}
|
119
|
|
|
|
|
|
|
|
120
|
52
|
|
|
|
|
129
|
@attr_list = split(/\./, $slot);
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# if it's explicitly a global object, start from there,
|
123
|
|
|
|
|
|
|
# else default to _context
|
124
|
52
|
50
|
|
|
|
117
|
if ($attr_list[0] =~ m/^_/) {
|
125
|
0
|
|
|
|
|
0
|
$obj = $globals->GetAttribute($attr_list[0]);
|
126
|
0
|
0
|
|
|
|
0
|
unless (ref($obj)) {
|
127
|
0
|
|
|
|
|
0
|
$self->error("'$attr_list[0] is not a defined global object");
|
128
|
0
|
|
|
|
|
0
|
return undef;
|
129
|
|
|
|
|
|
|
}
|
130
|
0
|
|
|
|
|
0
|
shift @attr_list;
|
131
|
|
|
|
|
|
|
} else {
|
132
|
52
|
|
|
|
|
175
|
$obj = $globals->GetAttribute('_context');
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Get attribute by parsing dot-notation
|
136
|
52
|
|
|
|
|
112
|
while (@attr_list) {
|
137
|
52
|
|
|
|
|
72
|
my $attr = shift @attr_list;
|
138
|
|
|
|
|
|
|
|
139
|
52
|
50
|
33
|
|
|
362
|
if (! ref($obj) || ref($obj) =~ /(ARRAY|HASH)/) {
|
140
|
0
|
|
|
|
|
0
|
$self->error("Attempt to take attribute '$attr' from non-object");
|
141
|
0
|
|
|
|
|
0
|
return "";
|
142
|
|
|
|
|
|
|
}
|
143
|
|
|
|
|
|
|
|
144
|
52
|
|
|
|
|
138
|
$obj = $obj->GetAttribute($attr);
|
145
|
|
|
|
|
|
|
}
|
146
|
|
|
|
|
|
|
|
147
|
52
|
|
|
|
|
149
|
return $obj;
|
148
|
|
|
|
|
|
|
}
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1;
|