line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dallycot::AST; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JSMITH'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Abstract type representing a syntax node |
5
|
|
|
|
|
|
|
|
6
|
23
|
|
|
23
|
|
268794
|
use strict; |
|
23
|
|
|
|
|
41
|
|
|
23
|
|
|
|
|
705
|
|
7
|
23
|
|
|
23
|
|
85
|
use warnings; |
|
23
|
|
|
|
|
35
|
|
|
23
|
|
|
|
|
465
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
76
|
use utf8; |
|
23
|
|
|
|
|
35
|
|
|
23
|
|
|
|
|
102
|
|
10
|
23
|
|
|
23
|
|
818
|
use experimental qw(switch); |
|
23
|
|
|
|
|
2657
|
|
|
23
|
|
|
|
|
167
|
|
11
|
|
|
|
|
|
|
|
12
|
23
|
|
|
23
|
|
2696
|
use Carp qw(croak); |
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
1083
|
|
13
|
23
|
|
|
23
|
|
96
|
use Promises qw(deferred); |
|
23
|
|
|
|
|
29
|
|
|
23
|
|
|
|
|
165
|
|
14
|
23
|
|
|
23
|
|
5547
|
use Scalar::Util qw(blessed); |
|
23
|
|
|
|
|
34
|
|
|
23
|
|
|
|
|
1146
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Module::Pluggable |
17
|
23
|
|
|
|
|
182
|
require => 1, |
18
|
|
|
|
|
|
|
sub_name => '_node_types', |
19
|
23
|
|
|
23
|
|
1098
|
search_path => 'Dallycot::AST'; |
|
23
|
|
|
|
|
11487
|
|
20
|
|
|
|
|
|
|
|
21
|
23
|
|
|
23
|
|
2600
|
use Dallycot::Value; |
|
23
|
|
|
|
|
37
|
|
|
23
|
|
|
|
|
10230
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Dallycot::AST is an abstract class inherited by all of the AST classes: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over 4 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item L<Apply|Dallycot::AST::Apply> |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item L<Assign|Dallycot::AST::Assign> |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item L<BuildFilter|Dallycot::AST::BuildFilter> |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item L<BuildList|Dallycot::AST::BuildList> |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item L<BuildMap|Dallycot::AST::BuildMap> |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item L<BuildRange|Dallycot::AST::BuildRange> |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item L<BuildVector|Dallycot::AST::BuildVector> |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item L<Compose|Dallycot::AST::Compose> |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item L<Defined|Dallycot::AST::Defined> |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item L<Expr|Dallycot::AST::Expr> |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item L<Fetch|Dallycot::AST::Fetch> |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item L<ForwardWalk|Dallycot::AST::ForwardWalk> |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item L<Head|Dallycot::AST::Head> |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item L<Identity|Dallycot::AST::Identity> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item L<Index|Dallycot::AST::Index> |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item L<Invert|Dallycot::AST::Invert> |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item L<Lambda|Dallycot::AST::Lambda> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item L<LibraryFunction|Dallycot::AST::LibraryFunction> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item L<Modulus|Dallycot::AST::Modulus> |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item L<Negation|Dallycot::AST::Negation> |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item L<Placeholder|Dallycot::AST::Placeholder> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item L<Product|Dallycot::AST::Product> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item L<PropertyLit|Dallycot::AST::PropertyLit> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item L<Reciprocal|Dallycot::AST::Reciprocal> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item L<Reduce|Dallycot::AST::Reduce> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item L<Sequence|Dallycot::AST::Sequence> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item L<Sum|Dallycot::AST::Sum> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item L<Tail|Dallycot::AST::Tail> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item L<TypePromotion|Dallycot::AST::TypePromotion> |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item L<Unique|Dallycot::AST::Unique> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item L<Zip|Dallycot::AST::Zip> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Additional base classes inherit from this abstract class as well: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item L<ComparisonBase|Dallycot::AST::ComparisonBase> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The base for the various comparison operations. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=over 4 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item L<Decreasing|Dallycot::AST::Decreasing> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item L<Equality|Dallycot::AST::Equality> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item L<Increasing|Dallycot::AST::Increasing> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item L<StrictlyDecreasing|Dallycot::AST::StrictlyDecreasing> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item L<StrictlyIncreasing|Dallycot::AST::StrictlyIncreasing> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item L<LoopBase|Dallycot::AST::LoopBase> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
The base for operations that loop through a series of options. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over 4 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item L<All|Dallycot::AST::All> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item L<Any|Dallycot::AST::Any> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item L<Condition|Dallycot::AST::Condition> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item L<PropWalk|Dallycot::AST::PropWalk> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# use overload '""' => sub { |
136
|
|
|
|
|
|
|
# shift->to_string |
137
|
|
|
|
|
|
|
# }; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
our @NODE_TYPES; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=func node_types |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns a list of Perl packages that provide AST nodes. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
4
|
|
|
4
|
0
|
16
|
sub is_declarative {return} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub node_types { |
150
|
24
|
100
|
|
24
|
0
|
493
|
return @NODE_TYPES if @NODE_TYPES; |
151
|
23
|
|
|
|
|
83
|
(@NODE_TYPES) = shift->_node_types; |
152
|
23
|
|
|
|
|
156174
|
return @NODE_TYPES; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__PACKAGE__->node_types; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub new { |
158
|
2
|
|
|
2
|
0
|
17
|
my ($class) = @_; |
159
|
|
|
|
|
|
|
|
160
|
2
|
|
66
|
|
|
7
|
$class = ref $class || $class; |
161
|
|
|
|
|
|
|
|
162
|
2
|
|
|
|
|
9
|
return bless [] => $class; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=method simplify |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Simplifies the node and any child nodes. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub simplify { |
172
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
173
|
1
|
|
|
|
|
5
|
return $self; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=method check_for_common_mistakes |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Checks for any odd expressions given their context. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Returns a list of warnings. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub check_for_common_mistakes { |
185
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
186
|
|
|
|
|
|
|
|
187
|
1
|
|
|
|
|
3
|
return map { $_->check_for_common_mistakes } $self->child_nodes; |
|
0
|
|
|
|
|
0
|
|
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=method to_json |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Returns a Perl Hash containing the JSON-LD representation of the node and |
193
|
|
|
|
|
|
|
any child nodes. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub to_json { |
198
|
1
|
|
|
1
|
0
|
348
|
my ($self) = @_; |
199
|
|
|
|
|
|
|
|
200
|
1
|
|
33
|
|
|
167
|
croak "to_json not defined for " . ( blessed($self) || $self ); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=method to_string |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Returns a Perl string containing a pseudo-code representation of the node |
206
|
|
|
|
|
|
|
and any child nodes. This string may not parse. It's intended for debugging |
207
|
|
|
|
|
|
|
purposes. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub to_string { |
212
|
1
|
|
|
1
|
0
|
403
|
my ($self) = @_; |
213
|
|
|
|
|
|
|
|
214
|
1
|
|
33
|
|
|
76
|
croak "to_string not defined for " . ( blessed($self) || $self ); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=method execute($engine) |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Executes the node using the provided engine. Returns a promise. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub execute { |
224
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $engine ) = @_; |
225
|
|
|
|
|
|
|
|
226
|
1
|
|
|
|
|
5
|
my $d = deferred; |
227
|
|
|
|
|
|
|
|
228
|
1
|
|
33
|
|
|
30
|
$d->reject( ( blessed($self) || $self ) . " is not a valid operation" ); |
229
|
|
|
|
|
|
|
|
230
|
1
|
|
|
|
|
59
|
return $d->promise; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=method identifiers |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Returns a list of identifiers referenced in the current environment by this node. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
0
|
0
|
0
|
sub identifiers { return () } |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=method child_nodes |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Returns a list of child nodes. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub child_nodes { |
248
|
2
|
|
|
2
|
0
|
4
|
my ($self) = @_; |
249
|
|
|
|
|
|
|
|
250
|
2
|
50
|
|
|
|
3
|
return grep { blessed($_) && $_->isa(__PACKAGE__) } @{$self}; |
|
1
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
7
|
|
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
1; |