| 1 | package Perl::ToPerl6::Transformer::BasicTypes::Strings::Interpolation; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use 5.006001; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use List::Util qw( max ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Text::Balanced qw( extract_variable ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use Perl::ToPerl6::Utils qw{ :severities }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use Perl::ToPerl6::Utils::PPI qw{ set_string }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | use base 'Perl::ToPerl6::Transformer'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 17 | Readonly::Scalar my $DESC => q{Rewrite interpolated strings}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 17 | Readonly::Scalar my $EXPL => q{Rewrite interpolated strings}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 38 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 26 | ▶ | sub default_necessity { return $NECESSITY_HIGHEST } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_necessity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 24 | ▶ | sub default_themes { return qw( core ) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | sub applies_to { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | return 'PPI::Token::Quote::Interpolate', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 'PPI::Token::Quote::Double' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # A fairly comprehensive list of edge case handling: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # "\o" --> "o". It's illegal in Perl5, but may be encountered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # "\o" is illegal in Perl5, so it shouldn't be encountered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # "\o1" is illegal in Perl5, so it shouldn't be encountered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # "\0" is legal though. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # "\c" is illegal in Perl5, so it shouldn't be encountered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Tokenizer II: Electric Boogaloo. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Since it'll eventually be needed... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub tokenize { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tokenize: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my ( $str ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my @c = split //, $str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my @token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | for ( my $i = 0; $i < @c; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my ( $v, $la1 ) = @c[ $i, $i + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( $v eq '\\' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( $la1 eq 'c' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | elsif ( $la1 eq 'l' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | elsif ( $la1 eq 'u' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | elsif ( $la1 eq 'E' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | elsif ( $la1 eq 'F' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | elsif ( $la1 eq 'L' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | elsif ( $la1 eq 'Q' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | elsif ( $la1 eq 'U' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | elsif ( $v eq '$' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | elsif ( $v eq '@' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif ( $v eq '%' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | elsif ( $v eq '{' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | elsif ( $v eq '}' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | elsif ( $v eq '(' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | elsif ( $v eq ')' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | elsif ( $v eq '<' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ( $v eq '>' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return @token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Some more cases get folded away here (hee.) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # \U foo \L\E bar \E - 'bar' will get altered here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # \U foo \L$x\E bar \E - 'bar' will *not* get altered here, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # even if $x is empty. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # \U foo \Lxxx\E bar \E - 'bar' will *not* get altered here, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # So, \L..\E affects the rest of the string only if the contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # are empty. So it's effectively as if it never was there. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Get rid of it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub casefold { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
casefold: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @split = grep { $_ ne '' } split /( \\[luEFLQU] )/x, $text; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my @token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | for ( my $i = 0; $i < @split; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my ($v, $la1) = @split[$i,$i+1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( $v =~ m< ^ \\[FLU] $ >x and | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/6
$v =~ / ^ \\[FLU] $ /x and $la1 and $la1 eq "\\E"
$v =~ / ^ \\[FLU] $ /x and $la1
MC/DC0%0/3
$v =~ / ^ \\[FLU] $ /x and $la1 and $la1 eq "\\E"
$v =~ / ^ \\[FLU] $ /x
$la1
$la1 eq "\\E"
Truth table0%0/4
A and B and C
A= $v =~ / ^ \\[FLU] $ /xB= $la1C= $la1 eq "\\E"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | $la1 and $la1 eq '\\E' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $i+=2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | elsif ( $v eq '\\Q' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | push @token, { type => 'quotemeta', content => $v }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | elsif ( $v =~ m{ \\[luEFLQU] }x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | push @token, { type => 'casefold', content => $v }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | push @token, { type => 'uninterpolated', content => $v }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return @token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # At the end of this process, ideally we should only have these types of tokens: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # Disambiguated variable - '${foo}' (needs separate handling) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Variable - '$foo', '$foo[32]', '$foo{blah}' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Case folding - '\l', '\E' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Quotemeta - '\Q' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Uninterpolated content - Anything that's not one of the above. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub tokenize_variables { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tokenize_variables: not called CC=20 SCAR=60.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my ($self, $elem, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $full_string = $string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my @token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $iter = 100; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | while ( $string ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | unless ( --$iter ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $line_number = $elem->line_number; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | die "Congratulations, you've broken string interpolation. Please report this message, along with the test file you were using to the author: <<$full_string>> on line $line_number\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # '${foo}', '@{foo}' is an interpolated value. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ( $string =~ s< ^ ( [\$\@] ) \{ ( [^}]+ ) \} ><>x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | push @token, { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | type => 'disambiguated variable', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | sigil => $1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | content => $2 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # extract_variable() doesn't handle most 'special' Perl variables, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # so handle them specially. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | elsif ( $string =~ s< ^ ( [\$\@] ) ( \s | [^a-zA-Z] ) }><>x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my ( $sigil, $content ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | while ( $string =~ s< ^ ( \[ [^\]]+ \] ) ><>sx or | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$string =~ s/ ^ ( \[ [^\]]+ \] ) //sx or $string =~ s/ ^ ( \{ [^\}]+ \} ) //sx
MC/DC0%0/2
$string =~ s/ ^ ( \[ [^\]]+ \] ) //sx or $string =~ s/ ^ ( \{ [^\}]+ \} ) //sx
$string =~ s/ ^ ( \[ [^\]]+ \] ) //sx
$string =~ s/ ^ ( \{ [^\}]+ \} ) //sx
Truth table0%0/3
A or B
A= $string =~ s/ ^ ( \[ [^\]]+ \] ) //sxB= $string =~ s/ ^ ( \{ [^\}]+ \} ) //sx
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | $string =~ s< ^ ( \{ [^\}]+ \} ) ><>sx ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $content .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | push @token, { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | type => 'variable', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | sigil => $sigil, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | content => $content | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # Anything else starting with a '$' or '@' is fair game. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | elsif ( $string =~ m< ^ [\$\@] >x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my ( $var_name, $remainder, $prefix ) = | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | extract_variable( $string ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ( $var_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | push @token, { type => 'variable', content => $var_name }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $string = $remainder; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # XXX I"m betting that extract_variable() doesn't catch $] etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | elsif ( $string =~ s< ^ ( [\$\@] [^\$\@]* ) ><>x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ( @token ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $token[-1]{content} .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | push @token, { type => 'variable', content => $1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | die "XXX String interpolation (leading variable) failed on '$string'! Please report this to the author.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Anything that does *not* start with '$' or '@' is its own token, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # at least up until the next '$' or '@' encountered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | elsif ( $string =~ s< ^ ( [^\$\@]+ ) ><>x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $residue = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | while ( $residue and $residue =~ m< \\ $ >x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$residue and $residue =~ / \\ $ /x
MC/DC0%0/2
$residue and $residue =~ / \\ $ /x
$residue
$residue =~ / \\ $ /x
Truth table0%0/3
A and B
A= $residueB= $residue =~ / \\ $ /x
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ( $string =~ s< ^ ( \$\@ ) ><>x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $residue .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $string =~ s< (.) ><>x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $residue .= $1 if $1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ( $string =~ s< ^ ( [^\$\@]+ ) ><>x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $residue .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # Merge the first element of the residue with the last token if | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my @result = $self->casefold($residue); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ( @token and $token[-1]{type} eq 'uninterpolated' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@token and $token[-1]{"type"} eq "uninterpolated"
MC/DC0%0/2
@token and $token[-1]{"type"} eq "uninterpolated"
@token
$token[-1]{"type"} eq "uninterpolated"
Truth table0%0/3
A and B
A= @tokenB= $token[-1]{"type"} eq "uninterpolated"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $token[-1]{content} .= shift(@result)->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | push @token, @result if @result; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | die "XXX String interpolation failed on '$string'! Please report this to the author.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | return grep { $_ ne '' } @token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub transform { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform: not called CC=7 SCAR=38.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my ($self, $elem, $doc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $old_string = $elem->string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $new_string; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ( index( $old_string, '@{[' ) >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | warn "Interpolating perl code."; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # Save the delimiters for later. Since they surrounded the original Perl5 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # string, we can be certain that if we use these for the Perl6 equivalent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # they'll be valid. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # Yes, even in the case of: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # "\lfoo" -> "{lcfirst("f")}oo". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # Perl6 is smart enough to know which segment of the braid it's on, and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # interprets the {..} boundary as a new Perl6 block. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my ( $start_delimiter ) = | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | $elem->content =~ m{ ^ ( qq[ ]. | qq. | q[ ]. | q. | . ) }x; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $end_delimiter = substr( $elem->content, -1, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # \l or \u followed *directly* by any \l or \u modifier simply ignores | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # the remaining \l or \u modifiers. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $old_string =~ s{ (\\[lu]) (\\[lu])+ }{$1}gx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # \F, \L or \U followed *directly* by any \F, \L or \U modifier is a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # syntax error in Perl5, and can be reduced to a single \F, \L or \U. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $old_string =~ s{ (\\[FLU]) (\\[FLU])+ }{$1}gx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # \Q followed by anything is still a legal sequence. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # \t is unchanged in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # \n is unchanged in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # \r is unchanged in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # \f is unchanged in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # \b is unchanged in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # \a is unchanged in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # \e is unchanged in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # \v is deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $old_string =~ s{ \\v }{v}mgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # \x{263a} now looks like \x[263a]. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $old_string =~ s{ \\x \{ ([0-9a-fA-F]+) \} }{\\x[$1]}mgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # \x12 is unaltered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # \x1L is unaltered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # '..\x' is illegal in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $old_string =~ s{ \\x $ }{}mx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # \N{U+1234} is now \x[1234]. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # Variants with whitespace are illegal in Perl5, so don't worry about 'em | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $old_string =~ s{ \\N \{ U \+ ([0-9a-fA-F]+) \} }{\\x[$1]}mgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # \N{LATIN CAPITAL LETTER X} is now \c[LATIN CAPITAL LETTER X] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $old_string =~ s{ \\N \{ ([^\}]+) \} }{\\c[$1]}mgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # \o{2637} now looks like \o[2637]. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # \o12 is unaltered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $old_string =~ s{ \\o \{ ([0-7]*) \) }{\\o[$1]}mgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # \0123 is now \o[123]. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $old_string =~ s{ \\0 \{ ([0-7]*) \) }{\\o[$1]}mgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # \oL is now illegal, and in perl5 it generated nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # "...\o" is a syntax error in both languages, so don't worry about it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $old_string =~ s{ \\o \{ ([^\}]*) \} }{\\o[$1]}mgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # \c. is unchanged. Or at least I'll treat it as such. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # At this point, you'll notice that practically every '{' and '}' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # character is out of our target string, with trivial exceptions like | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # 'c{', which is illegal anyway. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # This is important for two main reasons. The first is that anything inside | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # {} in Perl6 is considered valid Perl6 code, which is also why a trick | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # we use later works. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # So, unless {} are part of a variable that can be interpolated, we have | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # to escape it. And we can't do that if there are constructs like \x{123} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # hanging around in the string, because those would get messed up. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my @token = $self->tokenize_variables($elem,$old_string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | #use YAML;warn Dump grep { $_->{type} eq 'a' } @token; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # Now on to rewriting \l, \u, \E, \F, \L, \Q, \U in Perl6. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # \F, \L, \Q and \U are "sort of" nested. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # You can see this by running C<print "Start \L lOWER \U Upper Me \E mE \E"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # > Start lower UPPER ME mE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # Note how 'lOWER' is case-flattend, but after the \U..E, 'mE' isn't? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # So, rather than having to retain case settings, we can simply stop the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # lc(..) block after the first... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $new_content; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | for ( my $i = 0; $i < @token; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my ( $v, $la1 ) = @token[$i,$i+1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # '${a}' is mapped to '{$a}'. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | # '${$a}' is a varvar in Perl5, needs other techniques in perl6 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if ( $v->{type} eq 'disambiguated variable' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ( $v->{content} =~ m{ ^ ( \$ | \@ ) }x ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | warn "Use of varvar in string, not translating.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $v->{content} = $v->{sigil} . '{' . $v->{content} . '}'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $v->{content} =~ s< [-][\>] ><.>gx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $v->{content} =~ s< \{ (\w+) (\s*) \} >< '{' . | |||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | $start_delimiter . $1 . | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | $end_delimiter . $2 . | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | '}'>segx; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $v->{content} = '{' . $v->{sigil} . $v->{content} . '}'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # All the other variables, including those with {} and [] indices, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # are grouped in this category. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | elsif ( $v->{type} eq 'variable' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $v->{content} =~ s< [-][\>] ><.>gx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $v->{content} =~ s< \{ (\w+) (\s*) \} >< '{' . | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | $start_delimiter . $1 . | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | $end_delimiter . $2 . | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | '}'>segx; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $v->{content} =~ s< ^ ( [(<>)] ) ><\\$1>sgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $v->{content} =~ s< ( [^\\] ) ( [(<>)] ) ><$1\\$2>sgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # Non-variables are handled down here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # < > is now a pointy block, { } is now a code block, ( ) is also | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # used. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $v->{content} =~ s< ^ ( [{(<>)}] ) ><\\$1>sgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $v->{content} =~ s< ( [^\\] ) ( [{(<>)}] ) ><$1\\$2>sgx; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $new_content .= $v->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # elsif ( $v eq '\\F' or $v eq '\\L' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # $collected .= '{' if @manip == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # if ( @manip == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # $collected .= 'lc(' . $start_delimiter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # $collected .= $end_delimiter . ')~lc(' . $start_delimiter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # push @manip, $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # elsif ( $v eq '\\Q' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # $collected .= '{' if @manip == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # if ( @manip == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # $collected .= 'quotemeta(' . $start_delimiter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # $collected .= $end_delimiter . ')~quotemeta(' . $start_delimiter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # push @manip, $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # elsif ( $v eq '\\U' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # $collected .= '{' if @manip == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # if ( @manip == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # $collected .= 'tc(' . $start_delimiter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # $collected .= $end_delimiter . ')~tc(' . $start_delimiter; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # push @manip, $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # elsif ( $v eq '\\E' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # pop @manip; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # if ( @manip == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # $collected .= $end_delimiter . ')}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | # else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # $collected .= $end_delimiter . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | set_string($elem,$new_content); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | use YAML;die "set_string broke! Please report this: ".Dump($elem); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | return $self->transformation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||