File Coverage

inc/TestML/Compiler/Pegex.pm
Criterion Covered Total %
statement 34 34 100.0
branch 5 10 50.0
condition n/a
subroutine 7 7 100.0
pod 0 3 0.0
total 46 54 85.1


line stmt bran cond sub pod time code
1             package TestML::Compiler::Pegex;
2              
3 3     3   15 use TestML::Base;
  3         6  
  3         19  
4             extends 'TestML::Compiler';
5              
6 3     3   1401 use TestML::Compiler::Pegex::Grammar;
  3         11  
  3         32  
7 3     3   1341 use TestML::Compiler::Pegex::AST;
  3         11  
  3         91  
8 3     3   17 use Pegex::Parser;
  3         6  
  3         1234  
9              
10             has parser => ();
11              
12             sub compile_code {
13 3     3 0 8 my ($self) = @_;
14              
15 3         29 $self->{parser} = Pegex::Parser->new(
16             grammar => TestML::Compiler::Pegex::Grammar->new,
17             receiver => TestML::Compiler::Pegex::AST->new,
18             );
19 3         235 $self->fixup_grammar;
20              
21 3 50       22 $self->parser->parse($self->code, 'code_section')
22             or die "Parse TestML code section failed";
23             }
24              
25             sub compile_data {
26 3     3 0 7 my ($self) = @_;
27              
28 3 50       30 if (length $self->data) {
29 3 50       16 $self->parser->parse($self->data, 'data_section')
30             or die "Parse TestML data section failed";
31             }
32              
33 3         149 $self->{function} = $self->parser->receiver->function;
34             }
35              
36             # TODO This can be moved to the AST some day.
37             sub fixup_grammar {
38 3     3 0 6 my ($self) = @_;
39              
40 3         19 my $tree = $self->{parser}->grammar->tree;
41              
42 3         27 my $point_lines = $tree->{point_lines}{'.rgx'};
43              
44 3         14 my $block_marker = $self->directives->{BlockMarker};
45 3 50       12 if ($block_marker) {
46 3         11 $block_marker =~ s/([\$\%\^\*\+\?\|])/\\$1/g;
47 3         71 $tree->{block_marker}{'.rgx'} = qr/\G$block_marker/;
48 3         30 $point_lines =~ s/===/$block_marker/;
49             }
50              
51 3         13 my $point_marker = $self->directives->{PointMarker};
52 3 50       27 if ($point_marker) {
53 3         7 $point_marker =~ s/([\$\%\^\*\+\?\|])/\\$1/g;
54 3         41 $tree->{point_marker}{'.rgx'} = qr/\G$point_marker/;
55 3         13 $point_lines =~ s/\\-\\-\\-/$point_marker/;
56             }
57              
58 3         149 $tree->{point_lines}{'.rgx'} = qr/$point_lines/;
59             }
60              
61             1;