| 1 | package Parse::EBNF::Rule; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Parse::EBNF::Token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | my ($class, $rule) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | $self->{error} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | $self->parse($rule) if defined $rule; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 22 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=26 SCAR=34.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 22 | my ($self, $rule) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 22 | $self->{error} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # strip comments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 22 | $rule =~ s!/\*([^\*]|\*[^\/])*\*\/!!g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 22 | ▶ | unless ($rule =~ m!^\s*\[(\d+)\]\s*([A-Z][a-zA-Z]*)\s*\:\:=!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | $self->{error} = "can't parse rule $rule"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 20 | $self->{index} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 20 | $self->{name} = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 20 | $rule =~ s!^(.*?)\:\:=!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 20 | $self->{rule} = $rule; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # now try and tokenise the rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # we first tokenise it, and *then* split it into alternations, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # since finding the pipes will be tricky if they occur inside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # literals or character classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 20 | my $tokens = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 20 | $rule =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 20 | ▶ | while($rule){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 32 | my $token = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 32 | ▶ | if ($rule =~ m!^'([^']+)'!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 13 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | $token->{content} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | $token->{type} = 'literal'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | $rule = substr $rule, 2 + length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | }elsif ($rule =~ m!^"([^"]+)"!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | $token->{content} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | $token->{type} = 'literal'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $rule = substr $rule, 2 + length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | }elsif ($rule =~ m!^\|!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | $token->{type} = 'alt'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | $rule = substr $rule, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | }elsif ($rule =~ m!^([A-Z][a-zA-Z]*)!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 12 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 12 | $token->{content} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 12 | $token->{type} = 'subrule'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | $rule = substr $rule, length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | }elsif ($rule =~ m!^\[(\^?)(([^\]]|\\\])+)\]!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # some sort of class - sub-parse it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | my $neg = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | my $inner = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | $rule = substr $rule, 2 + length($neg) + length($inner); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 8 | my $rx = '['.$neg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | ▶ | while(length $inner){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 18 | ▶ | if ($inner =~ m!^#x([0-9a-f]+)-#x([0-9a-f]+)!i){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | $inner = substr $inner, 5 + length($1) + length($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | $rx .= $self->hexchar($1).'-'.$self->hexchar($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | }elsif ($inner =~ m!^#x([0-9a-f]+)!i){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | $inner = substr $inner, 2 + length($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 6 | $rx .= $self->hexchar($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | }elsif ($inner =~ m!^([^-])-([^-])!i){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | $inner = substr $inner, 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | $rx .= quotemeta($1).'-'.quotemeta($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | }elsif ($inner =~ m!^([^-])!i){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | $inner = substr $inner, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | $rx .= quotemeta($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->{error} = "couldn't parse class rx at $inner"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 8 | $rx .= ']'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | $token->{content} = $rx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | $token->{type} = 'rx'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | }elsif ($rule =~ m!^\[(([^\]]|\\\])+)\]!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $token->{content} = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $token->{type} = 'class'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $rule = substr $rule, 2 + length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | }elsif ($rule =~ m!^\*!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | $token->{type} = 'rep star'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | $rule = substr $rule, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | }elsif ($rule =~ m!^\+!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | $token->{type} = 'rep plus'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | $rule = substr $rule, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | }elsif ($rule =~ m!^\?!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | $token->{type} = 'rep quest'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | $rule = substr $rule, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | }elsif ($rule =~ m!^\(!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $token->{type} = 'group start'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $rule = substr $rule, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | }elsif ($rule =~ m!^\)!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | $token->{type} = 'group end'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | $rule = substr $rule, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | }elsif ($rule =~ m!^\-!){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $token->{type} = 'dash'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $rule = substr $rule, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | }elsif ($rule =~ m!^#x([0-9a-f]+)!i){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | $token = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | $token->{content} = $self->hexchar($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | $token->{type} = 'rx'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | $rule = substr $rule, 2 + length $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $self->{error} = "couldn't parse token at start of $rule"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 32 | push @{$tokens}, $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 32 | $rule =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # first we create a base token (of type list) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # which will represent a list of tokens for this rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 20 | my $base = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 20 | $base->{type} = 'list'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 20 | $base->{tokens} = $tokens; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 20 | $self->{base} = $base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # now we create a node tree from the flat list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 20 | ▶ | return unless $self->produce_groups($base); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # and perform recursive cleanups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 20 | ▶ | unless ($base->reduce_alternations()){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $self->{error} = $base->{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 20 | ▶ | unless ($base->reduce_repetition()){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->{error} = $base->{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # TODO: negations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 20 | ▶ | unless ($base->reduce_empty()){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $self->{error} = $base->{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 20 | ▶ | unless ($base->reduce_rx()){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $self->{error} = $base->{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 11 | ▶ | sub hexchar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hexchar: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 11 | my ($self, $char) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 11 | $char =~ s!^0+!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 11 | ▶ | if (hex($char) > 255){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | return '\\x{'.lc($char).'}'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 11 | return '\\x'.lc($char); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 20 | ▶ | sub produce_groups { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
produce_groups: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 20 | my ($self, $base) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 20 | my $tokens = $base->{tokens}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 20 | $base->{tokens} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 20 | my $current = $base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 20 | ▶ | while(my $token = shift @{$tokens}){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 32 | ▶ | if ($token->{type} eq 'group start'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | my $parent = Parse::EBNF::Token->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | $parent->{type} = 'list'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | $parent->{parent} = $current; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | $parent->{tokens} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | push @{$current->{tokens}}, $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | $current = $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | }elsif ($token->{type} eq 'group end'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | $current = $current->{parent}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | ▶ | if (!defined($current)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $self->{error} = "end of group found without matching begin in rule $self->{rule}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 30 | push @{$current->{tokens}}, $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 21 | ▶ | sub has_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_error: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 21 | ▶ | return $self->{error} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | return $self->{error} ? $self->{error} : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 54 | ▶ | sub base_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 54 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 54 | return $self->{base}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||