line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::EBNF;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
38321
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
663
|
use Parse::EBNF::Rule;
|
|
1
|
|
|
|
|
75
|
|
|
1
|
|
|
|
|
494
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 1.04;
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new {
|
9
|
1
|
|
|
1
|
1
|
1559
|
my ($class) = @_;
|
10
|
1
|
|
|
|
|
5
|
my $self = bless {}, $class;
|
11
|
1
|
|
|
|
|
8
|
$self->{verbose} = 0;
|
12
|
1
|
|
|
|
|
4
|
$self->{rules} = {};
|
13
|
1
|
|
|
|
|
4
|
return $self;
|
14
|
|
|
|
|
|
|
}
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub parse_lines {
|
17
|
0
|
|
|
0
|
1
|
|
my ($self, $lines) = @_;
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#
|
20
|
|
|
|
|
|
|
# split into rules
|
21
|
|
|
|
|
|
|
#
|
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my @rules;
|
24
|
|
|
|
|
|
|
my $current;
|
25
|
0
|
|
|
|
|
|
while(my $line = shift @{$lines}){
|
|
0
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if ($line =~ /^\s*\[\d+\]/){
|
27
|
0
|
|
|
|
|
|
push @rules, $current;
|
28
|
0
|
|
|
|
|
|
$current = '';
|
29
|
|
|
|
|
|
|
}
|
30
|
0
|
|
|
|
|
|
$line =~ s![\r\n\t]! !g;
|
31
|
0
|
|
|
|
|
|
$line =~ s!\s{2,}! !g;
|
32
|
0
|
|
|
|
|
|
$current .= $line;
|
33
|
|
|
|
|
|
|
}
|
34
|
0
|
|
|
|
|
|
push @rules, $current;
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#
|
38
|
|
|
|
|
|
|
# create rules
|
39
|
|
|
|
|
|
|
#
|
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
for my $rule(@rules){
|
42
|
0
|
0
|
|
|
|
|
if (defined($rule)){
|
43
|
0
|
|
|
|
|
|
my $rule_obj = Parse::EBNF::Rule->new($rule);
|
44
|
0
|
|
|
|
|
|
$self->{rules}->{$rule_obj->{name}} = $rule_obj;
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
}
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub rules {
|
50
|
0
|
|
|
0
|
1
|
|
my ($self) = @_;
|
51
|
0
|
|
|
|
|
|
return $self->{rules};
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub dump_rule {
|
55
|
0
|
|
|
0
|
1
|
|
my ($self, $rule) = @_;
|
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
unless ( defined $self->{rules}->{$rule} ){
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
print "rule $rule not found\n";
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
}else{
|
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
1
|
|
6359
|
use Data::Dumper;
|
|
1
|
|
|
|
|
26058
|
|
|
1
|
|
|
|
|
689
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $obj = $self->{rules}->{$rule};
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $d = Data::Dumper->new([$obj]);
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
print $d->Dump();
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub dump_rules {
|
74
|
0
|
|
|
0
|
1
|
|
my ($self) = @_;
|
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
|
12
|
use Data::Dumper;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
551
|
|
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $d = Data::Dumper->new([$self->{rules}]);
|
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
print $d->Dump();
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1;
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__
|