File Coverage

blib/lib/TestML1/Compiler/Pegex.pm
Criterion Covered Total %
statement 34 34 100.0
branch 6 10 60.0
condition n/a
subroutine 7 7 100.0
pod 0 3 0.0
total 47 54 87.0


line stmt bran cond sub pod time code
1             package TestML1::Compiler::Pegex;
2              
3 23     23   48215 use TestML1::Base;
  23         36  
  23         99  
4             extends 'TestML1::Compiler';
5              
6 23     23   7788 use TestML1::Compiler::Pegex::Grammar;
  23         56  
  23         165  
7 23     23   8011 use TestML1::Compiler::Pegex::AST;
  23         51  
  23         567  
8 23     23   7420 use Pegex::Parser;
  23         169919  
  23         7749  
9              
10             has parser => ();
11              
12             sub compile_code {
13 33     33 0 73 my ($self) = @_;
14              
15 33         208 $self->{parser} = Pegex::Parser->new(
16             grammar => TestML1::Compiler::Pegex::Grammar->new,
17             receiver => TestML1::Compiler::Pegex::AST->new,
18             );
19 33         2563 $self->fixup_grammar;
20              
21 33 50       123 $self->parser->parse($self->code, 'code_section')
22             or die "Parse TestML1 code section failed";
23             }
24              
25             sub compile_data {
26 33     33 0 70 my ($self) = @_;
27              
28 33 100       176 if (length $self->data) {
29 22 50       90 $self->parser->parse($self->data, 'data_section')
30             or die "Parse TestML1 data section failed";
31             }
32              
33 33         695 $self->{function} = $self->parser->receiver->function;
34             }
35              
36             # TODO This can be moved to the AST some day.
37             sub fixup_grammar {
38 33     33 0 69 my ($self) = @_;
39              
40 33         135 my $tree = $self->{parser}->grammar->tree;
41              
42 33         118 my $point_lines = $tree->{point_lines}{'.rgx'};
43              
44 33         104 my $block_marker = $self->directives->{BlockMarker};
45 33 50       94 if ($block_marker) {
46 33         95 $block_marker =~ s/([\$\%\^\*\+\?\|])/\\$1/g;
47 33         523 $tree->{block_marker}{'.rgx'} = qr/\G$block_marker/;
48 33         214 $point_lines =~ s/===/$block_marker/;
49             }
50              
51 33         112 my $point_marker = $self->directives->{PointMarker};
52 33 50       85 if ($point_marker) {
53 33         78 $point_marker =~ s/([\$\%\^\*\+\?\|])/\\$1/g;
54 33         225 $tree->{point_marker}{'.rgx'} = qr/\G$point_marker/;
55 33         108 $point_lines =~ s/\\-\\-\\-/$point_marker/;
56             }
57              
58 33         798 $tree->{point_lines}{'.rgx'} = qr/$point_lines/;
59             }
60              
61             1;