line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Highlife::Rule::Choice; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
7
|
use base qw(Parse::Highlife::Rule); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
74
|
|
5
|
1
|
|
|
1
|
|
7
|
use Parse::Highlife::Utils qw(params); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
356
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new |
8
|
|
|
|
|
|
|
{ |
9
|
0
|
|
|
0
|
0
|
|
my( $class, @args ) = @_; |
10
|
0
|
|
|
|
|
|
my $self = bless Parse::Highlife::Rule->new( @args ), $class; |
11
|
0
|
|
|
|
|
|
return $self -> _init( @args ); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _init |
15
|
|
|
|
|
|
|
{ |
16
|
0
|
|
|
0
|
|
|
my( $self, $choice ) |
17
|
|
|
|
|
|
|
= params( \@_, |
18
|
|
|
|
|
|
|
-choice => [], |
19
|
|
|
|
|
|
|
); |
20
|
0
|
|
|
|
|
|
$self->{'choice'} = $choice; |
21
|
0
|
|
|
|
|
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub parse_from_token |
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
0
|
0
|
|
my( $self, $parser, $tokens, $t ) = @_; |
27
|
0
|
0
|
|
|
|
|
return (0,0,0) if $t >= scalar(@{$tokens}); |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# - try to parse one sub-rule after another |
30
|
|
|
|
|
|
|
# - return result on first success |
31
|
|
|
|
|
|
|
# - if no success: return failure |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $_t; |
34
|
0
|
|
|
|
|
|
my ($_status, $_result); |
35
|
0
|
|
|
|
|
|
foreach my $subrulename (@{$self->{'choice'}}) { |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $subrule = $parser->get_rule( $subrulename ); |
37
|
0
|
|
|
|
|
|
$_t = $t; |
38
|
0
|
|
|
|
|
|
($_t) = $self->_parse_ignored_tokens( $tokens, $_t ); |
39
|
0
|
|
|
|
|
|
($_status, $_t, $_result) = $subrule->wrap_parse_from_token( $parser, $tokens, $_t ); |
40
|
0
|
0
|
|
|
|
|
last if $_status; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if( $_status ) { |
44
|
|
|
|
|
|
|
return ( |
45
|
0
|
|
|
|
|
|
1, |
46
|
|
|
|
|
|
|
$_t, |
47
|
|
|
|
|
|
|
$parser->make_ast_element('group', $self->{'name'}, [ $_result ]) |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
return (0,0,0); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |