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::Case; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
13
|
use Moose; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
20
|
|
8
|
|
|
|
|
|
|
with 'Erlang::Parser::Node'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'of' => (is => 'rw', required => 1, isa => 'Erlang::Parser::Node'); |
11
|
|
|
|
|
|
|
has 'alts' => (is => 'rw', required => 1, isa => 'ArrayRef[Erlang::Parser::Node::Alt]'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub print { |
14
|
496
|
|
|
496
|
1
|
674
|
my ($self, $fh, $depth) = @_; |
15
|
496
|
|
100
|
|
|
900
|
$depth ||= 0; |
16
|
|
|
|
|
|
|
|
17
|
496
|
|
|
|
|
652
|
print $fh 'case '; |
18
|
496
|
|
|
|
|
11663
|
$self->of->print($fh, $depth); |
19
|
496
|
|
|
|
|
594
|
print $fh " of\n"; |
20
|
|
|
|
|
|
|
|
21
|
496
|
|
|
|
|
468
|
$depth++; |
22
|
|
|
|
|
|
|
|
23
|
496
|
|
|
|
|
892
|
print $fh "\t" x $depth; |
24
|
|
|
|
|
|
|
|
25
|
496
|
|
|
|
|
514
|
my $first = 1; |
26
|
496
|
|
|
|
|
435
|
foreach (@{$self->alts}) { |
|
496
|
|
|
|
|
11921
|
|
27
|
1280
|
100
|
|
|
|
1624
|
if ($first) { $first = 0 } else { print $fh ";\n", "\t" x $depth } |
|
496
|
|
|
|
|
505
|
|
|
784
|
|
|
|
|
1167
|
|
28
|
1280
|
|
|
|
|
3367
|
$_->print($fh, $depth); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
496
|
|
|
|
|
441
|
$depth--; |
32
|
496
|
|
|
|
|
1605
|
print $fh "\n", "\t" x $depth, "end"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Erlang::Parser::Node::Case - a case expression |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
An expression which tries several different pattern matches and guards. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 Accessors |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=over 4 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item C<of> |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
An L<Erlang::Parser::Node> which is evaluated to be matched against C<alts>. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item C<alts> |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
A list of L<Erlang::Parser::Node::Alt>s which are tried against C<of> in turn. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 Methods |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item C<print> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Pretty-prints the node to its filehandle argument. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=back |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 EXAMPLE |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
case ?MODULE:myfun() of |
72
|
|
|
|
|
|
|
{X, Y} -> |
73
|
|
|
|
|
|
|
io:format("I'm a tuple! ~p, ~p~n", [X, Y]); |
74
|
|
|
|
|
|
|
[X, Y] = Z -> |
75
|
|
|
|
|
|
|
io:format("I'm a list! ~p, ~p~n", Z) |
76
|
|
|
|
|
|
|
end |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# vim: set sw=4 ts=4: |