| 1 | package Text::Xslate::Parser; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 357 | ▶ | use Mouse; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 357 | ▶ | use Scalar::Util (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 357 | ▶ | use Text::Xslate::Symbol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 357 | ▶ | use Text::Xslate::Util qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | $DEBUG | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | $STRING $NUMBER | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | is_int any_in | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | neat | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | literal_to_value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | make_error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | p | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 357 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 357 | ▶ | use constant _DUMP_PROTO => scalar($DEBUG =~ /\b dump=proto \b/xmsi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 357 | ▶ | use constant _DUMP_TOKEN => scalar($DEBUG =~ /\b dump=token \b/xmsi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 357 | our @CARP_NOT = qw(Text::Xslate::Compiler Text::Xslate::Symbol); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 357 | my $CODE = qr/ (?: $STRING | [^'"] ) /xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 357 | my $COMMENT = qr/\# [^\n;]* (?= [;\n] | \z)/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Operator tokens that the parser recognizes. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # All the single characters are tokenized as an operator. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 357 | my $OPERATOR_TOKEN = sprintf '(?:%s|[^ \t\r\n])', join('|', map{ quotemeta } qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | .. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | == != <=> <= >= | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | << >> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | += -= *= /= %= ~= | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | &&= ||= //= | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ~~ =~ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | && || // | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | -> => | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | :: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ++ -- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | +| +& +^ +< +> +~ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ), ','); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 357 | my %shortcut_table = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | '=' => 'print', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 357 | my $CHOMP_FLAGS = qr/-/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 357 | has identity_pattern => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | isa => 'RegexpRef', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | builder => '_build_identity_pattern', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 372 | ▶ | sub _build_identity_pattern { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_identity_pattern: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 372 | return qr/(?: (?:[A-Za-z_]|\$\~?) [A-Za-z0-9_]* )/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 357 | has [qw(compiler engine)] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | required => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | weak_ref => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | has symbol_table => ( # the global symbol table | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | isa => 'HashRef', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 493 | ▶ | default => sub{ {} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 357 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 357 | has iterator_element => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | isa => 'HashRef', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | lazy => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | builder => '_build_iterator_element', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | has scope => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | isa => 'ArrayRef[HashRef]', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | clearer => 'init_scope', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | lazy => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 493 | ▶ | default => sub{ [ {} ] }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 357 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 357 | has token => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | isa => 'Maybe[Object]', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 357 | has next_token => ( # to peek the next token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | isa => 'Maybe[ArrayRef]', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 357 | has statement_is_finished => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | isa => 'Bool', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 357 | has following_newline => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | isa => 'Int', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | default => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 357 | has input => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | isa => 'Str', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 357 | has line_start => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | isa => 'Maybe[Str]', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | builder => '_build_line_start', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 360 | ▶ | sub _build_line_start { ':' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_line_start: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 357 | has tag_start => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | isa => 'Str', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | builder => '_build_tag_start', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 362 | ▶ | sub _build_tag_start { '<:' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_tag_start: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 357 | has tag_end => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | isa => 'Str', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | builder => '_build_tag_end', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 362 | ▶ | sub _build_tag_end { ':>' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_tag_end: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 357 | has comment_pattern => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | isa => 'RegexpRef', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | builder => '_build_comment_pattern', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 493 | ▶ | sub _build_comment_pattern { $COMMENT } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_comment_pattern: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 357 | has shortcut_table => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | isa => 'HashRef[Str]', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | builder => '_build_shortcut_table', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 493 | ▶ | sub _build_shortcut_table { \%shortcut_table } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_shortcut_table: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 357 | has in_given => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | isa => 'Bool', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # attributes for error messages | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 357 | has near_token => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 357 | has file => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | required => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 357 | has line => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | is => 'rw', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | required => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 357 | has input_layer => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | is => 'ro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | default => ':utf8', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | sub symbol_class() { 'Text::Xslate::Symbol' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # the entry point | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 7034 | ▶ | sub parse { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=5 SCAR=16.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 7034 | my($parser, $input, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 7034 | ▶ | local $parser->{file} = $args{file} || \$input; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'file'} || \$input
MC/DC100%1/1
$args{'file'} || \$input
$args{'file'}
Truth table100%2/2
A
A= $args{'file'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 7034 | ▶ | local $parser->{line} = $args{line} || 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'line'} || 1
MC/DC0%0/1
$args{'line'} || 1
$args{'line'}
Truth table50%1/2
A
A= $args{'line'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 7034 | local $parser->{in_given} = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 7034 | local $parser->{scope} = [ map { +{ %{$_} } } @{ $parser->scope } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 7034 | local $parser->{symbol_table} = { %{ $parser->symbol_table } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 7034 | local $parser->{near_token}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 7034 | local $parser->{next_token}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 7034 | local $parser->{token}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 7034 | local $parser->{input}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 7034 | $parser->input( $parser->preprocess($input) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 7024 | $parser->next_token( $parser->tokenize() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 7024 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 7022 | my $ast = $parser->statements(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 6940 | ▶ | if(my $input_pos = pos $parser->{input}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 6934 | ▶ | if($input_pos != length($parser->{input})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 4 | $parser->_error("Syntax error", $parser->token); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6936 | return $ast; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 10567 | ▶ | sub trim_code { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trim_code: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 10567 | my($parser, $s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 10567 | $s =~ s/\A [ \t]+ //xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 10567 | $s =~ s/ [ \t]+ \n?\z//xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 10567 | return $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 20924 | ▶ | sub auto_chomp { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto_chomp: called CC=11 SCAR=24.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 20924 | my($parser, $tokens_ref, $i, $s_ref) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 20924 | my $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 20924 | my $nl = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # postchomp | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 20924 | ▶ | if($i >= 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i >= 1 and +($p = $$tokens_ref[$i - 1])->[0] eq "postchomp"
MC/DC100%2/2
$i >= 1 and +($p = $$tokens_ref[$i - 1])->[0] eq "postchomp"
$i >= 1
+($p = $$tokens_ref[$i - 1])->[0] eq "postchomp"
Truth table100%3/3
A and B
A= $i >= 1B= +($p = $$tokens_ref[$i - 1])->[0] eq "postchomp"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | and ($p = $tokens_ref->[$i-1])->[0] eq 'postchomp') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # [ CODE ][*][ TEXT ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # <: ... -:> \nfoobar | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # ^^^^ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 782 | ${$s_ref} =~ s/\A [ \t]* (\n)//xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 782 | ▶ | if($1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 772 | $nl++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # prechomp | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 20924 | ▶ | if(($i+1) < @{$tokens_ref} | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$i + 1 < @{$tokens_ref;} and +($p = $$tokens_ref[$i + 1])->[0] eq "prechomp"
MC/DC100%2/2
$i + 1 < @{$tokens_ref;} and +($p = $$tokens_ref[$i + 1])->[0] eq "prechomp"
$i + 1 < @{$tokens_ref;}
+($p = $$tokens_ref[$i + 1])->[0] eq "prechomp"
Truth table100%3/3
A and B
A= $i + 1 < @{$tokens_ref;}B= +($p = $$tokens_ref[$i + 1])->[0] eq "prechomp"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | and ($p = $tokens_ref->[$i+1])->[0] eq 'prechomp') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 102 | ▶ | if(${$s_ref} !~ / [^ \t] /xms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # HERE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # [ TEXT ][*][ CODE ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # <:- ... :> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # ^^^^^^^^ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 68 | ${$s_ref} = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # HERE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # [ TEXT ][*][ CODE ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # \n<:- ... :> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # ^^ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 34 | $nl += chomp ${$s_ref}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 20822 | ▶ | elsif(($i+2) < @{$tokens_ref} | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
$i + 2 < @{$tokens_ref;} and +($p = $$tokens_ref[$i + 2])->[0] eq "prechomp" and +($p = $$tokens_ref[$i + 1])->[0] eq "text" and not $p->[1] =~ / [^ \t] /msx
$i + 2 < @{$tokens_ref;} and +($p = $$tokens_ref[$i + 2])->[0] eq "prechomp" and +($p = $$tokens_ref[$i + 1])->[0] eq "text"
$i + 2 < @{$tokens_ref;} and +($p = $$tokens_ref[$i + 2])->[0] eq "prechomp"
MC/DC75%3/4
$i + 2 < @{$tokens_ref;} and +($p = $$tokens_ref[$i + 2])->[0] eq "prechomp" and +($p = $$tokens_ref[$i + 1])->[0] eq "text" and not $p->[1] =~ / [^ \t] /msx
$i + 2 < @{$tokens_ref;}
+($p = $$tokens_ref[$i + 2])->[0] eq "prechomp"
+($p = $$tokens_ref[$i + 1])->[0] eq "text"
not $p->[1] =~ / [^ \t] /msx
Truth table80%4/5
A and B and C and not(D)
A= $i + 2 < @{$tokens_ref;}B= +($p = $$tokens_ref[$i + 2])->[0] eq "prechomp"C= +($p = $$tokens_ref[$i + 1])->[0] eq "text"D= not $p->[1] =~ / [^ \t] /msx
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | and ($p = $tokens_ref->[$i+2])->[0] eq 'prechomp' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | and ($p = $tokens_ref->[$i+1])->[0] eq 'text' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | and $p->[1] !~ / [^ \t] /xms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # HERE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # [ TEXT ][ TEXT ][*][ CODE ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # \n <:- ... :> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # ^^^^^^^^^^ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 32 | $p->[1] = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 32 | $nl += (${$s_ref} =~ s/\n\z//xms); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 20924 | return $nl; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # split templates by tags before tokenizing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 7034 | ▶ | sub split :method { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split: called CC=17 SCAR=28.3
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 7034 | my $parser = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 7034 | local($_) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 7034 | my @tokens; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 7034 | my $line_start = $parser->line_start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 7034 | my $tag_start = $parser->tag_start; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 7034 | my $tag_end = $parser->tag_end; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 7034 | ▶ | my $lex_line_code = defined($line_start) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
defined $line_start && qr/\A ^ [ \t]* \Q$line_start\E ([^\n]* \n?) /msx
MC/DC100%1/1
defined $line_start && qr/\A ^ [ \t]* \Q$line_start\E ([^\n]* \n?) /msx
defined $line_start
Truth table100%2/2
A
A= defined $line_start
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | && qr/\A ^ [ \t]* \Q$line_start\E ([^\n]* \n?) /xms; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 7034 | my $lex_tag_start = qr/\A \Q$tag_start\E ($CHOMP_FLAGS?)/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # 'text' is a something without newlines | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # following a newline, $tag_start, or end of the input | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 7034 | my $lex_text = qr/\A ( [^\n]*? (?: \n | (?= \Q$tag_start\E ) | \z ) ) /xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 7034 | my $lex_comment = $parser->comment_pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 7034 | my $lex_code = qr/(?: $lex_comment | $CODE )/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 7034 | my $in_tag = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 7034 | ▶ | while($_ ne '') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 36950 | ▶ | if($in_tag) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 5423 | my $start = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 5423 | my $pos; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 5423 | ▶ | while( ($pos = index $_, $tag_end, $start) >= 0 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 5421 | my $code = substr $_, 0, $pos; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 5421 | $code =~ s/$lex_code//xmsg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 5421 | ▶ | if(length($code) == 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 5415 | last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 6 | $start = $pos + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 5423 | ▶ | if($pos >= 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 5415 | my $code = substr $_, 0, $pos, ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 5415 | $code =~ s/($CHOMP_FLAGS?) \z//xmso; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 5415 | my $chomp = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 5415 | ▶ | s/\A \Q$tag_end\E //xms or die "Oops!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 5415 | push @tokens, [ code => $code ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 5415 | ▶ | if($chomp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 786 | push @tokens, [ postchomp => $chomp ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 5415 | $in_tag = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 8 | last; # the end tag is not found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # not $in_tag | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | ▶ | elsif($lex_line_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
$lex_line_code and @tokens == 0 || $tokens[-1][1] =~ /\n\z/msx and s/$lex_line_code//msx
$lex_line_code and @tokens == 0 || $tokens[-1][1] =~ /\n\z/msx
@tokens == 0 or $tokens[-1][1] =~ /\n\z/msx
MC/DC100%4/4
$lex_line_code and @tokens == 0 || $tokens[-1][1] =~ /\n\z/msx and s/$lex_line_code//msx
$lex_line_code
@tokens == 0
$tokens[-1][1] =~ /\n\z/msx
s/$lex_line_code//msx
Truth table100%6/6
A and B or C and D
A= $lex_line_codeB= @tokens == 0C= $tokens[-1][1] =~ /\n\z/msxD= s/$lex_line_code//msx
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | && (@tokens == 0 || $tokens[-1][1] =~ /\n\z/xms) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | && s/$lex_line_code//xms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 5162 | push @tokens, [ code => $1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | elsif(s/$lex_tag_start//xms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 5425 | $in_tag = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 5425 | my $chomp = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 5425 | ▶ | if($chomp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 120 | push @tokens, [ prechomp => $chomp ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | elsif(s/$lex_text//xms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 20940 | push @tokens, [ text => $1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | confess "Oops: Unreached code, near" . p($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 7034 | ▶ | if($in_tag) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # calculate line number | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 10 | my $orig_src = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 10 | substr $orig_src, -length($_), length($_), ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 10 | my $line = ($orig_src =~ tr/\n/\n/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 10 | $parser->_error("Malformed templates detected", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | neat((split /\n/, $_)[0]), ++$line, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | #p(\@tokens); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 7024 | return \@tokens; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 7034 | ▶ | sub preprocess { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
preprocess: called CC=10 SCAR=23.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 7034 | my($parser, $input) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # tokenization | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 7034 | my $tokens_ref = $parser->split($input); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 7024 | my $code = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 7024 | my $shortcut_table = $parser->shortcut_table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 7024 | my $shortcut = join('|', map{ quotemeta } keys %shortcut_table); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 7024 | my $shortcut_rx = qr/\A ($shortcut)/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 7024 | ▶ | for(my $i = 0; $i < @{$tokens_ref}; $i++) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 32405 | my($type, $s) = @{ $tokens_ref->[$i] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 32405 | ▶ | if($type eq 'text') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 20924 | my $nl = $parser->auto_chomp($tokens_ref, $i, \$s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 20924 | $s =~ s/(["\\])/\\$1/gxms; # " for poor editors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # $s may have single new line | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 20924 | $nl += ($s =~ s/\n/\\n/xms); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 20924 | $code .= qq{print_raw "$s";}; # must set even if $s is empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 20924 | ▶ | $code .= qq{\n} if $nl > 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | elsif($type eq 'code') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # shortcut commands | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 10575 | ▶ | $s =~ s/$shortcut_rx/$shortcut_table->{$1}/xms | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | if $shortcut; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 10575 | $s = $parser->trim_code($s); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 10575 | ▶ | if($s =~ /\A \s* [}] \s* \z/xms){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 1114 | $code .= $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | elsif($s =~ s/\n\z//xms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 4086 | $code .= qq{$s\n}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 5375 | $code .= qq{$s;}; # auto semicolon insertion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | elsif($type eq 'prechomp') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # noop, just a marker | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | elsif($type eq 'postchomp') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # noop, just a marker | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $parser->_error("Oops: Unknown token: $s ($type)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 7024 | print STDOUT $code, "\n" if _DUMP_PROTO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 7024 | return $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 493 | ▶ | sub BUILD { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 493 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 493 | $parser->_init_basic_symbols(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 493 | $parser->init_symbols(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 493 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # The grammer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 493 | ▶ | sub _init_basic_symbols { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_basic_symbols: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 493 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 493 | $parser->symbol('(end)')->is_block_end(1); # EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # prototypes of value symbols | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 493 | foreach my $type (qw(name variable literal)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1479 | my $s = $parser->symbol("($type)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1479 | $s->arity($type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 1479 | $s->set_nud( $parser->can("nud_$type") ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # common separators | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 493 | $parser->symbol(';')->set_nud(\&nud_separator); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 493 | $parser->define_pair('(' => ')'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 493 | $parser->define_pair('{' => '}'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 493 | $parser->define_pair('[' => ']'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 493 | $parser->symbol(',') ->is_comma(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 493 | $parser->symbol('=>') ->is_comma(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # common commands | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 493 | $parser->symbol('print') ->set_std(\&std_print); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 493 | $parser->symbol('print_raw')->set_std(\&std_print); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # special literals | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 493 | $parser->define_literal(nil => undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 493 | $parser->define_literal(true => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 493 | $parser->define_literal(false => 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # special tokens | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 493 | $parser->symbol('__FILE__')->set_nud(\&nud_current_file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 493 | $parser->symbol('__LINE__')->set_nud(\&nud_current_line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 493 | $parser->symbol('__ROOT__')->set_nud(\&nud_current_vars); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 493 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 493 | ▶ | sub init_basic_operators { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_basic_operators: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 493 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # define operator precedence | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 493 | $parser->prefix('{', 256, \&nud_brace); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 493 | $parser->prefix('[', 256, \&nud_brace); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 493 | $parser->infix('(', 256, \&led_call); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 493 | $parser->infix('.', 256, \&led_dot); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 493 | $parser->infix('[', 256, \&led_fetch); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 493 | $parser->prefix('(', 256, \&nud_paren); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 493 | $parser->prefix('!', 200)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 493 | $parser->prefix('+', 200); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 493 | $parser->prefix('-', 200); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 493 | $parser->prefix('+^', 200); # numeric bitwise negate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 493 | $parser->infix('*', 190); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 493 | $parser->infix('/', 190); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 493 | $parser->infix('%', 190); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 493 | $parser->infix('x', 190); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 493 | $parser->infix('+&', 190); # numeric bitwise and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 493 | $parser->infix('+', 180); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 493 | $parser->infix('-', 180); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 493 | $parser->infix('~', 180); # connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 493 | $parser->infix('+|', 180); # numeric bitwise or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 493 | $parser->infix('+^', 180); # numeric bitwise xor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 493 | $parser->prefix('defined', 170, \&nud_defined); # named unary operator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 493 | $parser->infix('<', 160)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 493 | $parser->infix('<=', 160)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 493 | $parser->infix('>', 160)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 493 | $parser->infix('>=', 160)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 493 | $parser->infix('==', 150)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 493 | $parser->infix('!=', 150)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 493 | $parser->infix('<=>', 150); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 493 | $parser->infix('cmp', 150); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 493 | $parser->infix('~~', 150); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 493 | $parser->infix('|', 140, \&led_pipe); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 493 | $parser->infix('&&', 130)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 493 | $parser->infix('||', 120)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 493 | $parser->infix('//', 120)->is_logical(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 493 | $parser->infix('min', 120); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 493 | $parser->infix('max', 120); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 493 | $parser->infix('..', 110, \&led_range); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 493 | $parser->symbol(':'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 493 | $parser->infixr('?', 100, \&led_ternary); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 493 | $parser->assignment('=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 493 | $parser->assignment('+=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 493 | $parser->assignment('-=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 493 | $parser->assignment('*=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 493 | $parser->assignment('/=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 493 | $parser->assignment('%=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 493 | $parser->assignment('~=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 493 | $parser->assignment('&&=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 493 | $parser->assignment('||=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 493 | $parser->assignment('//=', 90); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 493 | $parser->make_alias('!' => 'not')->ubp(70); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 493 | $parser->make_alias('&&' => 'and')->lbp(60); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 493 | $parser->make_alias('||' => 'or') ->lbp(50); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 493 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 372 | ▶ | sub init_symbols { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_symbols: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 372 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 372 | my $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # syntax specific separators | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 372 | $parser->symbol('{'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 372 | $parser->symbol('}')->is_block_end(1); # block end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 372 | $parser->symbol('->'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 372 | $parser->symbol('else'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 372 | $parser->symbol('with'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 372 | $parser->symbol('::'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # operators | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 372 | $parser->init_basic_operators(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # statements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 372 | $s = $parser->symbol('if'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 372 | $s->set_std(\&std_if); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 372 | $s->can_be_modifier(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 372 | $parser->symbol('for') ->set_std(\&std_for); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 372 | $parser->symbol('while' ) ->set_std(\&std_while); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 372 | $parser->symbol('given') ->set_std(\&std_given); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 372 | $parser->symbol('when') ->set_std(\&std_when); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 372 | $parser->symbol('default') ->set_std(\&std_when); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 372 | $parser->symbol('include') ->set_std(\&std_include); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 372 | $parser->symbol('last') ->set_std(\&std_last); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 372 | $parser->symbol('next') ->set_std(\&std_next); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # macros | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 372 | $parser->symbol('cascade') ->set_std(\&std_cascade); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 372 | $parser->symbol('macro') ->set_std(\&std_proc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 372 | $parser->symbol('around') ->set_std(\&std_proc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 372 | $parser->symbol('before') ->set_std(\&std_proc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 372 | $parser->symbol('after') ->set_std(\&std_proc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 372 | $parser->symbol('block') ->set_std(\&std_macro_block); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 372 | $parser->symbol('super') ->set_std(\&std_super); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 372 | $parser->symbol('override') ->set_std(\&std_override); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 372 | $parser->symbol('->') ->set_nud(\&nud_lambda); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | # lexical variables/constants stuff | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 372 | $parser->symbol('constant')->set_nud(\&nud_constant); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 372 | $parser->symbol('my' )->set_nud(\&nud_constant); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 372 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 8 | ▶ | sub _build_iterator_element { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_iterator_element: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | return { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 8 | index => \&iterator_index, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | count => \&iterator_count, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | is_first => \&iterator_is_first, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | is_last => \&iterator_is_last, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | body => \&iterator_body, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | size => \&iterator_size, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | max_index => \&iterator_max_index, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | peek_next => \&iterator_peek_next, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | peek_prev => \&iterator_peek_prev, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | cycle => \&iterator_cycle, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 107906 | ▶ | sub symbol { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
symbol: called CC=4 SCAR=13.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 107906 | my($parser, $id, $lbp) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 107906 | my $stash = $parser->symbol_table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 107906 | my $s = $stash->{$id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 107906 | ▶ | if(defined $s) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 51186 | ▶ | if(defined $lbp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 2465 | $s->lbp($lbp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | else { # create a new symbol | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 56720 | ▶ | $s = $parser->symbol_class->new(id => $id, lbp => $lbp || 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$lbp || 0
MC/DC100%1/1
$lbp || 0
$lbp
Truth table100%2/2
A
A= $lbp
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 56720 | $stash->{$id} = $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 107906 | return $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1479 | ▶ | sub define_pair { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define_pair: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 1479 | my($parser, $left, $right) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 1479 | $parser->symbol($left) ->counterpart($right); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 1479 | $parser->symbol($right)->counterpart($left); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1479 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | # the low-level tokenizer. Don't use it directly, use advance() instead. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 130790 | ▶ | sub tokenize { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tokenize: called CC=6 SCAR=17.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 130790 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 130790 | local *_ = \$parser->{input}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 130790 | my $comment_rx = $parser->comment_pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 130790 | my $id_rx = $parser->identity_pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 130790 | my $count = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | TRY: { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 130790 | /\G (\s*) /xmsgc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 130882 | $count += ( $1 =~ tr/\n/\n/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 130882 | $parser->following_newline( $count ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 130882 | ▶ | if(/\G $comment_rx /xmsgc) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 92 | redo TRY; # retry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | elsif(/\G ($id_rx)/xmsgc){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 39376 | return [ name => $1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | elsif(/\G ($NUMBER | $STRING)/xmsogc){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 35471 | return [ literal => $1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | elsif(/\G ($OPERATOR_TOKEN)/xmsogc){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 48993 | return [ operator => $1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | elsif(/\G (\S+)/xmsgc) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | Carp::confess("Oops: Unexpected token '$1'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | else { # empty | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 6950 | return [ special => '(end)' ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 39454 | ▶ | sub next_token_is { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_token_is: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 39454 | my($parser, $token) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 39454 | return $parser->next_token->[1] eq $token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # the high-level tokenizer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 130732 | ▶ | sub advance { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
advance: called CC=9 SCAR=22.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 130732 | my($parser, $expect) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 130732 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 130732 | ▶ | if(defined($expect) && $t->id ne $expect) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $expect and $t->id ne $expect
MC/DC100%2/2
defined $expect and $t->id ne $expect
defined $expect
$t->id ne $expect
Truth table100%3/3
A and B
A= defined $expectB= $t->id ne $expect
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 14 | $parser->_unexpected(neat($expect), $t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 130718 | $parser->near_token($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 130718 | my $stash = $parser->symbol_table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 130718 | $t = $parser->next_token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 130718 | ▶ | if($t->[0] eq 'special') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 6952 | return $parser->token( $stash->{ $t->[1] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 123766 | $parser->statement_is_finished( $parser->following_newline != 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 123766 | my $line = $parser->line( $parser->line + $parser->following_newline ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 123766 | $parser->next_token( $parser->tokenize() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 123766 | my($arity, $id) = @{$t}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 123766 | ▶ | if( $arity eq "name" && $parser->next_token_is("=>") ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$arity eq "name" and $parser->next_token_is("=>")
MC/DC100%2/2
$arity eq "name" and $parser->next_token_is("=>")
$arity eq "name"
$parser->next_token_is("=>")
Truth table100%3/3
A and B
A= $arity eq "name"B= $parser->next_token_is("=>")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 130 | $arity = "literal"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 123766 | print STDOUT "[$arity => $id] #$line\n" if _DUMP_TOKEN; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 123766 | my $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 123766 | ▶ | if($arity eq "literal") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 35599 | $symbol = $parser->symbol('(literal)')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | id => $id, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | value => $parser->parse_literal($id) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | elsif($arity eq "operator") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 48935 | $symbol = $stash->{$id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 48935 | ▶ | if(not defined $symbol) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 6 | $parser->_error("Unknown operator '$id'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 48929 | $symbol = $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | arity => $arity, # to make error messages clearer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | else { # name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | # find_or_create() returns a cloned symbol, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | # so there's not need to clone() here | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 39232 | $symbol = $parser->find_or_create($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 123760 | $symbol->line($line); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 123760 | return $parser->token($symbol); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 35599 | ▶ | sub parse_literal { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_literal: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 35599 | my($parser, $literal) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 35599 | return literal_to_value($literal); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 686 | ▶ | sub nud_name { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_name: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 686 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 686 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | arity => 'name', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 5654 | ▶ | sub nud_variable { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_variable: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 5654 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 5654 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | arity => 'variable', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 35557 | ▶ | sub nud_literal { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_literal: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 35557 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 35557 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | arity => 'literal', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 774 | ▶ | sub default_nud { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_nud: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 774 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 774 | return $symbol->clone(); # as is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | ▶ | sub default_led { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_led: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | $parser->near_token($parser->token); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | $parser->_error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | sprintf 'Missing operator (%s): %s', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | $symbol->arity, $symbol->id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | sub default_std { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_std: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 0 | $parser->near_token($parser->token); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | $parser->_error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | sprintf 'Not a statement (%s): %s', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | $symbol->arity, $symbol->id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 44237 | ▶ | sub expression { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expression: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 44237 | my($parser, $rbp) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 44237 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 44237 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 44237 | my $left = $t->nud($parser); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 44207 | ▶ | while($rbp < $parser->token->lbp) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 3970 | $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 3970 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 3970 | $left = $t->led($parser, $left); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 44171 | return $left; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 24678 | ▶ | sub expression_list { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expression_list: called CC=3 SCAR=11.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 24678 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 24678 | my @list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 24678 | while(1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 35330 | ▶ | if($parser->token->is_value) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 34823 | push @list, $parser->expression(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 35330 | ▶ | if(!$parser->token->is_comma) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 24678 | last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 10652 | $parser->advance(); # comma | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 24678 | return \@list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # for left associative infix operators | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 1789 | ▶ | sub led_infix { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_infix: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 1789 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 1789 | return $parser->binary( $symbol, $left, $parser->expression($symbol->lbp) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 14297 | ▶ | sub infix { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
infix: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 14297 | my($parser, $id, $bp, $led) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 14297 | my $symbol = $parser->symbol($id, $bp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 14297 | ▶ | $symbol->set_led($led || \&led_infix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$led || \&Text::Xslate::Parser::led_infix
MC/DC100%1/1
$led || \&Text::Xslate::Parser::led_infix
$led
Truth table100%2/2
A
A= $led
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 14297 | return $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # for right associative infix operators | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 52 | ▶ | sub led_infixr { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_infixr: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 52 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 52 | return $parser->binary( $symbol, $left, $parser->expression($symbol->lbp - 1) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 493 | ▶ | sub infixr { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
infixr: called CC=2 SCAR=7.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 493 | my($parser, $id, $bp, $led) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 493 | my $symbol = $parser->symbol($id, $bp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 493 | ▶ | $symbol->set_led($led || \&led_infixr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$led || \&Text::Xslate::Parser::led_infixr
MC/DC0%0/1
$led || \&Text::Xslate::Parser::led_infixr
$led
Truth table50%1/2
A
A= $led
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 493 | return $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | # for prefix operators | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 3944 | ▶ | sub prefix { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prefix: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 3944 | my($parser, $id, $bp, $nud) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 3944 | my $symbol = $parser->symbol($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 3944 | $symbol->ubp($bp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 3944 | ▶ | $symbol->set_nud($nud || \&nud_prefix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$nud || \&Text::Xslate::Parser::nud_prefix
MC/DC100%1/1
$nud || \&Text::Xslate::Parser::nud_prefix
$nud
Truth table100%2/2
A
A= $nud
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 3944 | return $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 102 | ▶ | sub nud_prefix { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_prefix: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 102 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 102 | my $un = $symbol->clone(arity => 'unary'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 102 | $parser->reserve($un); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 102 | $un->first($parser->expression($symbol->ubp)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 100 | return $un; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 22 | ▶ | sub led_assignment { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_assignment: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 22 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 22 | $parser->_error("Assignment ($symbol) is forbidden", $left); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 3720 | ▶ | sub assignment { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assignment: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 3720 | my($parser, $id, $bp) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 3720 | $parser->symbol($id, $bp)->set_led(\&led_assignment); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 3720 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # the ternary is a right associative operator | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 232 | ▶ | sub led_ternary { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_ternary: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 232 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 232 | my $if = $symbol->clone(arity => 'if'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 232 | $if->first($left); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 232 | $if->second([$parser->expression( $symbol->lbp - 1 )]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 228 | $parser->advance(":"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 228 | $if->third([$parser->expression( $symbol->lbp - 1 )]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 228 | return $if; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 949 | ▶ | sub is_valid_field { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid_field: called CC=3 SCAR=11.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 949 | my($parser, $token) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 949 | my $arity = $token->arity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 949 | ▶ | if($arity eq "name") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 874 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | elsif($arity eq "literal") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 18 | return is_int($token->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 57 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 949 | ▶ | sub led_dot { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_dot: called CC=3 SCAR=11.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 949 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 949 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 949 | ▶ | if(!$parser->is_valid_field($t)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | $parser->_unexpected("a field name", $t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 949 | my $dot = $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | arity => "field", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | first => $left, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | second => $t->clone(arity => 'literal'), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 949 | $t = $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 949 | ▶ | if($t->id eq "(") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 493 | $parser->advance(); # "(" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 493 | $dot->third( $parser->expression_list() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 493 | $parser->advance(")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 493 | $dot->arity("methodcall"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 949 | return $dot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 180 | ▶ | sub led_fetch { # $h[$field] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_fetch: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 180 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 180 | my $fetch = $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | arity => "field", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | first => $left, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | second => $parser->expression(0), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 180 | $parser->advance("]"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 180 | return $fetch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 406 | ▶ | sub call { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 406 | my($parser, $function, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 406 | ▶ | if(not ref $function) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 8 | $function = $parser->symbol('(name)')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | arity => 'name', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | id => $function, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | line => $parser->line, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 406 | return $parser->symbol('(call)')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | arity => 'call', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | first => $function, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | second => \@args, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 592 | ▶ | sub led_call { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_call: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 592 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 592 | my $call = $symbol->clone(arity => 'call'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 592 | $call->first($left); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 592 | $call->second( $parser->expression_list() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 592 | $parser->advance(")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 590 | return $call; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 130 | ▶ | sub led_pipe { # filter | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_pipe: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 130 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | # a | b -> b(a) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 130 | return $parser->call($parser->expression($symbol->lbp), $left); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 14 | ▶ | sub led_range { # x .. y | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
led_range: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 14 | my($parser, $symbol, $left) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 14 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | arity => 'range', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | first => $left, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | second => $parser->expression(0), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 52 | ▶ | sub nil { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nil: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 52 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 52 | return $parser->symbol('nil')->nud($parser); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 46 | ▶ | sub nud_defined { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_defined: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 46 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 46 | $parser->reserve( $symbol->clone() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | # prefix:<defined> is a syntactic sugar to $a != nil | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 46 | return $parser->binary( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | '!=', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | $parser->expression($symbol->ubp), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | $parser->nil, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | # for special literals (e.g. nil, true, false) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 340 | ▶ | sub nud_special { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_special: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 340 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 340 | return $symbol->first; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 1479 | ▶ | sub define_literal { # special literals | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define_literal: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 1479 | my($parser, $id, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 1479 | my $symbol = $parser->symbol($id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 1479 | ▶ | $symbol->first( $symbol->clone( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | arity => defined($value) ? 'literal' : 'nil', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | value => $value, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 1479 | $symbol->set_nud(\&nud_special); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 1479 | $symbol->is_defined(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 1479 | return $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 1868 | ▶ | sub new_scope { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_scope: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 1868 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 1868 | push @{ $parser->scope }, {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 1868 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 1834 | ▶ | sub pop_scope { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pop_scope: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 1834 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 1834 | pop @{ $parser->scope }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 1834 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 7427 | ▶ | sub undefined_name { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
undefined_name: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 7427 | my($parser, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 7427 | ▶ | if($name =~ /\A \$/xms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 5815 | return $parser->symbol_table->{'(variable)'}->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | id => $name, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 1612 | return $parser->symbol_table->{'(name)'}->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | id => $name, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 39350 | ▶ | sub find_or_create { # find a name from all the scopes | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_or_create: called CC=4 SCAR=13.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 39350 | my($parser, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 39350 | my $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 39350 | foreach my $scope(reverse @{$parser->scope}){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 45819 | $s = $scope->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 45819 | ▶ | if(defined $s) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 12064 | return $s->clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 27286 | $s = $parser->symbol_table->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 27286 | ▶ | return defined($s) ? $s : $parser->undefined_name($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 27862 | ▶ | sub reserve { # reserve a name to the scope | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reserve: called CC=6 SCAR=20.7
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 27862 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 27862 | ▶ | if($symbol->arity ne 'name' or $symbol->is_reserved) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$symbol->arity ne "name" or $symbol->is_reserved
MC/DC100%2/2
$symbol->arity ne "name" or $symbol->is_reserved
$symbol->arity ne "name"
$symbol->is_reserved
Truth table100%3/3
A or B
A= $symbol->arity ne "name"B= $symbol->is_reserved
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 26680 | return $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 1182 | my $top = $parser->scope->[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 1182 | my $t = $top->{$symbol->id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 1182 | ▶ | if($t) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | ▶ | if($t->is_reserved) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | return $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | if($t->arity eq "name") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | $parser->_error("Already defined: $symbol"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 1182 | $top->{$symbol->id} = $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 1182 | $symbol->is_reserved(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | #$symbol->scope($top); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 1182 | return $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 1226 | ▶ | sub define { # define a name to the scope | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define: called CC=3 SCAR=11.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 1226 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 1226 | my $top = $parser->scope->[-1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 1226 | my $t = $top->{$symbol->id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 1226 | ▶ | if(defined $t) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 2 | ▶ | $parser->_error($t->is_reserved ? "Already is_reserved: $t" : "Already defined: $t"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 1224 | $top->{$symbol->id} = $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 1224 | $symbol->is_defined(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 1224 | $symbol->is_reserved(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 1224 | $symbol->remove_nud(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 1224 | $symbol->remove_led(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 1224 | $symbol->remove_std(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 1224 | $symbol->lbp(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | #$symbol->scope($top); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 1224 | return $symbol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 2538 | ▶ | sub print { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 2538 | my($parser, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 2538 | return $parser->symbol('print')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | arity => 'print', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | first => \@args, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | line => $parser->line, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 2051 | ▶ | sub binary { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
binary: called CC=4 SCAR=14.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 2051 | my($parser, $symbol, $lhs, $rhs) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 2051 | ▶ | if(!ref $symbol) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | # operator | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 218 | $symbol = $parser->symbol($symbol); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 2051 | ▶ | if(!ref $lhs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | # literal | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | $lhs = $parser->symbol('(literal)')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | id => $lhs, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 2051 | ▶ | if(!ref $rhs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | # literal | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 78 | $rhs = $parser->symbol('(literal)')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | id => $rhs, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 2051 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | arity => 'binary', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | first => $lhs, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | second => $rhs, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 1017 | ▶ | sub define_function { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define_function: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 1017 | my($parser, @names) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 1017 | foreach my $name(@names) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 12350 | my $s = $parser->symbol($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 12350 | $s->set_nud(\&nud_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 12350 | $s->is_defined(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 1017 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 28411 | ▶ | sub finish_statement { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish_statement: called CC=5 SCAR=16.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 28411 | my($parser, $expr) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 28411 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 28411 | ▶ | if($t->can_be_modifier) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 60 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 60 | $expr = $t->std($parser, $expr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 60 | $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 28411 | ▶ | if($t->is_block_end or $parser->statement_is_finished) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$t->is_block_end or $parser->statement_is_finished
MC/DC100%2/2
$t->is_block_end or $parser->statement_is_finished
$t->is_block_end
$parser->statement_is_finished
Truth table100%3/3
A or B
A= $t->is_block_endB= $parser->statement_is_finished
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | # noop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | elsif($t->id eq ";") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 25503 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 8 | $parser->_unexpected("a semicolon or block end", $t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 28399 | return $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 30990 | ▶ | sub statement { # process one or more statements | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
statement: called CC=3 SCAR=11.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 30990 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 30990 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 30990 | ▶ | if($t->id eq ";"){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 914 | $parser->advance(); # ";" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 914 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 30076 | ▶ | if($t->has_std) { # is $t a statement? | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 27538 | $parser->reserve($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 27538 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | # std() can return a list of nodes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 27538 | return $t->std($parser); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 2538 | my $expr = $parser->auto_command( $parser->expression(0) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 2486 | return $parser->finish_statement($expr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 2486 | ▶ | sub auto_command { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto_command: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 2486 | my($parser, $expr) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 2486 | ▶ | if($expr->is_statement) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | # expressions can produce pure statements (e.g. assignment ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 164 | return $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 2322 | return $parser->print($expr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 8793 | ▶ | sub statements { # process statements | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
statements: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 8793 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 8793 | my @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 8793 | ▶ | for(my $t = $parser->token; !$t->is_block_end; $t = $parser->token) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 30890 | push @a, $parser->statement(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 8691 | return \@a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 426 | ▶ | sub block { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
block: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 426 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 426 | $parser->new_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | 426 | $parser->advance("{"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 426 | my $a = $parser->statements(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 426 | $parser->advance("}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 424 | $parser->pop_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 424 | return $a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 254 | ▶ | sub nud_paren { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_paren: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 254 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 254 | my $expr = $parser->expression(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 254 | $parser->advance( $symbol->counterpart ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | 254 | return $expr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | # for object literals | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | 308 | ▶ | sub nud_brace { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_brace: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 308 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 308 | my $list = $parser->expression_list(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 308 | $parser->advance($symbol->counterpart); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 308 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | arity => 'composer', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | first => $list, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | # iterator variables ($~iterator) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | # $~iterator . NAME | NAME() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 110 | ▶ | sub nud_iterator { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_iterator: called CC=5 SCAR=16.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 110 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 110 | my $iterator = $symbol->clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 110 | ▶ | if($parser->token->id eq ".") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 102 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 102 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 102 | ▶ | if(!any_in($t->arity, qw(variable name))) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | $parser->_unexpected("a field name", $t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 102 | my $generator = $parser->iterator_element->{$t->value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 102 | ▶ | if(!$generator) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 0 | $parser->_error("Undefined iterator element: $t"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 102 | $parser->advance(); # element name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 102 | my $args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 102 | ▶ | if($parser->token->id eq "(") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 30 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 30 | $args = $parser->expression_list(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 30 | $parser->advance(")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | 102 | $iterator->second($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 102 | return $generator->($parser, $iterator, @{$args}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 8 | return $iterator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 142 | ▶ | sub nud_constant { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_constant: called CC=4 SCAR=14.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 142 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 142 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 142 | ▶ | my $expect = $symbol->id eq 'constant' ? 'name' | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | : $symbol->id eq 'my' ? 'variable' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | : die "Oops: $symbol"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 142 | ▶ | if($t->arity ne $expect) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 0 | $parser->_unexpected("a $expect", $t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 142 | $parser->define($t)->arity("name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 140 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | 140 | $parser->advance("="); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 140 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | arity => 'constant', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | first => $t, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | second => $parser->expression(0), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | is_statement => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | 357 | my $lambda_id = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | 130 | ▶ | sub lambda { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lambda: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 130 | my($parser, $proto) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 130 | my $name = $parser->symbol('(name)')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | id => sprintf('lambda@%s:%d', $parser->file, $lambda_id++), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 130 | return $parser->symbol('(name)')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | arity => 'proc', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | id => 'macro', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | first => $name, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | line => $proto->line, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | # -> $x { ... } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 86 | ▶ | sub nud_lambda { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_lambda: called CC=6 SCAR=18.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 86 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 86 | my $pointy = $parser->lambda($symbol); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 86 | $parser->new_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 86 | my @params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 86 | ▶ | if($parser->token->id ne "{") { # has params | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 86 | my $paren = ($parser->token->id eq "("); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | 86 | ▶ | $parser->advance("(") if $paren; # optional | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 86 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 86 | ▶ | while($t->arity eq "variable") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 118 | push @params, $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 118 | $parser->define($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 118 | $t = $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 118 | ▶ | if($t->id eq ",") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 32 | $t = $parser->advance(); # "," | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 86 | last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 86 | ▶ | $parser->advance(")") if $paren; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 86 | $pointy->second( \@params ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 86 | $parser->advance("{"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | 86 | $pointy->third($parser->statements()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 86 | $parser->advance("}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 86 | $parser->pop_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | 86 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | arity => 'lambda', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | first => $pointy, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 2 | ▶ | sub nud_current_file { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_current_file: called CC=2 SCAR=7.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 2 | my($self, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 2 | my $file = $self->file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 2 | ▶ | return $symbol->clone( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | arity => 'literal', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | value => ref($file) ? '<string>' : $file, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | 28 | ▶ | sub nud_current_line { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_current_line: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 28 | my($self, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 28 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | arity => 'literal', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | value => $symbol->line, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | 10 | ▶ | sub nud_current_vars { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_current_vars: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 10 | my($self, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | 10 | return $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | arity => 'vars', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | 8 | ▶ | sub nud_separator { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nud_separator: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 8 | my($self, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 8 | $self->_error("Invalid expression found", $symbol); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | # -> VARS { STATEMENTS } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | # -> { STATEMENTS } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | # { STATEMENTS } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | 896 | ▶ | sub pointy { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pointy: called CC=8 SCAR=20.8
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | 896 | my($parser, $pointy, $in_for) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 896 | my @params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | 896 | $parser->new_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 896 | ▶ | if($parser->token->id eq "->") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | 856 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | 856 | ▶ | if($parser->token->id ne "{") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | 462 | my $paren = ($parser->token->id eq "("); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | 462 | ▶ | $parser->advance("(") if $paren; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | 462 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | 462 | ▶ | while($t->arity eq "variable") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 474 | push @params, $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | 474 | $parser->define($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 474 | ▶ | if($in_for) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 310 | $parser->define_iterator($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | 474 | $t = $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | 474 | ▶ | if($t->id eq ",") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 14 | $t = $parser->advance(); # "," | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 460 | last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 462 | ▶ | $parser->advance(")") if $paren; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 892 | $pointy->second( \@params ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | 892 | $parser->advance("{"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 888 | $pointy->third($parser->statements()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | 868 | $parser->advance("}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 868 | $parser->pop_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 868 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 310 | ▶ | sub iterator_name { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_name: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 310 | my($parser, $var) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | # $foo -> $~foo | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 310 | (my $it_name = $var->id) =~ s/\A (\$?) /${1}~/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | 310 | return $it_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 380 | ▶ | sub define_iterator { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
define_iterator: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | 380 | my($parser, $var) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | 380 | my $it = $parser->symbol( $parser->iterator_name($var) )->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | arity => 'iterator', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | first => $var, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | 380 | $parser->define($it); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 380 | $it->set_nud(\&nud_iterator); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 380 | return $it; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | 310 | ▶ | sub std_for { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_for: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 310 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | 310 | my $proc = $symbol->clone(arity => 'for'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 310 | $proc->first( $parser->expression(0) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | 310 | $parser->pointy($proc, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | # for-else support | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | 290 | ▶ | if($parser->token eq 'else') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 10 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | 10 | my $else = $parser->block(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | 10 | $proc = $symbol->clone( arity => 'for_else', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | first => $proc, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | second => $else, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | 290 | return $proc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | 30 | ▶ | sub std_while { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_while: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | 30 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | 30 | my $proc = $symbol->clone(arity => 'while'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | 30 | $proc->first( $parser->expression(0) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | 30 | $parser->pointy($proc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | 30 | return $proc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | # macro name -> { ... } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | 304 | ▶ | sub std_proc { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_proc: called CC=2 SCAR=7.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | 304 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | 304 | my $macro = $symbol->clone(arity => "proc"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | 304 | my $name = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | 304 | ▶ | if($name->arity ne "name") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | 0 | $parser->_unexpected("a name", $name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | 304 | $parser->define_function($name->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | 304 | $macro->first($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | 304 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | 304 | $parser->pointy($macro); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | 296 | return $macro; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | # block name -> { ... } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | # block name | filter -> { ... } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | 192 | ▶ | sub std_macro_block { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_macro_block: called CC=8 SCAR=20.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | 192 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | 192 | my $macro = $symbol->clone(arity => "proc"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | 192 | my $name = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | 192 | ▶ | if($name->arity ne "name") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 0 | $parser->_unexpected("a name", $name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | # auto filters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | 192 | my @filters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | 192 | my $t = $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | 192 | ▶ | while($t->id eq "|") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | 22 | $t = $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | 22 | ▶ | if($t->arity ne "name") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 0 | $parser->_unexpected("a name", $name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | 22 | my $filter = $t->clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | 22 | $t = $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | 22 | my $args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | 22 | ▶ | if($t->id eq "(") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | 4 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | 4 | $args = $parser->expression_list(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | 4 | $t = $parser->advance(")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | push @filters, $args | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | 22 | ▶ | ? $parser->call($filter, @{$args}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | : $filter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | 192 | $parser->define_function($name->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | 192 | $macro->first($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | 192 | $parser->pointy($macro); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | 192 | my $call = $parser->call($macro->first); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | 192 | ▶ | if(@filters) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | 18 | foreach my $filter(@filters) { # apply filters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | 22 | $call = $parser->call($filter, $call); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | # std() can return a list | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | 192 | return( $macro, $parser->print($call) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | 12 | ▶ | sub std_override { # synonym to 'around' | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_override: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | 12 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | 12 | return $parser->std_proc($symbol->clone(id => 'around')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | 226 | ▶ | sub std_if { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_if: called CC=5 SCAR=16.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | 226 | my($parser, $symbol, $expr) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | 226 | my $if = $symbol->clone(arity => "if"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | 226 | $if->first( $parser->expression(0) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | 226 | ▶ | if(defined $expr) { # statement modifier | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | 26 | $if->second([$expr]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | 26 | return $if; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | 200 | $if->second( $parser->block() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | 198 | my $top_if = $if; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 198 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | 198 | ▶ | while($t->id eq "elsif") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | 6 | $parser->reserve($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | 6 | $parser->advance(); # "elsif" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | 6 | my $elsif = $t->clone(arity => "if"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | 6 | $elsif->first( $parser->expression(0) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | 6 | $elsif->second( $parser->block() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | 6 | $if->third([$elsif]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | 6 | $if = $elsif; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | 6 | $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | 198 | ▶ | if($t->id eq "else") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | 112 | $parser->reserve($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | 112 | $t = $parser->advance(); # "else" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | 112 | ▶ | $if->third( $t->id eq "if" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | ? [$parser->statement()] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | : $parser->block()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | 198 | return $top_if; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | 60 | ▶ | sub std_given { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_given: called CC=3 SCAR=11.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | 60 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | 60 | my $given = $symbol->clone(arity => 'given'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | 60 | $given->first( $parser->expression(0) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | 60 | local $parser->{in_given} = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | 60 | $parser->pointy($given); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | 60 | ▶ | if(!(defined $given->second && @{$given->second})) { # if no topic vars | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $given->second and @{$given->second;}
MC/DC50%1/2
defined $given->second and @{$given->second;}
defined $given->second
@{$given->second;}
Truth table66%2/3
A and B
A= defined $given->secondB= @{$given->second;}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | 28 | $given->second([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | $parser->symbol('($_)')->clone(arity => 'variable' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | 60 | $parser->build_given_body($given, "when"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | 60 | return $given; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | # when/default | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | 120 | ▶ | sub std_when { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_when: called CC=3 SCAR=11.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | 120 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | 120 | ▶ | if(!$parser->in_given) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | 0 | $parser->_error("You cannot use $symbol blocks outside given blocks"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | 120 | my $proc = $symbol->clone(arity => 'when'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | 120 | ▶ | if($symbol->id eq "when") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | 62 | $proc->first( $parser->expression(0) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | 120 | $proc->second( $parser->block() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | 120 | return $proc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | 42 | ▶ | sub _only_white_spaces { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_only_white_spaces: called CC=2 SCAR=8.1
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | 42 | my($s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | 42 | ▶ | return $s->arity eq "literal" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$s->arity eq 'literal' && $s->value =~ /\A [ \t\r\n]* \z/msx
MC/DC0%0/2
$s->arity eq 'literal' && $s->value =~ /\A [ \t\r\n]* \z/msx
$s->arity eq 'literal'
$s->value =~ /\A [ \t\r\n]* \z/msx
Truth table33%1/3
A && B
A= $s->arity eq 'literal'B= $s->value =~ /\A [ \t\r\n]* \z/msx
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | && $s->value =~ m{\A [ \t\r\n]* \z}xms | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | 80 | ▶ | sub build_given_body { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_given_body: called CC=11 SCAR=24.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | 80 | my($parser, $given, $expect) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | 80 | my($topic) = @{$given->second}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | # make if-elsif-else chain from given-when | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | 80 | my $if; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | my $elsif; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | 80 | my $else; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | 80 | foreach my $when(@{$given->third}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | 202 | ▶ | if($when->arity ne $expect) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | # ignore white space | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | 44 | ▶ | if($when->id eq "print_raw" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$when->id eq "print_raw" and not grep({not _only_white_spaces($_);} @{$when->first;})
MC/DC50%1/2
$when->id eq "print_raw" and not grep({not _only_white_spaces($_);} @{$when->first;})
$when->id eq "print_raw"
not grep({not _only_white_spaces($_);} @{$when->first;})
Truth table66%2/3
A and not(B)
A= $when->id eq "print_raw"B= not grep({not _only_white_spaces($_);} @{$when->first;})
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | 42 | && !grep { !_only_white_spaces($_) } @{$when->first}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | 42 | next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | 2 | $parser->_unexpected("$expect blocks", $when); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | 158 | $when->arity("if"); # change the arity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | 158 | ▶ | if(defined(my $test = $when->first)) { # when | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | 86 | ▶ | if(!$test->is_logical) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | 62 | $when->first( $parser->binary('~~', $topic, $test) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | else { # default | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | 72 | $when->first( $parser->symbol('true')->nud($parser) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | 72 | $else = $when; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | 72 | next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | 86 | ▶ | if(!defined $if) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | 70 | $if = $when; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | 70 | $elsif = $when; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | 16 | $elsif->third([$when]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | 16 | $elsif = $when; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | 78 | ▶ | if(defined $else) { # default | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | 72 | ▶ | if(defined $elsif) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | 66 | $elsif->third([$else]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | 6 | $if = $else; # only default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | 78 | ▶ | $given->third(defined $if ? [$if] : undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | 78 | return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | 2506 | ▶ | sub std_include { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_include: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | 2506 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | 2506 | my $arg = $parser->barename(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | 2506 | my $vars = $parser->localize_vars(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | 2506 | my $stmt = $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | first => $arg, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | second => $vars, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | arity => 'include', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | 2506 | return $parser->finish_statement($stmt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | 23225 | ▶ | sub std_print { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_print: called CC=2 SCAR=7.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | 23225 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | 23225 | my $args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | 23225 | ▶ | if($parser->token->id ne ";") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | 23225 | $args = $parser->expression_list(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | 23225 | my $stmt = $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1712 | arity => 'print', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1713 | first => $args, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1714 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1715 | 23225 | return $parser->finish_statement($stmt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1716 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1717 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1718 | # for cascade() and include() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1719 | 2680 | ▶ | sub barename { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
barename: called CC=5 SCAR=16.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1720 | 2680 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1721 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1722 | 2680 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1723 | 2680 | ▶ | if($t->arity ne 'name' or $t->is_defined) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$t->arity ne "name" or $t->is_defined
MC/DC100%2/2
$t->arity ne "name" or $t->is_defined
$t->arity ne "name"
$t->is_defined
Truth table100%3/3
A or B
A= $t->arity ne "name"B= $t->is_defined
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1724 | # string literal for 'cascade', or any expression for 'include' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1725 | 2540 | return $parser->expression(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1726 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1727 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1728 | # path::to::name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1729 | 140 | my @parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1730 | 140 | push @parts, $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1731 | 140 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1732 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1733 | 140 | while(1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1734 | 246 | my $t = $parser->token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1735 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1736 | 246 | ▶ | if($t->id eq "::") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1737 | 106 | $t = $parser->advance(); # "::" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1738 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | 106 | ▶ | if($t->arity ne "name") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | 0 | $parser->_unexpected("a name", $t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | 106 | push @parts, $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1744 | 106 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1745 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1746 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1747 | 140 | last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1748 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1749 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1750 | 140 | return \@parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1751 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1752 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1753 | # NOTHING | { expression-list } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1754 | 2602 | ▶ | sub localize_vars { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
localize_vars: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1755 | 2602 | my($parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1756 | 2602 | ▶ | if($parser->token->id eq "{") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1757 | 26 | $parser->advance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1758 | 26 | $parser->new_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1759 | 26 | my $vars = $parser->expression_list(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1760 | 26 | $parser->pop_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1761 | 26 | $parser->advance("}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1762 | 26 | return $vars; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1763 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1764 | 2576 | return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1765 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1766 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1767 | 132 | ▶ | sub std_cascade { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_cascade: called CC=4 SCAR=13.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | 132 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1770 | 132 | my $base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1771 | 132 | ▶ | if($parser->token->id ne "with") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1772 | 118 | $base = $parser->barename(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1773 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1774 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1775 | 132 | my $components; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1776 | 132 | ▶ | if($parser->token->id eq "with") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1777 | 22 | $parser->advance(); # "with" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1778 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1779 | 22 | my @c = $parser->barename(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1780 | 22 | ▶ | while($parser->token->id eq ",") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | 4 | $parser->advance(); # "," | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1782 | 4 | push @c, $parser->barename(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1783 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1784 | 22 | $components = \@c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1785 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1786 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1787 | 132 | my $vars = $parser->localize_vars(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1788 | 132 | my $stmt = $symbol->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1789 | arity => 'cascade', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1790 | first => $base, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1791 | second => $components, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1792 | third => $vars, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1793 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1794 | 132 | return $parser->finish_statement($stmt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1795 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1796 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1797 | 14 | ▶ | sub std_super { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_super: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1798 | 14 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1799 | 14 | my $stmt = $symbol->clone(arity => 'super'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1800 | 14 | return $parser->finish_statement($stmt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1801 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1802 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1803 | 10 | ▶ | sub std_next { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_next: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1804 | 10 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1805 | 10 | my $stmt = $symbol->clone(arity => 'loop_control', id => 'next'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1806 | 10 | return $parser->finish_statement($stmt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1807 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1808 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1809 | 14 | ▶ | sub std_last { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
std_last: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1810 | 14 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1811 | 14 | my $stmt = $symbol->clone(arity => 'loop_control', id => 'last'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1812 | 14 | return $parser->finish_statement($stmt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1813 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1815 | # iterator elements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1816 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1817 | 16 | ▶ | sub bad_iterator_args { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bad_iterator_args: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1818 | 16 | my($parser, $iterator) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1819 | 16 | $parser->_error("Wrong number of arguments for $iterator." . $iterator->second); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1820 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1821 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1822 | 32 | ▶ | sub iterator_index { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_index: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1823 | 32 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1824 | 32 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1825 | # $~iterator | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1826 | 30 | return $iterator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1827 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1828 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1829 | 20 | ▶ | sub iterator_count { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_count: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1830 | 20 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1831 | 20 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1832 | # $~iterator + 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1833 | 18 | return $parser->binary('+', $iterator, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1834 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1835 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1836 | 14 | ▶ | sub iterator_is_first { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_is_first: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1837 | 14 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1838 | 14 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1839 | # $~iterator == 0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1840 | 12 | return $parser->binary('==', $iterator, 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1841 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1842 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1843 | 8 | ▶ | sub iterator_is_last { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_is_last: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1844 | 8 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1845 | 8 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1846 | # $~iterator == $~iterator.max_index | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1847 | 6 | return $parser->binary('==', $iterator, $parser->iterator_max_index($iterator)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1848 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1849 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1850 | 32 | ▶ | sub iterator_body { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_body: called CC=2 SCAR=7.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1851 | 32 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1852 | 32 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1853 | # $~iterator.body | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1854 | 32 | return $iterator->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1855 | arity => 'iterator_body', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1856 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1857 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1858 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1859 | 6 | ▶ | sub iterator_size { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_size: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1860 | 6 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1861 | 6 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1862 | # $~iterator.max_index + 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1863 | 4 | return $parser->binary('+', $parser->iterator_max_index($iterator), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1864 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1865 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1866 | 16 | ▶ | sub iterator_max_index { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_max_index: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1867 | 16 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1868 | 16 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1869 | # __builtin_max_index($~iterator.body) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1870 | 14 | return $parser->symbol('max_index')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1871 | arity => 'unary', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1872 | first => $parser->iterator_body($iterator), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1873 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1874 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1875 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1876 | 12 | ▶ | sub _iterator_peek { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_iterator_peek: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1877 | 12 | my($parser, $iterator, $pos) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1878 | # $~iterator.body[ $~iterator.index + $pos ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1879 | 12 | return $parser->binary('[', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1880 | $parser->iterator_body($iterator), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1881 | $parser->binary('+', $parser->iterator_index($iterator), $pos), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1882 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1883 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1884 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1885 | 6 | ▶ | sub iterator_peek_next { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_peek_next: called CC=2 SCAR=7.1
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1886 | 6 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1887 | 6 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1888 | 6 | return $parser->_iterator_peek($iterator, +1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1889 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1890 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1891 | 10 | ▶ | sub iterator_peek_prev { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_peek_prev: called CC=2 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1892 | 10 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1893 | 10 | ▶ | $parser->bad_iterator_args($iterator) if @args != 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1894 | # $~iterator.is_first ? nil : <prev> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1895 | 6 | return $parser->symbol('?')->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1896 | arity => 'if', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1897 | first => $parser->iterator_is_first($iterator), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1898 | second => [$parser->nil], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1899 | third => [$parser->_iterator_peek($iterator, -1)], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1900 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1901 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1902 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1903 | 12 | ▶ | sub iterator_cycle { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_cycle: called CC=3 SCAR=11.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1904 | 12 | my($parser, $iterator, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1905 | 12 | ▶ | $parser->bad_iterator_args($iterator) if @args < 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1906 | # $iterator.cycle("foo", "bar", "baz") makes: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1907 | # ($tmp = $~iterator % n) == 0 ? "foo" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1908 | # : $tmp == 1 ? "bar" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1909 | # : "baz" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1910 | 12 | $parser->new_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1911 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1912 | 12 | my $mod = $parser->binary('%', $iterator, scalar @args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1913 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1914 | # for the second time | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1915 | 12 | my $tmp = $parser->symbol('($cycle)')->clone(arity => 'name'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1916 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1917 | # for the first time | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1918 | 12 | my $cond = $iterator->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1919 | arity => 'constant', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1920 | first => $tmp, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1921 | second => $mod, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1922 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1923 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1924 | 12 | my $parent = $iterator->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1925 | arity => 'if', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1926 | first => $parser->binary('==', $cond, 0), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1927 | second => [ $args[0] ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1928 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1929 | 12 | my $child = $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1930 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1931 | 12 | my $last = pop @args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1932 | 12 | ▶ | for(my $i = 1; $i < @args; $i++) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1933 | 8 | my $nth = $iterator->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1934 | arity => 'if', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1935 | id => "$iterator.cycle: $i", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1936 | first => $parser->binary('==', $tmp, $i), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1937 | second => [$args[$i]], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1938 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1939 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1940 | 8 | $child->third([$nth]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1941 | 8 | $child = $nth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1942 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1943 | 12 | $child->third([$last]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1944 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1945 | 12 | $parser->pop_scope(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1946 | 12 | return $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1947 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1948 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1949 | # utils | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1950 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1951 | 6682 | ▶ | sub make_alias { # alas(from => to) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_alias: called CC=2 SCAR=7.4
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1952 | 6682 | my($parser, $from, $to) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1953 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1954 | 6682 | my $stash = $parser->symbol_table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1955 | 6682 | ▶ | if(exists $parser->symbol_table->{$to}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1956 | Carp::confess( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1957 | "Cannot make an alias to an existing symbol ($from => $to / " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1958 | 0 | . p($parser->symbol_table->{$to}) .")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1959 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1960 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1961 | # make a snapshot | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1962 | 6682 | return $stash->{$to} = $parser->symbol($from)->clone( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1963 | value => $to, # real id | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1964 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1965 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1966 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1967 | 4 | ▶ | sub not_supported { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
not_supported: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1968 | 4 | my($parser, $symbol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1969 | 4 | $parser->_error("'$symbol' is not supported"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1970 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1971 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1972 | 26 | ▶ | sub _unexpected { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unexpected: called CC=4 SCAR=13.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1973 | 26 | my($parser, $expected, $got) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1974 | 26 | ▶ | if(defined($got) && $got ne ";") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $got and $got ne ";"
MC/DC50%1/2
defined $got and $got ne ";"
defined $got
$got ne ";"
Truth table66%2/3
A and B
A= defined $gotB= $got ne ";"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1975 | 24 | ▶ | if($got eq '(end)') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1976 | 4 | $parser->_error("Expected $expected, but reached EOF"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1977 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1978 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1979 | 20 | $parser->_error("Expected $expected, but got " . neat("$got")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1980 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1981 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1982 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1983 | 2 | $parser->_error("Expected $expected"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1984 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1985 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1986 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1987 | 98 | ▶ | sub _error { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=6 SCAR=18.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1988 | 98 | my($parser, $message, $near, $line) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1989 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1990 | 98 | ▶ | $near ||= $parser->near_token || ";"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition80%4/5
$near ||= $parser->near_token || ";"
$parser->near_token || ';'
MC/DC0%0/2
$near ||= $parser->near_token || ";"
$near
$parser->near_token
Truth table66%2/3
A ||= B
A= $nearB= $parser->near_token
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1991 | 98 | ▶ | if($near ne ";" && $message !~ /\b \Q$near\E \b/xms) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$near ne ";" and not $message =~ /\b \Q$near\E \b/msx
MC/DC100%2/2
$near ne ";" and not $message =~ /\b \Q$near\E \b/msx
$near ne ";"
not $message =~ /\b \Q$near\E \b/msx
Truth table100%3/3
A and not(B)
A= $near ne ";"B= not $message =~ /\b \Q$near\E \b/msx
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1992 | 78 | $message .= ", near $near"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1993 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1994 | 98 | ▶ | die $parser->make_error($message . ", while parsing templates", | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$line || $parser->line
MC/DC0%0/2
$line || $parser->line
$line
$parser->line
Truth table66%2/3
A || B
A= $lineB= $parser->line
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1995 | $parser->file, $line || $parser->line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1996 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1997 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1998 | 357 | ▶ | no Mouse; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1999 | 357 | __PACKAGE__->meta->make_immutable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2000 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||