| 1 | package Parse::EBNF; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Parse::EBNF::Rule; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = 1.04; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 9 | 1 | my ($class) = @_; | |||||||||
| 10 | 1 | my $self = bless {}, $class; | |||||||||
| 11 | 1 | $self->{verbose} = 0; | |||||||||
| 12 | 1 | $self->{rules} = {}; | |||||||||
| 13 | 1 | return $self; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub parse_lines { | ||||||||
|
Subroutine
parse_lines: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 17 | 0 | 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}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | ▶ | if ($line =~ /^\s*\[\d+\]/){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if (defined($rule)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | my $rule_obj = Parse::EBNF::Rule->new($rule); | |||||||||
| 44 | 0 | $self->{rules}->{$rule_obj->{name}} = $rule_obj; | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub rules { | ||||||||
|
Subroutine
rules: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 50 | 0 | my ($self) = @_; | |||||||||
| 51 | 0 | return $self->{rules}; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub dump_rule { | ||||||||
|
Subroutine
dump_rule: not called CC=2 SCAR=12.6
Pod
documented
| |||||||||||
| 55 | 0 | my ($self, $rule) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | unless ( defined $self->{rules}->{$rule} ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | |||||||||||
| 59 | 0 | print "rule $rule not found\n"; | |||||||||
| 60 | |||||||||||
| 61 | }else{ | ||||||||||
| 62 | |||||||||||
| 63 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 0 | ▶ | sub dump_rules { | ||||||||
|
Subroutine
dump_rules: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||
| 74 | 0 | my ($self) = @_; | |||||||||
| 75 | |||||||||||
| 76 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 77 | |||||||||||
| 78 | 0 | my $d = Data::Dumper->new([$self->{rules}]); | |||||||||
| 79 | |||||||||||
| 80 | 0 | print $d->Dump(); | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 1 | 1; | |||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||