line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2011-2012 Yuki Izumi. ( anneli AT cpan DOT org ) |
2
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the |
3
|
|
|
|
|
|
|
# same terms as Perl itself. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Erlang::Parser::Node::Try; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
12
|
use Moose; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
17
|
|
8
|
|
|
|
|
|
|
with 'Erlang::Parser::Node'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'exprs' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node]'); |
11
|
|
|
|
|
|
|
has 'of' => (is => 'rw', required => 0, isa => 'Maybe[ArrayRef[Erlang::Parser::Node::Alt]]'); |
12
|
|
|
|
|
|
|
has 'catch' => (is => 'rw', required => 0, isa => 'Maybe[ArrayRef[Erlang::Parser::Node::Alt]]'); |
13
|
|
|
|
|
|
|
has 'aft' => (is => 'rw', required => 0, isa => 'Maybe[ArrayRef[Erlang::Parser::Node]]'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub print { |
16
|
62
|
|
|
62
|
1
|
93
|
my ($self, $fh, $depth) = @_; |
17
|
62
|
|
50
|
|
|
116
|
$depth ||= 0; |
18
|
|
|
|
|
|
|
|
19
|
62
|
|
|
|
|
94
|
print $fh "try\n"; |
20
|
|
|
|
|
|
|
|
21
|
62
|
|
|
|
|
58
|
$depth++; |
22
|
62
|
|
|
|
|
109
|
print $fh "\t" x $depth; |
23
|
|
|
|
|
|
|
|
24
|
62
|
|
|
|
|
67
|
my $first = 1; |
25
|
62
|
|
|
|
|
71
|
foreach (@{$self->exprs}) { |
|
62
|
|
|
|
|
1578
|
|
26
|
90
|
100
|
|
|
|
145
|
if ($first) { $first = 0 } else { print $fh ",\n", "\t" x $depth } |
|
62
|
|
|
|
|
83
|
|
|
28
|
|
|
|
|
46
|
|
27
|
90
|
|
|
|
|
253
|
$_->print($fh, $depth); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
62
|
|
|
|
|
64
|
$depth--; |
31
|
62
|
|
|
|
|
114
|
print $fh "\n", "\t" x $depth; |
32
|
|
|
|
|
|
|
|
33
|
62
|
100
|
66
|
|
|
1571
|
if (defined $self->of and @{$self->of}) { |
|
2
|
|
|
|
|
48
|
|
34
|
2
|
|
|
|
|
5
|
print $fh "of\n"; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
3
|
$depth++; |
37
|
2
|
|
|
|
|
5
|
print $fh "\t" x $depth; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
4
|
my $first = 1; |
40
|
2
|
|
|
|
|
3
|
foreach (@{$self->of}) { |
|
2
|
|
|
|
|
44
|
|
41
|
4
|
100
|
|
|
|
7
|
if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth } |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
7
|
|
42
|
4
|
|
|
|
|
11
|
$_->print($fh, $depth); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
4
|
$depth--; |
46
|
2
|
|
|
|
|
5
|
print $fh "\n", "\t" x $depth; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
62
|
100
|
66
|
|
|
1454
|
if (defined $self->catch and @{$self->catch}) { |
|
52
|
|
|
|
|
1101
|
|
50
|
52
|
|
|
|
|
111
|
print $fh "catch\n"; |
51
|
|
|
|
|
|
|
|
52
|
52
|
|
|
|
|
68
|
$depth++; |
53
|
52
|
|
|
|
|
89
|
print $fh "\t" x $depth; |
54
|
|
|
|
|
|
|
|
55
|
52
|
|
|
|
|
63
|
my $first = 1; |
56
|
52
|
|
|
|
|
55
|
foreach (@{$self->catch}) { |
|
52
|
|
|
|
|
1171
|
|
57
|
52
|
50
|
|
|
|
81
|
if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth } |
|
52
|
|
|
|
|
84
|
|
|
0
|
|
|
|
|
0
|
|
58
|
52
|
|
|
|
|
189
|
$_->print($fh, $depth); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
52
|
|
|
|
|
51
|
$depth--; |
62
|
52
|
|
|
|
|
95
|
print $fh "\n", "\t" x $depth; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
62
|
100
|
66
|
|
|
1459
|
if (defined $self->aft and @{$self->aft}) { |
|
10
|
|
|
|
|
233
|
|
66
|
10
|
|
|
|
|
31
|
print $fh "after\n"; |
67
|
|
|
|
|
|
|
|
68
|
10
|
|
|
|
|
11
|
$depth++; |
69
|
10
|
|
|
|
|
24
|
print $fh "\t" x $depth; |
70
|
|
|
|
|
|
|
|
71
|
10
|
|
|
|
|
11
|
my $first = 1; |
72
|
10
|
|
|
|
|
19
|
foreach (@{$self->aft}) { |
|
10
|
|
|
|
|
226
|
|
73
|
10
|
50
|
|
|
|
20
|
if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth } |
|
10
|
|
|
|
|
17
|
|
|
0
|
|
|
|
|
0
|
|
74
|
10
|
|
|
|
|
44
|
$_->print($fh, $depth); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
10
|
|
|
|
|
16
|
$depth--; |
78
|
10
|
|
|
|
|
26
|
print $fh "\n", "\t" x $depth; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
62
|
|
|
|
|
180
|
print $fh "end"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Erlang::Parser::Node::Try - a try/catch clause |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
A clause to catch exceptions. A block of expressions is evaluated; the last |
93
|
|
|
|
|
|
|
expression's value is optionally then matched against patterns and guards, and |
94
|
|
|
|
|
|
|
then a further block of statements executed. Exceptions raised therein can be |
95
|
|
|
|
|
|
|
caught in the catch clause. Finally, cleanup statements can be invoked. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 Accessors |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item C<exprs> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
A list of L<Erlang::Parser::Node>s; the last expression's value is that used in |
104
|
|
|
|
|
|
|
the of clause. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item C<of> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
An optional list of L<Erlang::Parser::Node::Alt>s against which the last |
109
|
|
|
|
|
|
|
expression in C<exprs> is matched. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item C<catch> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
An optional list of L<Erlang::Parser::Node::Alt>s for exceptions raised during |
114
|
|
|
|
|
|
|
evaluation in C<exprs> and C<of>. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item C<aft> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
An optional list of L<Erlang::Parser::Node>s, executed after all previous |
119
|
|
|
|
|
|
|
statements. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 Methods |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=over 4 |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item C<print> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Pretty-prints the node to its filehandle argument. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 EXAMPLE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
try |
136
|
|
|
|
|
|
|
{ok, X} = my_fun(), |
137
|
|
|
|
|
|
|
binary_to_term(X) |
138
|
|
|
|
|
|
|
catch |
139
|
|
|
|
|
|
|
throw:Term -> Term |
140
|
|
|
|
|
|
|
after |
141
|
|
|
|
|
|
|
file:close(F) |
142
|
|
|
|
|
|
|
end |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# vim: set sw=4 ts=4: |