# A sub to store one token in the new array
# All new tokens must be stored by this sub so that it can update
# all data structures on the fly.
- my $last_nonblank_type = ';';
- my $store_token = sub {
+ my $last_nonblank_type = ';';
+ my $last_nonblank_token = ';';
+ my $last_nonblank_block_type = '';
+ my $store_token = sub {
my ($item) = @_;
# This will be the index of this item in the new array
$item->[_CUMULATIVE_LENGTH_] = $cumulative_length;
my $type = $item->[_TYPE_];
- if ( $type ne 'b' ) { $last_nonblank_type = $type }
+ if ( $type && $type ne 'b' && $type ne '#' ) {
+ $last_nonblank_type = $type;
+ $last_nonblank_token = $item->[_TOKEN_];
+ $last_nonblank_block_type = $item->[_BLOCK_TYPE_];
+ }
# and finally, add this item to the new array
push @{$rLL_new}, $item;
# $check_Q->($KK, $Kfirst);
}
+ # handle semicolons
+ elsif ( $type eq ';' ) {
+
+ # Remove unnecessary semicolons, but not after bare
+ # blocks, where it could be unsafe if the brace is
+ # mistokenized.
+ if (
+ $rOpts->{'delete-semicolons'}
+ && (
+ (
+ $last_nonblank_type eq '}'
+ && (
+ $is_block_without_semicolon{
+ $last_nonblank_block_type}
+ || $last_nonblank_block_type =~ /$SUB_PATTERN/
+ || $last_nonblank_block_type =~ /^\w+:$/ )
+ )
+ || $last_nonblank_type eq ';'
+ )
+ )
+ {
+
+ my $has_side_comment;
+ if ( $KK < $Klast ) {
+ my $Kn = $self->K_next_nonblank($KK);
+ my $next_nonblank_token_type = "";
+ if ( defined($Kn) && $Kn <= $Klast ) {
+ $next_nonblank_token_type = $rLL->[$Kn]->[_TYPE_];
+ $has_side_comment =
+ $next_nonblank_token_type eq '#';
+ }
+ }
+
+ # don't delete ; before a # because it would promote it
+ # to a block comment
+ if ( !$has_side_comment ) {
+ note_deleted_semicolon();
+ next;
+ }
+ else {
+ write_logfile_entry(
+ "Extra ';' at line $input_line_number\n");
+ }
+ }
+ }
+
elsif ($type_sequence) {
# if ( $is_opening_token{$token} ) {
$line_of_tokens->{_line_text} =~ s/\s+$//;
}
$line_of_tokens->{_rK_range} = [ $Kfirst, $Klast ];
+
+ # Deleting semicolons can create new empty code lines
+ # which should be marked as blank
+ if ( !defined($Kfirst) ) {
+ my $code_type = $line_of_tokens->{_code_type};
+ if ( !$code_type ) {
+ $line_of_tokens->{_code_type} = 'BL';
+ }
+ }
}
}
write_logfile_entry(
" Last at input line $last_deleted_semicolon_at\n");
}
- write_logfile_entry(" (Use -ndsc to prevent semicolon deletion)\n");
+ write_logfile_entry(" (Use -ndsm to prevent semicolon deletion)\n");
write_logfile_entry("\n");
}
destroy_one_line_block();
}
- # Remove unnecessary semicolons, but not after bare
- # blocks, where it could be unsafe if the brace is
- # mistokenized.
- if (
- (
- $last_nonblank_token eq '}'
- && (
- $is_block_without_semicolon{
- $last_nonblank_block_type}
- || $last_nonblank_block_type =~ /$SUB_PATTERN/
- || $last_nonblank_block_type =~ /^\w+:$/ )
- )
- || $last_nonblank_type eq ';'
- )
- {
-
- if (
- $rOpts->{'delete-semicolons'}
-
- # don't delete ; before a # because it would promote it
- # to a block comment
- && ( $next_nonblank_token_type ne '#' )
- )
- {
- note_deleted_semicolon();
- $self->output_line_to_go()
- unless ( $no_internal_newlines
- || $index_start_one_line_block != UNDEFINED_INDEX );
- next;
- }
- else {
- write_logfile_entry("Extra ';'\n");
- }
- }
$self->store_token_to_go();
$self->output_line_to_go()
$first_deleted_semicolon_at = $last_deleted_semicolon_at;
}
$deleted_semicolon_count++;
- write_logfile_entry("Deleted unnecessary ';'\n"); # i hope ;)
+ write_logfile_entry("Deleted unnecessary ';' at line $input_line_number\n");
return;
}
#11 rt130394.def
#12 rt131115.def
#13 rt131115.rt131115
+#14 ndsm1.def
+#15 ndsm1.ndsm
# To locate test #13 you can search for its name or the string '#13'
$rparams = {
'def' => "",
'git10' => "-wn -ce -cbl=sort,map,grep",
+ 'ndsm' => "-ndsm",
'rt131115' => "-bli",
'spp1' => "-spp=1",
'spp2' => "-spp=2",
$proof = $xxxxreg = $reg = $dist = '';
----------
+ 'ndsm1' => <<'----------',
+;;;;; # 1 trapped semicolon
+sub numerically {$a <=> $b};
+;;;;;
+sub Numerically {$a <=> $b}; # trapped semicolon
+@: = qw;2c72656b636168
+ 2020202020
+ ;; __;
+----------
+
'rt130394' => <<'----------',
# rt130394: keep on one line
$factorial = sub { reduce { $a * $b } 1 .. 11 };
}
#13...........
},
+
+ 'ndsm1.def' => {
+ source => "ndsm1",
+ params => "def",
+ expect => <<'#14...........',
+; # 1 trapped semicolon
+sub numerically { $a <=> $b }
+
+sub Numerically { $a <=> $b }; # trapped semicolon
+@: = qw;2c72656b636168
+ 2020202020
+ ;;
+__;
+#14...........
+ },
+
+ 'ndsm1.ndsm' => {
+ source => "ndsm1",
+ params => "ndsm",
+ expect => <<'#15...........',
+;
+;
+;
+;
+; # 1 trapped semicolon
+sub numerically { $a <=> $b };
+;
+;
+;
+;
+;
+sub Numerically { $a <=> $b }; # trapped semicolon
+@: = qw;2c72656b636168
+ 2020202020
+ ;;
+__;
+#15...........
+ },
};
my $ntests = 0 + keys %{$rtests};