| 1 | package Pegex::Parser; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 18 | ▶ | use Pegex::Base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 18 | ▶ | no warnings qw( recursion ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use Pegex::Input; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 18 | ▶ | use Pegex::Optimizer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 18 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 18 | has grammar => (required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 18 | has receiver => (); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 18 | has input => (); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 18 | has recursion_count => 0; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 18 | has iteration_count => 0; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 18 | has debug => (); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 18 | has debug_indent => (); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 18 | has debug_color => (); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 18 | has debug_got_color => (); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 18 | has debug_not_color => (); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 18 | has recursion_limit => (); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 18 | has recursion_warn_limit => (); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 18 | has iteration_limit => (); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 289 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=36 SCAR=47.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 289 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 289 | ▶ | $self->{throw_on_error} ||= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"throw_on_error"} ||= 1
MC/DC0%0/1
$self->{"throw_on_error"} ||= 1
$self->{"throw_on_error"}
Truth table50%1/2
A
A= $self->{"throw_on_error"}
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | $self->{debug} = | ||||||||||||||||||||||||||||||||||||||||||
| 32 | defined($ENV{PERL_PEGEX_DEBUG}) ? $ENV{PERL_PEGEX_DEBUG} : | ||||||||||||||||||||||||||||||||||||||||||
| 33 | defined($Pegex::Parser::Debug) ? $Pegex::Parser::Debug : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 289 | ▶ | unless defined($self->{debug}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | $self->{debug_indent} = | ||||||||||||||||||||||||||||||||||||||||||
| 37 | defined($ENV{PERL_PEGEX_DEBUG_INDENT}) ? $ENV{PERL_PEGEX_DEBUG_INDENT} : | ||||||||||||||||||||||||||||||||||||||||||
| 38 | defined($Pegex::Parser::DebugIndent) ? $Pegex::Parser::DebugIndent : 1 | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 289 | ▶ | unless defined($self->{debug_indent}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | $self->{debug_indent} = 1 if ( | ||||||||||||||||||||||||||||||||||||||||||
| 41 | not length $self->{debug_indent} | ||||||||||||||||||||||||||||||||||||||||||
| 42 | or $self->{debug_indent} =~ tr/0-9//c | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 289 | ▶ | or $self->{debug_indent} < 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not length $self->{"debug_indent"} or $self->{"debug_indent"} =~ tr/0-9//c or $self->{"debug_indent"} < 0
not length $self->{"debug_indent"} or $self->{"debug_indent"} =~ tr/0-9//c
MC/DC0%0/3
not length $self->{"debug_indent"} or $self->{"debug_indent"} =~ tr/0-9//c or $self->{"debug_indent"} < 0
not length $self->{"debug_indent"}
$self->{"debug_indent"} =~ tr/0-9//c
$self->{"debug_indent"} < 0
Truth table25%1/4
not(A) or B or C
A= not length $self->{"debug_indent"}B= $self->{"debug_indent"} =~ tr/0-9//cC= $self->{"debug_indent"} < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 289 | ▶ | if ($self->{debug}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | $self->{debug_color} = | ||||||||||||||||||||||||||||||||||||||||||
| 48 | defined($ENV{PERL_PEGEX_DEBUG_COLOR}) ? $ENV{PERL_PEGEX_DEBUG_COLOR} : | ||||||||||||||||||||||||||||||||||||||||||
| 49 | defined($Pegex::Parser::DebugColor) ? $Pegex::Parser::DebugColor : 1 | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | unless defined($self->{debug_color}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | my ($got, $not); | |||||||||||||||||||||||||||||||||||||||||
| 52 | ($self->{debug_color}, $got, $not) = | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | split / *, */, $self->{debug_color}; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | $got ||= 'bright_green'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$got ||= "bright_green"
MC/DC0%0/1
$got ||= "bright_green"
$got
Truth table50%1/2
A
A= $got
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | $not ||= 'bright_red'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$not ||= "bright_red"
MC/DC0%0/1
$not ||= "bright_red"
$not
Truth table50%1/2
A
A= $not
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | $_ = [split ' ', $_] for ($got, $not); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | $self->{debug_got_color} = $got; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | $self->{debug_not_color} = $not; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | my $c = defined($self->{debug_color}) ? $self->{debug_color} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | $self->{debug_color} = | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | $c eq 'always' ? 1 : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | $c eq 'auto' ? (-t STDERR ? 1 : 0) : | ||||||||||||||||||||||||||||||||||||||||||
| 63 | $c eq 'never' ? 0 : | ||||||||||||||||||||||||||||||||||||||||||
| 64 | $c =~ /^\d+$/ ? $c : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | if ($self->{debug_color}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | require Term::ANSIColor; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | if ($Term::ANSIColor::VERSION < 3.00) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | s/^bright_// for | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | @{$self->{debug_got_color}}, | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | @{$self->{debug_not_color}}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | $self->{recursion_limit} = | ||||||||||||||||||||||||||||||||||||||||||
| 75 | defined($ENV{PERL_PEGEX_RECURSION_LIMIT}) ? $ENV{PERL_PEGEX_RECURSION_LIMIT} : | ||||||||||||||||||||||||||||||||||||||||||
| 76 | defined($Pegex::Parser::RecursionLimit) ? $Pegex::Parser::RecursionLimit : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 289 | ▶ | unless defined($self->{recursion_limit}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | $self->{recursion_warn_limit} = | ||||||||||||||||||||||||||||||||||||||||||
| 79 | defined($ENV{PERL_PEGEX_RECURSION_WARN_LIMIT}) ? $ENV{PERL_PEGEX_RECURSION_WARN_LIMIT} : | ||||||||||||||||||||||||||||||||||||||||||
| 80 | defined($Pegex::Parser::RecursionWarnLimit) ? $Pegex::Parser::RecursionWarnLimit : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 289 | ▶ | unless defined($self->{recursion_warn_limit}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | $self->{iteration_limit} = | ||||||||||||||||||||||||||||||||||||||||||
| 83 | defined($ENV{PERL_PEGEX_ITERATION_LIMIT}) ? $ENV{PERL_PEGEX_ITERATION_LIMIT} : | ||||||||||||||||||||||||||||||||||||||||||
| 84 | defined($Pegex::Parser::IterationLimit) ? $Pegex::Parser::IterationLimit : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 289 | ▶ | unless defined($self->{iteration_limit}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # XXX Add an optional $position argument. Default to 0. This is the position | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # to start parsing. Set position and farthest below to this value. Allows for | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # sub-parsing. Need to somehow return the finishing position of a subparse. | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # Maybe this all goes in a subparse() method. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 287 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=17 SCAR=30.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 287 | my ($self, $input, $start) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 287 | ▶ | $start =~ s/-/_/g if $start; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 287 | $self->{position} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 287 | $self->{farthest} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 287 | ▶ | $self->{input} = (not ref $input) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | ? Pegex::Input->new(string => $input) | ||||||||||||||||||||||||||||||||||||||||||
| 102 | : $input; | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | $self->{input}->open | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 287 | ▶ | unless $self->{input}{_is_open}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 287 | $self->{buffer} = $self->{input}->read; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 287 | $self->{last_line_pos} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 287 | $self->{last_line} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 287 | ▶ | $self->{grammar}{tree} ||= $self->{grammar}->make_tree; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"grammar"}{"tree"} ||= $self->{"grammar"}->make_tree
MC/DC0%0/2
$self->{"grammar"}{"tree"} ||= $self->{"grammar"}->make_tree
$self->{"grammar"}{"tree"}
$self->{"grammar"}->make_tree
Truth table66%2/3
A ||= B
A= $self->{"grammar"}{"tree"}B= $self->{"grammar"}->make_tree
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | my $start_rule_ref = $start || | ||||||||||||||||||||||||||||||||||||||||||
| 113 | $self->{grammar}{tree}{'+toprule'} || | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 273 | ▶ | $self->{grammar}{tree}{'TOP'} & 'TOP' or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$start || $self->{'grammar'}{'tree'}{'+toprule'} || $self->{'grammar'}{'tree'}{'TOP'} & 'TOP'
$start or $self->{"grammar"}{"tree"}{"+toprule"}
MC/DC0%0/3
$start || $self->{'grammar'}{'tree'}{'+toprule'} || $self->{'grammar'}{'tree'}{'TOP'} & 'TOP'
$start
$self->{"grammar"}{"tree"}{"+toprule"}
$self->{'grammar'}{'tree'}{'TOP'} & 'TOP'
Truth table25%1/4
A or B || C
A= $startB= $self->{"grammar"}{"tree"}{"+toprule"}C= $self->{'grammar'}{'tree'}{'TOP'} & 'TOP'
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | die "No starting rule for Pegex::Parser::parse"; | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | die "No 'receiver'. Can't parse" | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 273 | ▶ | unless $self->{receiver}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | my $optimizer = Pegex::Optimizer->new( | ||||||||||||||||||||||||||||||||||||||||||
| 121 | parser => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | grammar => $self->{grammar}, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | receiver => $self->{receiver}, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 273 | ); | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 273 | $optimizer->optimize_grammar($start_rule_ref); | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # Add circular ref and weaken it. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 273 | $self->{receiver}{parser} = $self; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 273 | Scalar::Util::weaken($self->{receiver}{parser}); | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 273 | ▶ | if ($self->{receiver}->can("initial")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->{rule} = $start_rule_ref; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $self->{parent} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $self->{receiver}->initial(); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 273 | local *match_next; | |||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 18 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | *match_next = ( | ||||||||||||||||||||||||||||||||||||||||||
| 142 | $self->{recursion_warn_limit} or | ||||||||||||||||||||||||||||||||||||||||||
| 143 | $self->{recursion_limit} or | ||||||||||||||||||||||||||||||||||||||||||
| 144 | $self->{iteration_limit} | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 273 | ▶ | ) ? \&match_next_with_limit : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->{"recursion_warn_limit"} or $self->{"recursion_limit"} or $self->{"iteration_limit"}
$self->{"recursion_warn_limit"} or $self->{"recursion_limit"}
MC/DC0%0/3
$self->{"recursion_warn_limit"} or $self->{"recursion_limit"} or $self->{"iteration_limit"}
$self->{"recursion_warn_limit"}
$self->{"recursion_limit"}
$self->{"iteration_limit"}
Truth table25%1/4
A or B or C
A= $self->{"recursion_warn_limit"}B= $self->{"recursion_limit"}C= $self->{"iteration_limit"}
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | \&match_next_normal; | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 273 | ▶ | my $match = $self->debug ? do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | my $method = $optimizer->make_trace_wrapper(\&match_ref); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $self->$method($start_rule_ref, {'+asr' => 0}); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } : $self->match_ref($start_rule_ref, {}); | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 259 | $self->{input}->close; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 259 | ▶ | if (not $match or $self->{position} < length ${$self->{buffer}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $match or $self->{"position"} < length ${$self->{"buffer"};}
MC/DC100%2/2
not $match or $self->{"position"} < length ${$self->{"buffer"};}
not $match
$self->{"position"} < length ${$self->{"buffer"};}
Truth table100%3/3
not(A) or B
A= not $matchB= $self->{"position"} < length ${$self->{"buffer"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | $self->throw_error("Parse document failed for some reason"); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | return; # In case $self->throw_on_error is off | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 257 | ▶ | if ($self->{receiver}->can("final")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 255 | $self->{rule} = $start_rule_ref; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 255 | $self->{parent} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 255 | $match = [ $self->{receiver}->final(@$match) ]; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 257 | $match->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 41558 | ▶ | sub match_next_normal { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_next_normal: called CC=17 SCAR=28.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 41558 | my ($self, $next) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | my ($rule, $method, $kind, $min, $max, $assertion) = | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 41558 | @{$next}{'rule', 'method', 'kind', '+min', '+max', '+asr'}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | my ($position, $match, $count) = | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 41558 | ($self->{position}, [], 0); | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 41558 | ▶ | while (my $return = $method->($self, $rule, $next)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 15949 | ▶ | $position = $self->{position} unless $assertion; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 15949 | $count++; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 15949 | push @$match, @$return; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 15949 | ▶ | last if $max == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 41388 | ▶ | if (not $count and $min == 0 and $kind eq 'all') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $count and $min == 0 and $kind eq "all"
not $count and $min == 0
MC/DC100%3/3
not $count and $min == 0 and $kind eq "all"
not $count
$min == 0
$kind eq "all"
Truth table100%4/4
not(A) and B and C
A= not $countB= $min == 0C= $kind eq "all"
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 1443 | $match = [[]]; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 41388 | ▶ | if ($max != 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 1633 | ▶ | if ($next->{-flat}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 34 | ▶ | $match = [ map { (ref($_) eq 'ARRAY') ? (@$_) : ($_) } @$match ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 1599 | $match = [$match] | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 41388 | ▶ | my $result = ($count >= $min and (not $max or $count <= $max)) | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$count >= $min && (!$max || $count <= $max)
not $max or $count <= $max
MC/DC33%1/3
$count >= $min && (!$max || $count <= $max)
$count >= $min
not $max
$count <= $max
Truth table75%3/4
A && not(B) or C
A= $count >= $minB= not $maxC= $count <= $max
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | ^ ($assertion == -1); | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 41388 | ▶ | if (not($result) or $assertion) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $result or $assertion
MC/DC100%2/2
not $result or $assertion
not $result
$assertion
Truth table100%3/3
not(A) or B
A= not $resultB= $assertion
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | $self->{farthest} = $position | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 24039 | ▶ | if ($self->{position} = $position) > $self->{farthest}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 41388 | ▶ | ($result ? $next->{'-skip'} ? [] : $match : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | sub match_next_with_limit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_next_with_limit: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my ($self, $next) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub limit_msg { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
limit_msg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | "Deep recursion ($_[0] levels) on Pegex::Parser::match_next\n"; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $self->{iteration_count}++; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $self->{recursion_count}++; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$self->{"recursion_limit"} and $self->{"recursion_count"} >= $self->{"recursion_limit"}
MC/DC0%0/2
$self->{"recursion_limit"} and $self->{"recursion_count"} >= $self->{"recursion_limit"}
$self->{"recursion_limit"}
$self->{"recursion_count"} >= $self->{"recursion_limit"}
Truth table0%0/3
A and B
A= $self->{"recursion_limit"}B= $self->{"recursion_count"} >= $self->{"recursion_limit"}
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | $self->{recursion_limit} and | ||||||||||||||||||||||||||||||||||||||||||
| 218 | $self->{recursion_count} >= $self->{recursion_limit} | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ) { die limit_msg $self->{recursion_count} } | |||||||||||||||||||||||||||||||||||||||||
| 220 | ▶ | elsif ( | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"recursion_warn_limit"} and not $self->{"recursion_count"} % $self->{"recursion_warn_limit"}
MC/DC0%0/2
$self->{"recursion_warn_limit"} and not $self->{"recursion_count"} % $self->{"recursion_warn_limit"}
$self->{"recursion_warn_limit"}
not $self->{"recursion_count"} % $self->{"recursion_warn_limit"}
Truth table0%0/3
A and not(B)
A= $self->{"recursion_warn_limit"}B= not $self->{"recursion_count"} % $self->{"recursion_warn_limit"}
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | $self->{recursion_warn_limit} and | ||||||||||||||||||||||||||||||||||||||||||
| 222 | not ($self->{recursion_count} % $self->{recursion_warn_limit}) | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ) { warn limit_msg $self->{recursion_count} } | |||||||||||||||||||||||||||||||||||||||||
| 224 | ▶ | elsif ( | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"iteration_limit"} and $self->{"iteration_count"} > $self->{"iteration_limit"}
MC/DC0%0/2
$self->{"iteration_limit"} and $self->{"iteration_count"} > $self->{"iteration_limit"}
$self->{"iteration_limit"}
$self->{"iteration_count"} > $self->{"iteration_limit"}
Truth table0%0/3
A and B
A= $self->{"iteration_limit"}B= $self->{"iteration_count"} > $self->{"iteration_limit"}
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | $self->{iteration_limit} and | ||||||||||||||||||||||||||||||||||||||||||
| 226 | $self->{iteration_count} > $self->{iteration_limit} | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ) { die "Pegex iteration limit of $self->{iteration_limit} reached." } | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $result = $self->match_next_normal($next); | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->{recursion_count}--; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | ▶ | sub match_rule { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_rule: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | my ($self, $position, $match) = (@_, []); | |||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | $self->{position} = $position; | |||||||||||||||||||||||||||||||||||||||||
| 239 | $self->{farthest} = $position | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | ▶ | if $position > $self->{farthest}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | ▶ | $match = [ $match ] if @$match > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | my ($ref, $parent) = @{$self}{'rule', 'parent'}; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | ▶ | my $rule = $self->{grammar}{tree}{$ref} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | or die "No rule defined for '$ref'"; | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | [ $rule->{action}->($self->{receiver}, @$match) ]; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 17470 | ▶ | sub match_ref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_ref: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 17470 | my ($self, $ref, $parent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 17470 | ▶ | my $rule = $self->{grammar}{tree}{$ref} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | or die "No rule defined for '$ref'"; | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 17470 | ▶ | my $match = $self->match_next($rule) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 6942 | ▶ | return $Pegex::Constant::Dummy unless $rule->{action}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 6919 | @{$self}{'rule', 'parent'} = ($ref, $parent); | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | # XXX Possible API mismatch. | ||||||||||||||||||||||||||||||||||||||||||
| 258 | # Not sure if we should "splat" the $match. | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 6919 | [ $rule->{action}->($self->{receiver}, @$match) ]; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 15041 | ▶ | sub match_rgx { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_rgx: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 15041 | my ($self, $regexp) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 15041 | my $buffer = $self->{buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 15041 | pos($$buffer) = $self->{position}; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 15041 | ▶ | $$buffer =~ /$regexp/g or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 4640 | $self->{position} = pos($$buffer); | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | $self->{farthest} = $self->{position} | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 4640 | ▶ | if $self->{position} > $self->{farthest}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 18 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 4640 | my $captures = [ map $$_, 1..$#+ ]; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 4640 | ▶ | $captures = [ $captures ] if $#+ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 4640 | return $captures; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 7434 | ▶ | sub match_all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_all: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 7434 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 7434 | my $position = $self->{position}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 7434 | my $set = []; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 7434 | my $len = 0; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 7434 | for my $elem (@$list) { | |||||||||||||||||||||||||||||||||||||||||
| 287 | 13242 | ▶ | if (my $match = $self->match_next($elem)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 8699 | ▶ | if (not ($elem->{'+asr'} or $elem->{'-skip'})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$elem->{"+asr"} or $elem->{"-skip"}
MC/DC100%2/2
$elem->{"+asr"} or $elem->{"-skip"}
$elem->{"+asr"}
$elem->{"-skip"}
Truth table100%3/3
A or B
A= $elem->{"+asr"}B= $elem->{"-skip"}
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 8666 | push @$set, @$match; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 8666 | $len++; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | $self->{farthest} = $position | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 4486 | ▶ | if ($self->{position} = $position) > $self->{farthest}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 4486 | return; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 2891 | ▶ | $set = [ $set ] if $len > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 2891 | return $set; | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 2974 | ▶ | sub match_any { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_any: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 2974 | my ($self, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 2974 | for my $elem (@$list) { | |||||||||||||||||||||||||||||||||||||||||
| 306 | 10846 | ▶ | if (my $match = $self->match_next($elem)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 1733 | return $match; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 1199 | return; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 14 | ▶ | sub match_err { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_err: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 14 | my ($self, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 14 | $self->throw_error($error); | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 46 | ▶ | sub trace { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trace: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 46 | my ($self, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 46 | ▶ | my $indent = ($action =~ /^try_/) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 46 | ▶ | $self->{indent} ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"indent"} ||= 0
MC/DC100%1/1
$self->{"indent"} ||= 0
$self->{"indent"}
Truth table100%2/2
A
A= $self->{"indent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 46 | ▶ | $self->{indent}-- unless $indent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | $action = ( | ||||||||||||||||||||||||||||||||||||||||||
| 325 | $action =~ m/got_/ ? | ||||||||||||||||||||||||||||||||||||||||||
| 326 | Term::ANSIColor::colored($self->{debug_got_color}, $action) : | ||||||||||||||||||||||||||||||||||||||||||
| 327 | $action =~ m/not_/ ? | ||||||||||||||||||||||||||||||||||||||||||
| 328 | Term::ANSIColor::colored($self->{debug_not_color}, $action) : | ||||||||||||||||||||||||||||||||||||||||||
| 329 | $action | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 46 | ▶ | ) if $self->{debug_color}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 46 | print STDERR ' ' x ($self->{indent} * $self->{debug_indent}); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 46 | ▶ | $self->{indent}++ if $indent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 46 | my $snippet = substr(${$self->{buffer}}, $self->{position}); | |||||||||||||||||||||||||||||||||||||||||
| 335 | 46 | ▶ | $snippet = substr($snippet, 0, 30) . "..." | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | if length $snippet > 30; | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 46 | $snippet =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 46 | ▶ | print STDERR sprintf("%-30s", $action) . | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | ($indent ? " >$snippet<\n" : "\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 16 | ▶ | sub throw_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw_error: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 16 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 16 | $@ = $self->{error} = $self->format_error($msg); | |||||||||||||||||||||||||||||||||||||||||
| 345 | 16 | ▶ | return undef unless $self->{throw_on_error}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 16 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 16 | Carp::croak($self->{error}); | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 16 | ▶ | sub format_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_error: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 16 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 16 | my $buffer = $self->{buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 16 | my $position = $self->{farthest}; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 16 | my $real_pos = $self->{position}; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 16 | my $line = $self->line($position); | |||||||||||||||||||||||||||||||||||||||||
| 357 | 16 | my $column = $position - rindex($$buffer, "\n", $position); | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 16 | ▶ | my $pretext = substr( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | $$buffer, | ||||||||||||||||||||||||||||||||||||||||||
| 361 | $position < 50 ? 0 : $position - 50, | ||||||||||||||||||||||||||||||||||||||||||
| 362 | $position < 50 ? $position : 50 | ||||||||||||||||||||||||||||||||||||||||||
| 363 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 16 | my $context = substr($$buffer, $position, 50); | |||||||||||||||||||||||||||||||||||||||||
| 365 | 16 | $pretext =~ s/.*\n//gs; | |||||||||||||||||||||||||||||||||||||||||
| 366 | 16 | $context =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 16 | return <<"..."; | |||||||||||||||||||||||||||||||||||||||||
| 369 | Error parsing Pegex document: | ||||||||||||||||||||||||||||||||||||||||||
| 370 | msg: $msg | ||||||||||||||||||||||||||||||||||||||||||
| 371 | line: $line | ||||||||||||||||||||||||||||||||||||||||||
| 372 | column: $column | ||||||||||||||||||||||||||||||||||||||||||
| 373 | context: $pretext$context | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 16 | ${\ (' ' x (length($pretext) + 10) . '^')} | |||||||||||||||||||||||||||||||||||||||||
| 375 | position: $position ($real_pos pre-lookahead) | ||||||||||||||||||||||||||||||||||||||||||
| 376 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # TODO Move this to a Parser helper role/subclass | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | sub line_column { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line_column: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my ($self, $position) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | $position ||= $self->{position}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$position ||= $self->{"position"}
MC/DC0%0/2
$position ||= $self->{"position"}
$position
$self->{"position"}
Truth table0%0/3
A ||= B
A= $positionB= $self->{"position"}
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my $buffer = $self->{buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $line = $self->line($position); | |||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $column = $position - rindex($$buffer, "\n", $position); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | return [$line, $column]; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 16 | ▶ | sub line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 16 | my ($self, $position) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 16 | ▶ | $position ||= $self->{position}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$position ||= $self->{"position"}
MC/DC50%1/2
$position ||= $self->{"position"}
$position
$self->{"position"}
Truth table66%2/3
A ||= B
A= $positionB= $self->{"position"}
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 16 | my $buffer = $self->{buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 16 | my $last_line = $self->{last_line}; | |||||||||||||||||||||||||||||||||||||||||
| 394 | 16 | my $last_line_pos = $self->{last_line_pos}; | |||||||||||||||||||||||||||||||||||||||||
| 395 | 16 | my $len = $position - $last_line_pos; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 16 | ▶ | if ($len == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | return $last_line; | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 15 | my $line; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 15 | ▶ | if ($len < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $line = $last_line - scalar substr($$buffer, $position, -$len) =~ tr/\n//; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 15 | $line = $last_line + scalar substr($$buffer, $last_line_pos, $len) =~ tr/\n//; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 15 | $self->{last_line} = $line; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 15 | $self->{last_line_pos} = $position; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 15 | return $line; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | # XXX Need to figure out what uses this. (sample.t) | ||||||||||||||||||||||||||||||||||||||||||
| 411 | { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 18 | package Pegex::Constant; | |||||||||||||||||||||||||||||||||||||||||
| 413 | 18 | our $Null = []; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 18 | our $Dummy = []; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 18 | 1; | |||||||||||||||||||||||||||||||||||||||||