File Coverage

blib/lib/Pugs/Compiler/Grammar.pm
Criterion Covered Total %
statement 18 30 60.0
branch 0 2 0.0
condition 1 2 50.0
subroutine 6 7 85.7
pod 2 2 100.0
total 27 43 62.7


line stmt bran cond sub pod time code
1 1     1   644 use strict;
  1         2  
  1         35  
2 1     1   5 use warnings;
  1         2  
  1         59  
3             #use Smart::Comments;
4              
5             package Pugs::Compiler::Grammar;
6              
7             our $VERSION = '0.28';
8              
9 1     1   660 use Pugs::Grammar::Rule;
  1         3  
  1         54  
10 1     1   739 use Pugs::Emitter::Grammar::Perl5;
  1         4  
  1         40  
11 1     1   13 use Carp qw(carp croak);
  1         3  
  1         298  
12              
13             sub compile {
14 1     1 1 15 my ($class, $src, $opts) = @_;
15 1   50     10 $opts ||= {};
16 1         13 my $match = Pugs::Grammar::Rule->spec($src);
17 0 0         if ($match->bool) {
18             ## $match
19 0           my $capture = $match->();
20 0           my $leading_block = $capture->{block};
21             ### leading block: $leading_block
22 0           my $ast = $capture->{grammar};
23             ## $ast
24 0           my $perl5;
25 0           for my $g (@$ast) {
26             ### Grammar found...
27 0           $g = $g->();
28 0           my ($name) = keys %$g;
29             ### Grammar: $name
30 0           $perl5 .= Pugs::Emitter::Grammar::Perl5::emit($g, $opts);
31             }
32             bless {
33 0           source => $src,
34             ast => $ast,
35             perl5 => $perl5,
36             }, $class;
37             } else {
38 0           carp "Failed to compile the grammar source";
39             }
40             }
41              
42             sub perl5 {
43 0     0 1   $_[0]->{perl5};
44             }
45              
46             1;
47             __END__