| 1 | package Text::Xslate::Syntax::TTerse; | ||||||||||||||||||||||||||||
| 2 | 103 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 103 | ▶ | use Text::Xslate::Util qw(p any_in); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 103 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 103 | extends qw(Text::Xslate::Parser); | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 121 | ▶ | sub _build_identity_pattern { | ||||||||||||||||||||||||||
|
Subroutine
_build_identity_pattern: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 121 | return qr/(?: [A-Za-z_] [A-Za-z0-9_]* )/xms; | |||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # [% ... %] and %% ... | ||||||||||||||||||||||||||||
| 13 | 121 | ▶ | sub _build_line_start { '%%' } | ||||||||||||||||||||||||||
|
Subroutine
_build_line_start: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 117 | ▶ | sub _build_tag_start { '[%' } | ||||||||||||||||||||||||||
|
Subroutine
_build_tag_start: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 117 | ▶ | sub _build_tag_end { '%]' } | ||||||||||||||||||||||||||
|
Subroutine
_build_tag_end: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1404 | ▶ | around trim_code => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 18 | 1404 | my($super, $self, $code) = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1404 | ▶ | if($code =~ /^\#/) { # multiline comments | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 8 | return ''; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1396 | return $super->($self, $code); | |||||||||||||||||||||||||||
| 25 | 103 | }; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 121 | ▶ | sub init_symbols { | ||||||||||||||||||||||||||
|
Subroutine
init_symbols: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 121 | my($parser) = @_; | |||||||||||||||||||||||||||
| 29 | 121 | my $s; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 121 | $parser->init_basic_operators(); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 121 | $parser->symbol('$')->set_nud(\&nud_dollar); | |||||||||||||||||||||||||||
| 34 | 121 | $parser->make_alias('~' => '_'); | |||||||||||||||||||||||||||
| 35 | 121 | $parser->make_alias('|' => 'FILTER'); | |||||||||||||||||||||||||||
| 36 | 121 | $parser->symbol('.')->set_led(\&led_dot); # redefine | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 121 | $parser->symbol('END') ->is_block_end(1); | |||||||||||||||||||||||||||
| 39 | 121 | $parser->symbol('ELSE') ->is_block_end(1); | |||||||||||||||||||||||||||
| 40 | 121 | $parser->symbol('ELSIF')->is_block_end(1); | |||||||||||||||||||||||||||
| 41 | 121 | $parser->symbol('CASE') ->is_block_end(1); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 121 | $parser->symbol('IN'); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 121 | $s = $parser->symbol('IF'); | |||||||||||||||||||||||||||
| 46 | 121 | $s->set_std(\&std_if); | |||||||||||||||||||||||||||
| 47 | 121 | $s->can_be_modifier(1); | |||||||||||||||||||||||||||
| 48 | 121 | $s = $parser->symbol('UNLESS'); | |||||||||||||||||||||||||||
| 49 | 121 | $s->set_std(\&std_if); | |||||||||||||||||||||||||||
| 50 | 121 | $s->can_be_modifier(1); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 121 | $parser->symbol('FOREACH') ->set_std(\&std_for); | |||||||||||||||||||||||||||
| 53 | 121 | $parser->symbol('FOR') ->set_std(\&std_for); | |||||||||||||||||||||||||||
| 54 | 121 | $parser->symbol('WHILE') ->set_std(\&std_while); | |||||||||||||||||||||||||||
| 55 | 121 | $parser->symbol('SWITCH') ->set_std(\&std_switch); | |||||||||||||||||||||||||||
| 56 | 121 | $parser->symbol('CASE') ->set_std(\&std_case); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 121 | $parser->symbol('INCLUDE') ->set_std(\&std_include); | |||||||||||||||||||||||||||
| 59 | 121 | $parser->symbol('WITH'); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 121 | $parser->symbol('GET') ->set_std(\&std_get); | |||||||||||||||||||||||||||
| 62 | 121 | $parser->symbol('SET') ->set_std(\&std_set); | |||||||||||||||||||||||||||
| 63 | 121 | $parser->symbol('DEFAULT') ->set_std(\&std_set); | |||||||||||||||||||||||||||
| 64 | 121 | $parser->symbol('CALL') ->set_std(\&std_call); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 121 | $parser->symbol('NEXT') ->set_std( $parser->can('std_next') ); | |||||||||||||||||||||||||||
| 67 | 121 | $parser->symbol('LAST') ->set_std( $parser->can('std_last') ); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 121 | $parser->symbol('MACRO') ->set_std(\&std_macro); | |||||||||||||||||||||||||||
| 70 | 121 | $parser->symbol('BLOCK'); | |||||||||||||||||||||||||||
| 71 | 121 | $parser->symbol('WRAPPER')->set_std(\&std_wrapper); | |||||||||||||||||||||||||||
| 72 | 121 | $parser->symbol('INTO'); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 121 | $parser->symbol('FILTER')->set_std(\&std_filter); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # unsupported directives | ||||||||||||||||||||||||||||
| 77 | 121 | my $nos = $parser->can('not_supported'); | |||||||||||||||||||||||||||
| 78 | 121 | foreach my $keyword (qw( | |||||||||||||||||||||||||||
| 79 | INSERT PROCESS PERL RAWPERL TRY THROW RETURN | ||||||||||||||||||||||||||||
| 80 | STOP CLEAR META TAGS DEBUG VIEW)) { | ||||||||||||||||||||||||||||
| 81 | 1573 | $parser->symbol($keyword)->set_std($nos); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # not supported, but ignored (synonym to CALL) | ||||||||||||||||||||||||||||
| 85 | 121 | $parser->symbol('USE')->set_std(\&std_call); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 121 | foreach my $id(keys %{$parser->symbol_table}) { | |||||||||||||||||||||||||||
| 88 | 12705 | ▶ | if($id =~ /\A [A-Z]+ \z/xms) { # upper-cased keywords | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 4598 | $parser->make_alias($id => lc $id)->set_nud(\&aliased_nud); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 121 | $parser->make_alias('not' => 'NOT'); | |||||||||||||||||||||||||||
| 94 | 121 | $parser->make_alias('and' => 'AND'); | |||||||||||||||||||||||||||
| 95 | 121 | $parser->make_alias('or' => 'OR'); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 121 | return; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | ▶ | around _build_iterator_element => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 2 | my($super, $parser) = @_; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | my $table = $super->($parser); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # make aliases | ||||||||||||||||||||||||||||
| 106 | 2 | $table->{first} = $table->{is_first}; | |||||||||||||||||||||||||||
| 107 | 2 | $table->{last} = $table->{is_last}; | |||||||||||||||||||||||||||
| 108 | 2 | $table->{next} = $table->{peek_next}; | |||||||||||||||||||||||||||
| 109 | 2 | $table->{prev} = $table->{peek_prev}; | |||||||||||||||||||||||||||
| 110 | 2 | $table->{max} = $table->{max_index}; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2 | return $table; | |||||||||||||||||||||||||||
| 113 | 103 | }; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 170 | ▶ | sub default_nud { | ||||||||||||||||||||||||||
|
Subroutine
default_nud: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 170 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 117 | 170 | return $symbol->clone( | |||||||||||||||||||||||||||
| 118 | arity => 'variable', | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # same as default_nud, except for aliased symbols | ||||||||||||||||||||||||||||
| 123 | 4 | ▶ | sub aliased_nud { | ||||||||||||||||||||||||||
|
Subroutine
aliased_nud: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 4 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 125 | 4 | return $symbol->clone( | |||||||||||||||||||||||||||
| 126 | arity => 'name', | ||||||||||||||||||||||||||||
| 127 | id => lc( $symbol->id ), | ||||||||||||||||||||||||||||
| 128 | value => $symbol->id, | ||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 56 | ▶ | sub nud_dollar { | ||||||||||||||||||||||||||
|
Subroutine
nud_dollar: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 133 | 56 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 134 | 56 | my $expr; | |||||||||||||||||||||||||||
| 135 | 56 | my $t = $parser->token; | |||||||||||||||||||||||||||
| 136 | 56 | ▶ | if($t->id eq "{") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 12 | $parser->advance("{"); | |||||||||||||||||||||||||||
| 138 | 12 | $expr = $parser->expression(0); | |||||||||||||||||||||||||||
| 139 | 12 | $parser->advance("}"); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | else { | ||||||||||||||||||||||||||||
| 142 | 44 | ▶ | if(!any_in($t->arity, qw(name variable))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 2 | $parser->_unexpected("a name", $t); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 42 | $parser->advance(); | |||||||||||||||||||||||||||
| 146 | 42 | $expr = $t->clone( arity => 'variable' ); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 54 | return $expr; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 930 | ▶ | sub undefined_name { | ||||||||||||||||||||||||||
|
Subroutine
undefined_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | 930 | my($parser, $name) = @_; | |||||||||||||||||||||||||||
| 153 | # undefined names are always variables | ||||||||||||||||||||||||||||
| 154 | 930 | return $parser->symbol_table->{'(variable)'}->clone( | |||||||||||||||||||||||||||
| 155 | id => $name, | ||||||||||||||||||||||||||||
| 156 | ); | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 99 | ▶ | sub is_valid_field { | ||||||||||||||||||||||||||
|
Subroutine
is_valid_field: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | 99 | my($parser, $token) = @_; | |||||||||||||||||||||||||||
| 161 | 99 | ▶ | return $parser->SUPER::is_valid_field($token) | ||||||||||||||||||||||||||
|
Condition66%2/3
$parser->SUPER::is_valid_field($token) || $token->arity eq 'variable'
MC/DC0%0/2
$parser->SUPER::is_valid_field($token) || $token->arity eq 'variable'
$parser->SUPER::is_valid_field($token)
$token->arity eq 'variable'
Truth table66%2/3
A || B
A= $parser->SUPER::is_valid_field($token)B= $token->arity eq 'variable'
| |||||||||||||||||||||||||||||
| 162 | || $token->arity eq "variable"; | ||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 109 | ▶ | sub led_dot { | ||||||||||||||||||||||||||
|
Subroutine
led_dot: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 109 | my($parser, $symbol, $left) = @_; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # special case: foo.$field, foo.${expr} | ||||||||||||||||||||||||||||
| 169 | 109 | ▶ | if($parser->token->id eq '$') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 10 | return $symbol->clone( | |||||||||||||||||||||||||||
| 171 | arity => "field", | ||||||||||||||||||||||||||||
| 172 | first => $left, | ||||||||||||||||||||||||||||
| 173 | second => $parser->expression( $symbol->lbp ), | ||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 99 | return $parser->SUPER::led_dot($symbol, $left); | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 52 | ▶ | sub led_assignment { | ||||||||||||||||||||||||||
|
Subroutine
led_assignment: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 181 | 52 | my($parser, $symbol, $left) = @_; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 52 | my $assign = $parser->led_infixr($symbol, $left); | |||||||||||||||||||||||||||
| 184 | 52 | $assign->arity('assign'); | |||||||||||||||||||||||||||
| 185 | 52 | $assign->is_statement(1); | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 52 | my $name = $assign->first; | |||||||||||||||||||||||||||
| 188 | 52 | ▶ | if(not $parser->find_or_create($name->id)->is_defined) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 30 | $parser->define($name); | |||||||||||||||||||||||||||
| 190 | 30 | $assign->third('declare'); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 52 | return $assign; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 1210 | ▶ | sub assignment { | ||||||||||||||||||||||||||
|
Subroutine
assignment: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 197 | 1210 | my($parser, $id, $bp) = @_; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 1210 | $parser->symbol($id, $bp)->set_led(\&led_assignment); | |||||||||||||||||||||||||||
| 200 | 1210 | return; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 137 | ▶ | sub std_if { | ||||||||||||||||||||||||||
|
Subroutine
std_if: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 204 | 137 | my($parser, $symbol, $expr) = @_; | |||||||||||||||||||||||||||
| 205 | 137 | my $if = $symbol->clone(arity => "if"); | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 137 | my $is_modifier = defined $expr; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 137 | ▶ | $parser->new_scope() unless $is_modifier; # whole if block | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 137 | my $cond = $parser->expression(0); | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 137 | ▶ | if($symbol->id eq 'UNLESS') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 14 | $cond = $parser->symbol('!')->clone( | |||||||||||||||||||||||||||
| 215 | arity => 'unary', | ||||||||||||||||||||||||||||
| 216 | first => $cond, | ||||||||||||||||||||||||||||
| 217 | ); | ||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 137 | $if->first($cond); | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 137 | ▶ | if($is_modifier) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 34 | $if->second([ $expr ]); | |||||||||||||||||||||||||||
| 223 | 34 | return $if; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | # then block | ||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||
| 228 | 103 | $parser->new_scope(); | |||||||||||||||||||||||||||
| 229 | 103 | $if->second( $parser->statements() ); | |||||||||||||||||||||||||||
| 230 | 103 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 103 | my $t = $parser->token; | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 103 | my $top_if = $if; | |||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 103 | ▶ | while($t->id eq "ELSIF") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 20 | $parser->reserve($t); | |||||||||||||||||||||||||||
| 239 | 20 | $parser->advance(); # "ELSIF" | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 20 | my $elsif = $t->clone(arity => "if"); | |||||||||||||||||||||||||||
| 242 | 20 | $elsif->first( $parser->expression(0) ); | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||
| 245 | 20 | $parser->new_scope(); | |||||||||||||||||||||||||||
| 246 | 20 | $elsif->second( $parser->statements() ); | |||||||||||||||||||||||||||
| 247 | 20 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 20 | $if->third([$elsif]); | |||||||||||||||||||||||||||
| 251 | 20 | $if = $elsif; | |||||||||||||||||||||||||||
| 252 | 20 | $t = $parser->token; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 103 | ▶ | if($t->id eq "ELSE") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 32 | my $else_line = $t->line; | |||||||||||||||||||||||||||
| 257 | 32 | $parser->reserve($t); | |||||||||||||||||||||||||||
| 258 | 32 | $t = $parser->advance(); # "ELSE" | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 32 | ▶ | if($t->id eq "IF" and $t->line != $else_line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$t->id eq "IF" and $t->line != $else_line
MC/DC0%0/2
$t->id eq "IF" and $t->line != $else_line
$t->id eq "IF"
$t->line != $else_line
Truth table33%1/3
A and B
A= $t->id eq "IF"B= $t->line != $else_line
| |||||||||||||||||||||||||||||
| 261 | 0 | Carp::carp(sprintf "%s: Parsing ELSE-IF sequense as ELSIF, but it is likely to be a misuse of ELSE-IF. Please insert semicolon as ELSE; IF, or write it in the same line (around input line %d)", ref $parser, $t->line); | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | { | ||||||||||||||||||||||||||||
| 265 | 32 | $parser->new_scope(); | |||||||||||||||||||||||||||
| 266 | 32 | ▶ | $if->third( $t->id eq "IF" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | ? [$parser->statement()] | ||||||||||||||||||||||||||||
| 268 | : $parser->statements()); | ||||||||||||||||||||||||||||
| 269 | 32 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 103 | $parser->advance("END"); | |||||||||||||||||||||||||||
| 274 | 101 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 275 | 101 | return $top_if; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 20 | ▶ | sub std_switch { | ||||||||||||||||||||||||||
|
Subroutine
std_switch: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 279 | 20 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 20 | $parser->new_scope(); | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 20 | my $topic = $parser->symbol('$_')->clone(arity => 'variable' ); | |||||||||||||||||||||||||||
| 284 | 20 | my $switch = $symbol->clone( | |||||||||||||||||||||||||||
| 285 | arity => 'given', | ||||||||||||||||||||||||||||
| 286 | first => $parser->expression(0), | ||||||||||||||||||||||||||||
| 287 | second => [ $topic ], | ||||||||||||||||||||||||||||
| 288 | ); | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 20 | local $parser->{in_given} = 1; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 20 | my @cases; | |||||||||||||||||||||||||||
| 293 | 20 | ▶ | while(!($parser->token->id eq "END" or $parser->token->id eq '(end)')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$parser->token->id eq "END" or $parser->token->id eq "(end)"
MC/DC100%2/2
$parser->token->id eq "END" or $parser->token->id eq "(end)"
$parser->token->id eq "END"
$parser->token->id eq "(end)"
Truth table100%3/3
A or B
A= $parser->token->id eq "END"B= $parser->token->id eq "(end)"
| |||||||||||||||||||||||||||||
| 294 | 78 | push @cases, $parser->statement(); | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | 20 | $switch->third( \@cases ); | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 20 | $parser->build_given_body($switch, "case"); | |||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 18 | $parser->advance("END"); | |||||||||||||||||||||||||||
| 301 | 18 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 302 | 18 | return $switch; | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 38 | ▶ | sub std_case { | ||||||||||||||||||||||||||
|
Subroutine
std_case: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 306 | 38 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 307 | 38 | ▶ | if(!$parser->in_given) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 0 | $parser->_error("You cannot use $symbol statements outside switch statements"); | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | 38 | my $case = $symbol->clone(arity => "case"); | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 38 | ▶ | if($parser->token->id ne "DEFAULT") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 24 | $case->first( $parser->expression(0) ); | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | else { | ||||||||||||||||||||||||||||
| 316 | 14 | $parser->advance(); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | 38 | $case->second( $parser->statements() ); | |||||||||||||||||||||||||||
| 319 | 38 | return $case; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 70 | ▶ | sub iterator_name { | ||||||||||||||||||||||||||
|
Subroutine
iterator_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 323 | 70 | return 'loop'; # always 'loop' | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | # FOR ... IN ...; ...; END | ||||||||||||||||||||||||||||
| 327 | 70 | ▶ | sub std_for { | ||||||||||||||||||||||||||
|
Subroutine
std_for: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 328 | 70 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 70 | my $proc = $symbol->clone(arity => "for"); | |||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 70 | my $var = $parser->token; | |||||||||||||||||||||||||||
| 333 | 70 | ▶ | if(!any_in($var->arity, qw(variable name))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 0 | $parser->_unexpected("a variable name", $var); | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | 70 | $parser->advance(); | |||||||||||||||||||||||||||
| 337 | 70 | $parser->advance("IN"); | |||||||||||||||||||||||||||
| 338 | 70 | $proc->first( $parser->expression(0) ); | |||||||||||||||||||||||||||
| 339 | 70 | $proc->second([$var]); | |||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 70 | $parser->new_scope(); | |||||||||||||||||||||||||||
| 342 | 70 | $parser->define_iterator($var); | |||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 70 | $proc->third( $parser->statements() ); | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # for-else | ||||||||||||||||||||||||||||
| 347 | 70 | ▶ | if($parser->token->id eq 'ELSE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 6 | $parser->reserve($parser->token); | |||||||||||||||||||||||||||
| 349 | 6 | $parser->advance(); | |||||||||||||||||||||||||||
| 350 | 6 | my $else = $parser->statements(); | |||||||||||||||||||||||||||
| 351 | 6 | $proc = $symbol->clone( arity => 'for_else', | |||||||||||||||||||||||||||
| 352 | first => $proc, | ||||||||||||||||||||||||||||
| 353 | second => $else, | ||||||||||||||||||||||||||||
| 354 | ); | ||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | 70 | $parser->advance("END"); | |||||||||||||||||||||||||||
| 357 | 70 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 358 | 70 | return $proc; | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 20 | ▶ | sub std_while { | ||||||||||||||||||||||||||
|
Subroutine
std_while: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 362 | 20 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 20 | my $while = $symbol->clone(arity => "while"); | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 20 | $while->first( $parser->expression(0) ); | |||||||||||||||||||||||||||
| 367 | 20 | $while->second([]); # no vars | |||||||||||||||||||||||||||
| 368 | 20 | $parser->new_scope(); | |||||||||||||||||||||||||||
| 369 | 20 | $while->third( $parser->statements() ); | |||||||||||||||||||||||||||
| 370 | 20 | $parser->advance("END"); | |||||||||||||||||||||||||||
| 371 | 20 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 372 | 20 | return $while; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 36 | ▶ | around std_include => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 376 | 36 | my($super, $self, $symbol) = @_; | |||||||||||||||||||||||||||
| 377 | 36 | $symbol->id( lc $symbol->id ); | |||||||||||||||||||||||||||
| 378 | 36 | return $self->$super( $symbol ); | |||||||||||||||||||||||||||
| 379 | 103 | }; | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 66 | ▶ | sub localize_vars { | ||||||||||||||||||||||||||
|
Subroutine
localize_vars: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 382 | 66 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | # should make 'WITH' optional? | ||||||||||||||||||||||||||||
| 385 | # my $t = $parser->token; | ||||||||||||||||||||||||||||
| 386 | # if($t->id eq "WITH" or $t->arity eq "variable") { | ||||||||||||||||||||||||||||
| 387 | # $parser->advance() if $t->id eq "WITH"; | ||||||||||||||||||||||||||||
| 388 | 66 | ▶ | if($parser->token->id eq "WITH") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 389 | 18 | $parser->advance(); | |||||||||||||||||||||||||||
| 390 | 18 | $parser->new_scope(); | |||||||||||||||||||||||||||
| 391 | 18 | my $vars = $parser->set_list(); | |||||||||||||||||||||||||||
| 392 | 18 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 393 | 18 | return $vars; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | 48 | return undef; | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 78 | ▶ | sub set_list { | ||||||||||||||||||||||||||
|
Subroutine
set_list: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 399 | 78 | my($parser) = @_; | |||||||||||||||||||||||||||
| 400 | 78 | my @args; | |||||||||||||||||||||||||||
| 401 | 78 | while(1) { | |||||||||||||||||||||||||||
| 402 | 168 | my $key = $parser->token; | |||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 168 | ▶ | if(!(any_in($key->arity, qw(variable name)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
any_in($key->arity, ("variable", "name")) and $parser->next_token_is("=")
MC/DC100%2/2
any_in($key->arity, ("variable", "name")) and $parser->next_token_is("=")
any_in($key->arity, ("variable", "name"))
$parser->next_token_is("=")
Truth table100%3/3
A and B
A= any_in($key->arity, ("variable", "name"))B= $parser->next_token_is("=")
| |||||||||||||||||||||||||||||
| 405 | && $parser->next_token_is("="))) { | ||||||||||||||||||||||||||||
| 406 | 78 | last; | |||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | 90 | $parser->advance(); | |||||||||||||||||||||||||||
| 409 | 90 | $parser->advance("="); | |||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 90 | my $value = $parser->expression(0); | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 90 | push @args, $key => $value; | |||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 90 | ▶ | if($parser->token->id eq ",") { # , is optional | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | 6 | $parser->advance(); | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 78 | return \@args; | |||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 10 | ▶ | sub std_get { | ||||||||||||||||||||||||||
|
Subroutine
std_get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 424 | 10 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 10 | my $stmt = $parser->print( $parser->expression(0) ); | |||||||||||||||||||||||||||
| 427 | 10 | return $parser->finish_statement($stmt); | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 60 | ▶ | sub std_set { | ||||||||||||||||||||||||||
|
Subroutine
std_set: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 431 | 60 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 60 | my $is_default = ($symbol->id eq 'DEFAULT'); | |||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 60 | my $set_list = $parser->set_list(); | |||||||||||||||||||||||||||
| 436 | 60 | my @assigns; | |||||||||||||||||||||||||||
| 437 | 60 | ▶ | for(my $i = 0; $i < @{$set_list}; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | 66 | my($name, $value) = @{$set_list}[$i, $i+1]; | |||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 66 | ▶ | if($is_default) { # DEFAULT a = b -> a = a || b | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | 14 | my $var = $parser->symbol('(variable)')->clone( | |||||||||||||||||||||||||||
| 442 | id => $name->id, | ||||||||||||||||||||||||||||
| 443 | ); | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 14 | $value = $parser->binary('||', $var, $value); | |||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | 66 | my $assign = $symbol->clone( | |||||||||||||||||||||||||||
| 448 | id => '=', | ||||||||||||||||||||||||||||
| 449 | arity => 'assign', | ||||||||||||||||||||||||||||
| 450 | first => $name, | ||||||||||||||||||||||||||||
| 451 | second => $value, | ||||||||||||||||||||||||||||
| 452 | ); | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | 66 | ▶ | if(not $parser->find_or_create($name->id)->is_defined) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | 64 | $parser->define($name); | |||||||||||||||||||||||||||
| 456 | 64 | $assign->third('declare'); | |||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | 66 | push @assigns, $assign; | |||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | 60 | return @assigns; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 14 | ▶ | sub std_call { | ||||||||||||||||||||||||||
|
Subroutine
std_call: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 464 | 14 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 465 | 14 | my $stmt = $parser->expression(0); | |||||||||||||||||||||||||||
| 466 | 14 | return $parser->finish_statement($stmt); | |||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 36 | ▶ | sub std_macro { | ||||||||||||||||||||||||||
|
Subroutine
std_macro: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 470 | 36 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 471 | 36 | my $proc = $symbol->clone( | |||||||||||||||||||||||||||
| 472 | arity => 'proc', | ||||||||||||||||||||||||||||
| 473 | id => 'macro', | ||||||||||||||||||||||||||||
| 474 | ); | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 36 | my $name = $parser->token; | |||||||||||||||||||||||||||
| 477 | 36 | ▶ | if($name->arity ne "variable") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 478 | 0 | $parser->_error("a name", $name); | |||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | 36 | $parser->define_function($name->id); | |||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 36 | $proc->first($name); | |||||||||||||||||||||||||||
| 484 | 36 | $parser->advance(); | |||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 36 | $parser->new_scope(); | |||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 36 | my $paren = ($parser->token->id eq "("); | |||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 36 | ▶ | $parser->advance("(") if $paren; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 36 | my $t = $parser->token; | |||||||||||||||||||||||||||
| 493 | 36 | my @vars; | |||||||||||||||||||||||||||
| 494 | 36 | ▶ | while($t->arity eq "variable") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 495 | 18 | push @vars, $t; | |||||||||||||||||||||||||||
| 496 | 18 | $parser->define($t); | |||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 18 | $t = $parser->advance(); | |||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 18 | ▶ | if($t->id eq ",") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | 2 | $t = $parser->advance(); # "," | |||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||
| 503 | else { | ||||||||||||||||||||||||||||
| 504 | 16 | last; | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | 36 | ▶ | $parser->advance(")") if $paren; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | 36 | $proc->second(\@vars); | |||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 36 | $parser->advance("BLOCK"); | |||||||||||||||||||||||||||
| 512 | 36 | $proc->third( $parser->statements() ); | |||||||||||||||||||||||||||
| 513 | 36 | $parser->advance("END"); | |||||||||||||||||||||||||||
| 514 | 36 | $parser->pop_scope(); | |||||||||||||||||||||||||||
| 515 | 36 | return $proc; | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | # WRAPPER "foo.tt" ... END | ||||||||||||||||||||||||||||
| 520 | # is | ||||||||||||||||||||||||||||
| 521 | # cascade "foo.tt" { content => lambda@xxx() } | ||||||||||||||||||||||||||||
| 522 | # macro content@xxx -> { ... } | ||||||||||||||||||||||||||||
| 523 | 30 | ▶ | sub std_wrapper { | ||||||||||||||||||||||||||
|
Subroutine
std_wrapper: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 524 | 30 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 30 | my $base = $parser->barename(); | |||||||||||||||||||||||||||
| 527 | 30 | my $into; | |||||||||||||||||||||||||||
| 528 | 30 | ▶ | if($parser->token->id eq "INTO") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 529 | 2 | my $t = $parser->advance(); | |||||||||||||||||||||||||||
| 530 | 2 | ▶ | if(!any_in($t->arity, qw(name variable))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 531 | 0 | $parser->_unexpected("a variable name", $t); | |||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||
| 533 | 2 | $parser->advance(); | |||||||||||||||||||||||||||
| 534 | 2 | $into = $t->id; | |||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | else { | ||||||||||||||||||||||||||||
| 537 | 28 | $into = 'content'; | |||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||
| 539 | 30 | ▶ | my $vars = $parser->localize_vars() || []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$parser->localize_vars || []
MC/DC100%1/1
$parser->localize_vars || []
$parser->localize_vars
Truth table100%2/2
A
A= $parser->localize_vars
| |||||||||||||||||||||||||||||
| 540 | 30 | my $body = $parser->statements(); | |||||||||||||||||||||||||||
| 541 | 30 | $parser->advance("END"); | |||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | 30 | return $parser->wrap( | |||||||||||||||||||||||||||
| 544 | $symbol, | ||||||||||||||||||||||||||||
| 545 | $base, | ||||||||||||||||||||||||||||
| 546 | $into, | ||||||||||||||||||||||||||||
| 547 | $vars, | ||||||||||||||||||||||||||||
| 548 | $body, | ||||||||||||||||||||||||||||
| 549 | ); | ||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 30 | ▶ | sub wrap { | ||||||||||||||||||||||||||
|
Subroutine
wrap: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 553 | 30 | my($parser, $proto, $base, $into, $vars, $body) = @_; | |||||||||||||||||||||||||||
| 554 | 30 | my $cascade = $proto->clone( | |||||||||||||||||||||||||||
| 555 | arity => 'cascade', | ||||||||||||||||||||||||||||
| 556 | first => $base, | ||||||||||||||||||||||||||||
| 557 | ); | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 30 | my $content = $parser->lambda($proto); | |||||||||||||||||||||||||||
| 560 | 30 | $content->second([]); # args | |||||||||||||||||||||||||||
| 561 | 30 | $content->third($body); | |||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | 30 | my $call_content = $parser->call($content->first); | |||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | 30 | my $into_name = $proto->clone( | |||||||||||||||||||||||||||
| 566 | arity => 'literal', | ||||||||||||||||||||||||||||
| 567 | id => $into, | ||||||||||||||||||||||||||||
| 568 | ); | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 30 | push @{$vars}, $into_name => $call_content; | |||||||||||||||||||||||||||
| 571 | 30 | $cascade->third($vars); | |||||||||||||||||||||||||||
| 572 | 30 | return( $cascade, $content ); | |||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | # [% FILTER html %] | ||||||||||||||||||||||||||||
| 576 | # ... | ||||||||||||||||||||||||||||
| 577 | # [% END %] | ||||||||||||||||||||||||||||
| 578 | # is | ||||||||||||||||||||||||||||
| 579 | # : block filter_xxx | html -> { | ||||||||||||||||||||||||||||
| 580 | # ... | ||||||||||||||||||||||||||||
| 581 | # : } | ||||||||||||||||||||||||||||
| 582 | # in Kolon | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | 14 | ▶ | sub std_filter { | ||||||||||||||||||||||||||
|
Subroutine
std_filter: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 585 | 14 | my($parser, $symbol) = @_; | |||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | 14 | my $filter = $parser->expression(0); | |||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | 14 | my $proc = $parser->lambda($symbol); | |||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | 14 | $proc->second([]); | |||||||||||||||||||||||||||
| 592 | 14 | $proc->third( $parser->statements() ); | |||||||||||||||||||||||||||
| 593 | 14 | $parser->advance("END"); | |||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | 14 | my $callmacro = $parser->call($proc->first); | |||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | 14 | ▶ | if($filter->id eq 'html') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 598 | # for compatibility with TT2 | ||||||||||||||||||||||||||||
| 599 | 8 | $filter = 'unmark_raw'; | |||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||
| 601 | 14 | my $callfilter = $parser->call($filter, $callmacro); | |||||||||||||||||||||||||||
| 602 | 14 | return( $proc, $parser->print($callfilter) ); | |||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | 103 | ▶ | no Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 606 | 103 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||||||||||
| 607 | __END__ | ||||||||||||||||||||||||||||