-########################################################################
+#######################################################################
#
# the Perl::Tidy::Tokenizer package is essentially a filter which
# reads lines of perl source code from a source object and provides
return unless ( $tokenizer_self->{'_extended_syntax'} );
if ( $type eq ':' ) {
- my ( $next_nonblank_token, $i_next ) =
- find_next_nonblank_token( $i + 1, $rtokens, $max_token_index );
# Look for Switch::Plain syntax; some examples
# case 1: {
# default: {
# default:
- # This should be enough to identify this syntax. If necessary, we
- # could also look for and require 'use Switch::Plain', but then
- # perltidy would fail if run on small snippets in an editor.
+ # Note that the line 'default:' will be parsed as a label elsewhere.
+
if ( $statement_type eq 'case' || $statement_type eq 'default' ) {
# The type will be the same as a label
}
# if an error would otherwise occur, check for extended syntax
- elsif ( !$current_depth[QUESTION_COLON]
+ elsif ( !is_balanced_closing_container(QUESTION_COLON)
&& $extended_syntax_type->() )
{
return ( $seqno, $indent );
}
+sub is_balanced_closing_container {
+
+ # Return true if a closing container can go here without error
+ # Return false if not
+ my ($aa) = @_;
+
+ # cannot close if there was no opening
+ return unless ( $current_depth[$aa] > 0 );
+
+ # check that any other brace types $bb contained within would be balanced
+ for my $bb ( 0 .. @closing_brace_names - 1 ) {
+ next if ( $bb == $aa );
+ return
+ unless ( $depth_array[$aa][$bb][ $current_depth[$aa] ] ==
+ $current_depth[$bb] );
+ }
+
+ # OK, everything will be balanced
+ return 1;
+}
+
sub decrease_nesting_depth {
my ( $aa, $pos ) = @_;
-# must run with -nola to keep default from outdenting
+# run with -nola to keep default from outdenting
use Switch::Plain;
my $r = 'fail';
my $x = int rand 100_000;
$r = 'ok';
}
}
-my @words = qw(speed me towards death);
-$r = do {
+
+my @words = qw(cinnamon ginger nutmeg cloves);
+my $test = 1;
+$r = $test
+ ? do {
sswitch( $words[ rand @words ] ) {
case $words[0]:
case $words[1]:
case $words[2]:
case $words[3]: { 'ok' }
- default: { 'wtf' }
+ default: { 'default case' }
}
-};
+ }
+ : 'not ok';
-# must run with -nola to keep default from outdenting
+# run with -nola to keep default from outdenting
use Switch::Plain;
my $r = 'fail';
my $x = int rand 100_000;
$r = 'ok';
}
}
-my @words = qw(speed me towards death);
-$r = do {
+
+my @words = qw(cinnamon ginger nutmeg cloves);
+my $test = 1;
+$r = $test
+ ? do {
sswitch( $words[ rand @words ] ) {
case $words[0]:
case $words[1]:
case $words[2]:
case $words[3]: { 'ok' }
- default: { 'wtf' }
+ default: { 'default case' }
}
-};
+ }
+ : 'not ok';
../snippets20.t hanging_side_comments3.def
../snippets20.t lop.def
../snippets21.t lop.lop
+../snippets21.t switch_plain.def
+../snippets21.t switch_plain.switch_plain
../snippets3.t ce_wn1.ce_wn
../snippets3.t ce_wn1.def
../snippets3.t colin.colin
../snippets9.t rt98902.def
../snippets9.t rt98902.rt98902
../snippets9.t rt99961.def
-../snippets21.t switch_plain.def
-../snippets21.t switch_plain.switch_plain
-# must run with -nola to keep default from outdenting
+# run with -nola to keep default from outdenting
use Switch::Plain;
my $r = 'fail';
my $x = int rand 100_000;
$r = 'ok';
}
}
-my @words = qw(speed me towards death);
-$r = do {
- sswitch ($words[rand @words]) {
+
+my @words = qw(cinnamon ginger nutmeg cloves);
+my $test = 1;
+$r = $test
+ ? do {
+ sswitch( $words[ rand @words ] ) {
case $words[0]:
case $words[1]:
case $words[2]:
case $words[3]: { 'ok' }
- default: { 'wtf' }
+ default: { 'default case' }
}
-};
+ }
+ : 'not ok';
----------
'switch_plain' => <<'----------',
-# must run with -nola to keep default from outdenting
+# run with -nola to keep default from outdenting
use Switch::Plain;
my $r = 'fail';
my $x = int rand 100_000;
$r = 'ok';
}
}
-my @words = qw(speed me towards death);
-$r = do {
- sswitch ($words[rand @words]) {
+
+my @words = qw(cinnamon ginger nutmeg cloves);
+my $test = 1;
+$r = $test
+ ? do {
+ sswitch( $words[ rand @words ] ) {
case $words[0]:
case $words[1]:
case $words[2]:
case $words[3]: { 'ok' }
- default: { 'wtf' }
+ default: { 'default case' }
}
-};
+ }
+ : 'not ok';
----------
};
source => "switch_plain",
params => "def",
expect => <<'#2...........',
-# must run with -nola to keep default from outdenting
+# run with -nola to keep default from outdenting
use Switch::Plain;
my $r = 'fail';
my $x = int rand 100_000;
$r = 'ok';
}
}
-my @words = qw(speed me towards death);
-$r = do {
+
+my @words = qw(cinnamon ginger nutmeg cloves);
+my $test = 1;
+$r = $test
+ ? do {
sswitch( $words[ rand @words ] ) {
case $words[0]:
case $words[1]:
case $words[2]:
case $words[3]: { 'ok' }
- default: { 'wtf' }
+ default: { 'default case' }
}
-};
+ }
+ : 'not ok';
#2...........
},
source => "switch_plain",
params => "switch_plain",
expect => <<'#3...........',
-# must run with -nola to keep default from outdenting
+# run with -nola to keep default from outdenting
use Switch::Plain;
my $r = 'fail';
my $x = int rand 100_000;
$r = 'ok';
}
}
-my @words = qw(speed me towards death);
-$r = do {
+
+my @words = qw(cinnamon ginger nutmeg cloves);
+my $test = 1;
+$r = $test
+ ? do {
sswitch( $words[ rand @words ] ) {
case $words[0]:
case $words[1]:
case $words[2]:
case $words[3]: { 'ok' }
- default: { 'wtf' }
+ default: { 'default case' }
}
-};
+ }
+ : 'not ok';
#3...........
},
};