line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Highlife::Rule; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use Parse::Highlife::Utils qw(params); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
5
|
1
|
|
|
1
|
|
6
|
use Data::Dump qw(dump); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
648
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new |
8
|
|
|
|
|
|
|
{ |
9
|
0
|
|
|
0
|
0
|
|
my( $class, @args ) = @_; |
10
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
11
|
0
|
|
|
|
|
|
return $self -> _init( @args ); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _init |
15
|
|
|
|
|
|
|
{ |
16
|
0
|
|
|
0
|
|
|
my( $self, $name ) |
17
|
|
|
|
|
|
|
= params( \@_, |
18
|
|
|
|
|
|
|
-name => '', |
19
|
|
|
|
|
|
|
); |
20
|
0
|
|
|
|
|
|
$self->{'name'} = $name; |
21
|
0
|
|
|
|
|
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# abstract |
25
|
0
|
|
|
0
|
0
|
|
sub parse_from_token { return (0,0,0) } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub wrap_parse_from_token |
28
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
0
|
0
|
|
my( $self, $parser, $tokens, $t ) = @_; |
30
|
|
|
|
|
|
|
#return (0,0,0) if $t >= scalar(@{$tokens}); |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if( $parser->{'debug'} ) { |
33
|
0
|
|
|
|
|
|
my $classname = ref $self; |
34
|
0
|
|
|
|
|
|
$classname =~ s/^.*\://g; |
35
|
0
|
|
|
|
|
|
my $_t = $t; |
36
|
0
|
|
|
|
|
|
($_t) = $self->_parse_ignored_tokens( $tokens, $_t ); |
37
|
0
|
0
|
|
|
|
|
print ''.('| ' x $parser->{'current-indent'})."try rule <$self->{name}> as $classname from token #$_t'".($tokens->[$_t] ? $tokens->[$_t]->{'matched-substring'} : '')."'\n"; |
38
|
0
|
|
|
|
|
|
$parser->{'current-indent'} ++; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my @result = $self->parse_from_token( $parser, $tokens, $t ); |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if( $parser->{'debug'} ) { |
44
|
0
|
|
|
|
|
|
$parser->{'current-indent'} --; |
45
|
0
|
0
|
|
|
|
|
print ''.('| ' x $parser->{'current-indent'}).( $result[0] ? "MATCH <$self->{name}>" : '^' )."\n"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
#my $in = ; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $ast = $result[2]; |
50
|
0
|
0
|
0
|
|
|
|
if( ref $ast eq 'HASH' && $ast->{'category'} eq 'group' ) { |
51
|
0
|
|
|
|
|
|
foreach my $child (@{$ast->{'children'}}) { |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$child->{'parent'} = $ast; |
53
|
0
|
|
|
|
|
|
$child->{'parent-id'} = $ast->{'id'}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
return @result; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _parse_ignored_tokens |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
|
|
my( $self, $tokens, $offset ) = @_; |
62
|
0
|
|
|
|
|
|
my $t = $offset; |
63
|
0
|
|
|
|
|
|
while( $t < scalar @{$tokens} ) { |
|
0
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
last unless $tokens->[$t]->{'is-ignored'}; |
65
|
0
|
|
|
|
|
|
$t++; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
return ($t); # t = new offset after parsed stuff |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |