line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Highlife::Rule::Optional; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
4
|
use base qw(Parse::Highlife::Rule); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
5
|
1
|
|
|
1
|
|
5
|
use Parse::Highlife::Utils qw(params); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
6
|
1
|
|
|
1
|
|
5
|
use Data::Dump qw(dump); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
255
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new |
9
|
|
|
|
|
|
|
{ |
10
|
0
|
|
|
0
|
0
|
|
my( $class, @args ) = @_; |
11
|
0
|
|
|
|
|
|
my $self = bless Parse::Highlife::Rule->new( @args ), $class; |
12
|
0
|
|
|
|
|
|
return $self -> _init( @args ); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _init |
16
|
|
|
|
|
|
|
{ |
17
|
0
|
|
|
0
|
|
|
my( $self, $optional ) |
18
|
|
|
|
|
|
|
= params( \@_, |
19
|
|
|
|
|
|
|
-optional => '', |
20
|
|
|
|
|
|
|
); |
21
|
0
|
|
|
|
|
|
$self->{'optional'} = $optional; |
22
|
0
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub parse_from_token |
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
0
|
0
|
|
my( $self, $parser, $tokens, $t ) = @_; |
28
|
|
|
|
|
|
|
# - turn list of subrules into a single SEQ() rule |
29
|
|
|
|
|
|
|
# - try to parse SEQ() rule |
30
|
|
|
|
|
|
|
# - on success: return result, else return failure |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $subrule = $parser->get_rule( $self->{'optional'} ); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $_t = $t; |
35
|
0
|
|
|
|
|
|
my ($_status, $_result); |
36
|
0
|
|
|
|
|
|
($_t) = $self->_parse_ignored_tokens( $tokens, $_t ); |
37
|
0
|
|
|
|
|
|
($_status, $_t, $_result) = $subrule->wrap_parse_from_token( $parser, $tokens, $_t ); |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if( $_status ) { |
40
|
|
|
|
|
|
|
return ( |
41
|
0
|
|
|
|
|
|
1, |
42
|
|
|
|
|
|
|
$_t, |
43
|
|
|
|
|
|
|
$parser->make_ast_element('group', $self->{'name'}, [ $_result ]) |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
return ( |
47
|
0
|
|
|
|
|
|
1, |
48
|
|
|
|
|
|
|
$t, |
49
|
|
|
|
|
|
|
$parser->make_ast_element('group', $self->{'name'}, []) |
50
|
|
|
|
|
|
|
); # always succeeds, since its optional |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |