## 2024 05 11.07
+ - Add parameter --closing-side-comment-exclusion-list=string, or
+ -cscxl=string, where string is a list of block types to exclude
+ for closing side comment operations. Also, closing side comments
+ now work for anonymous subs. Use -cscxl=asub if you do not
+ want this.
+
- Include signature variables in --dump-unusual-variables and
--warn-variable-types; see git #158.
command changes the default list to be any selected block types; see
L<"Specifying Block Types">.
For example, the following command
-requests that only C<sub>'s, labels, C<BEGIN>, and C<END> blocks be
-affected by any B<-csc> or B<-dcsc> operation:
+requests that only C<sub>'s, labels, C<BEGIN>, and C<END> blocks be affected by
+operations which add (B<-csc>) or delete (B<-dcsc>) closing side comments:
- -cscl="sub : BEGIN END"
+ --closing-side-comment-list='sub : BEGIN END'
+
+=item B<-cscxl=string>, or B<--closing-side-comment-exclusion-list>
+
+where C<string> is a list of block types which should NOT be tagged with
+closing side comments. If a block type appears in both B<-cscl> and
+B<-cscxl>, then B<-cscxl> has priority and the block will not be tagged.
+
+For example, the following command requests that anonymous subs
+should not be affected by any B<-csc> or B<-dcsc> operation:
+
+ --closing-side-comment-exclusion-list='asub'
+
+By default, no block types are excluded.
=item B<-csct=n>, or B<--closing-side-comment-maximum-text=n>
########################################
$category = 4; # Comment controls
########################################
- $add_option->( 'closing-side-comment-else-flag', 'csce', '=i' );
- $add_option->( 'closing-side-comment-interval', 'csci', '=i' );
- $add_option->( 'closing-side-comment-list', 'cscl', '=s' );
- $add_option->( 'closing-side-comment-maximum-text', 'csct', '=i' );
- $add_option->( 'closing-side-comment-prefix', 'cscp', '=s' );
- $add_option->( 'closing-side-comment-warnings', 'cscw', '!' );
- $add_option->( 'closing-side-comments', 'csc', '!' );
- $add_option->( 'closing-side-comments-balanced', 'cscb', '!' );
- $add_option->( 'code-skipping', 'cs', '!' );
- $add_option->( 'code-skipping-begin', 'csb', '=s' );
- $add_option->( 'code-skipping-end', 'cse', '=s' );
- $add_option->( 'format-skipping', 'fs', '!' );
- $add_option->( 'format-skipping-begin', 'fsb', '=s' );
- $add_option->( 'format-skipping-end', 'fse', '=s' );
- $add_option->( 'hanging-side-comments', 'hsc', '!' );
- $add_option->( 'indent-block-comments', 'ibc', '!' );
- $add_option->( 'indent-spaced-block-comments', 'isbc', '!' );
- $add_option->( 'fixed-position-side-comment', 'fpsc', '=i' );
- $add_option->( 'minimum-space-to-comment', 'msc', '=i' );
- $add_option->( 'non-indenting-braces', 'nib', '!' );
- $add_option->( 'non-indenting-brace-prefix', 'nibp', '=s' );
- $add_option->( 'outdent-long-comments', 'olc', '!' );
- $add_option->( 'outdent-static-block-comments', 'osbc', '!' );
- $add_option->( 'static-block-comment-prefix', 'sbcp', '=s' );
- $add_option->( 'static-block-comments', 'sbc', '!' );
- $add_option->( 'static-side-comment-prefix', 'sscp', '=s' );
- $add_option->( 'static-side-comments', 'ssc', '!' );
- $add_option->( 'ignore-side-comment-lengths', 'iscl', '!' );
- $add_option->( 'ignore-perlcritic-comments', 'ipc', '!' );
+ $add_option->( 'closing-side-comment-else-flag', 'csce', '=i' );
+ $add_option->( 'closing-side-comment-interval', 'csci', '=i' );
+ $add_option->( 'closing-side-comment-list', 'cscl', '=s' );
+ $add_option->( 'closing-side-comment-exclusion-list', 'cscxl', '=s' );
+ $add_option->( 'closing-side-comment-maximum-text', 'csct', '=i' );
+ $add_option->( 'closing-side-comment-prefix', 'cscp', '=s' );
+ $add_option->( 'closing-side-comment-warnings', 'cscw', '!' );
+ $add_option->( 'closing-side-comments', 'csc', '!' );
+ $add_option->( 'closing-side-comments-balanced', 'cscb', '!' );
+ $add_option->( 'code-skipping', 'cs', '!' );
+ $add_option->( 'code-skipping-begin', 'csb', '=s' );
+ $add_option->( 'code-skipping-end', 'cse', '=s' );
+ $add_option->( 'format-skipping', 'fs', '!' );
+ $add_option->( 'format-skipping-begin', 'fsb', '=s' );
+ $add_option->( 'format-skipping-end', 'fse', '=s' );
+ $add_option->( 'hanging-side-comments', 'hsc', '!' );
+ $add_option->( 'indent-block-comments', 'ibc', '!' );
+ $add_option->( 'indent-spaced-block-comments', 'isbc', '!' );
+ $add_option->( 'fixed-position-side-comment', 'fpsc', '=i' );
+ $add_option->( 'minimum-space-to-comment', 'msc', '=i' );
+ $add_option->( 'non-indenting-braces', 'nib', '!' );
+ $add_option->( 'non-indenting-brace-prefix', 'nibp', '=s' );
+ $add_option->( 'outdent-long-comments', 'olc', '!' );
+ $add_option->( 'outdent-static-block-comments', 'osbc', '!' );
+ $add_option->( 'static-block-comment-prefix', 'sbcp', '=s' );
+ $add_option->( 'static-block-comments', 'sbc', '!' );
+ $add_option->( 'static-side-comment-prefix', 'sscp', '=s' );
+ $add_option->( 'static-side-comments', 'ssc', '!' );
+ $add_option->( 'ignore-side-comment-lengths', 'iscl', '!' );
+ $add_option->( 'ignore-perlcritic-comments', 'ipc', '!' );
########################################
$category = 5; # Linebreak controls
# INITIALIZER: sub make_closing_side_comment_list_pattern
$closing_side_comment_list_pattern,
$closing_side_comment_want_asub,
+ $closing_side_comment_exclusion_pattern,
# Table to efficiently find indentation and max line length
# from level.
# turn any input list into a regex for recognizing selected block types
$closing_side_comment_list_pattern = '^\w+';
- $closing_side_comment_want_asub = 0;
- if ( defined( $rOpts->{'closing-side-comment-list'} )
- && $rOpts->{'closing-side-comment-list'} )
- {
+
+ # '1' is an impossible block name
+ $closing_side_comment_exclusion_pattern = '^1';
+
+ # Need a separate flag for anonymous subs because they are the only
+ # types where the side comment might follow a ';'
+ $closing_side_comment_want_asub = 1;
+
+ my $cscl = $rOpts->{'closing-side-comment-list'};
+ if ( defined($cscl) && $cscl ) {
$closing_side_comment_list_pattern =
- make_block_pattern( '-cscl', $rOpts->{'closing-side-comment-list'} );
- $closing_side_comment_want_asub =
- $rOpts->{'closing-side-comment-list'} =~ /\basub\b/;
+ make_block_pattern( '-cscl', $cscl );
+ $closing_side_comment_want_asub = $cscl =~ /\basub\b/;
+ }
+
+ my $cscxl = $rOpts->{'closing-side-comment-exclusion-list'};
+ if ( defined($cscxl) && $cscxl ) {
+ $closing_side_comment_exclusion_pattern =
+ make_block_pattern( '-cscxl', $cscxl );
+ if ( $cscxl =~ /\basub\b/ ) {
+ $closing_side_comment_want_asub = 0;
+ }
}
return;
} ## end sub make_closing_side_comment_list_pattern
my $block_type_m = $rblock_type_of_seqno->{$seqno_m};
if ( $block_type_m
&& $token =~ /$closing_side_comment_prefix_pattern/
- && $block_type_m =~ /$closing_side_comment_list_pattern/ )
+ && $block_type_m =~ /$closing_side_comment_list_pattern/
+ && $block_type_m !~
+ /$closing_side_comment_exclusion_pattern/ )
{
$delete_side_comment = 1;
}
if ( $type eq 'k'
&& $csc_new_statement_ok
&& $is_if_elsif_else_unless_while_until_for_foreach{$token}
- && $token =~ /$closing_side_comment_list_pattern/ )
+ && $token =~ /$closing_side_comment_list_pattern/
+ && $token !~ /$closing_side_comment_exclusion_pattern/ )
{
$self->set_block_text_accumulator($i);
}
# .. and if this is one of the types of interest
&& $block_type_to_go[$i_terminal] =~
/$closing_side_comment_list_pattern/
-
- # anonymous sub only if specifically requested (c380)
- && ( $block_type_to_go[$i_terminal] ne 'sub'
- || $closing_side_comment_want_asub )
+ && $block_type_to_go[$i_terminal] !~
+ /$closing_side_comment_exclusion_pattern/
# ..and the corresponding opening brace must is not in this batch
# (because we do not need to tag one-line blocks, although this
print( $_[0], "\n" );
}
} ## end sub message
+
+ my $message =sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ }
+ else {
+ print( $_[0], "\n" );
+ }
+ };
--csc -csci=2 -ncscb
+-csc -csci=2 -ncscb -cscxl=asub
--- /dev/null
+-csc -csci=2 -ncscb
print( $_[0], "\n" );
} ## end else [ if ( !defined( $_[0] ))
} ## end sub message
+
+ my $message = sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ } ## end if ( !defined( $_[0] ))
+ else {
+ print( $_[0], "\n" );
+ } ## end else [ if ( !defined( $_[0] ))
+ };
print( $_[0], "\n" );
}
}
+
+ my $message = sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ }
+ else {
+ print( $_[0], "\n" );
+ }
+ };
--- /dev/null
+ sub message {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ } ## end if ( !defined( $_[0] ))
+ else {
+ print( $_[0], "\n" );
+ } ## end else [ if ( !defined( $_[0] ))
+ } ## end sub message
+
+ my $message = sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ } ## end if ( !defined( $_[0] ))
+ else {
+ print( $_[0], "\n" );
+ } ## end else [ if ( !defined( $_[0] ))
+ }; ## end $message = sub
print( $_[0], "\n" );
}
} ## end sub message
+
+ my $message = sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ }
+ else {
+ print( $_[0], "\n" );
+ }
+ };
../snippets30.t dltc.def
../snippets30.t dltc.dltc1
../snippets30.t dltc.dltc2
+../snippets30.t logical_xor.def
../snippets4.t gnu1.gnu
../snippets4.t gnu2.def
../snippets4.t gnu2.gnu
../snippets9.t rt98902.def
../snippets9.t rt98902.rt98902
../snippets9.t rt99961.def
-../snippets30.t logical_xor.def
+../snippets30.t csc.csc3
# testing --delete-side-comments and --nostatic-block-comments
-dsc -nsbc
----------
- 'csc1' => "-csc -csci=2 -ncscb",
+ 'csc1' => "-csc -csci=2 -ncscb -cscxl=asub",
'csc2' => "-dcsc",
'def' => "",
'iob' => "-iob",
print( $_[0], "\n" );
}
} ## end sub message
+
+ my $message =sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ }
+ else {
+ print( $_[0], "\n" );
+ }
+ };
----------
'iob' => <<'----------',
print( $_[0], "\n" );
} ## end else [ if ( !defined( $_[0] ))
} ## end sub message
+
+ my $message = sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ } ## end if ( !defined( $_[0] ))
+ else {
+ print( $_[0], "\n" );
+ } ## end else [ if ( !defined( $_[0] ))
+ };
#9...........
},
print( $_[0], "\n" );
}
}
+
+ my $message = sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ }
+ else {
+ print( $_[0], "\n" );
+ }
+ };
#10...........
},
print( $_[0], "\n" );
}
} ## end sub message
+
+ my $message = sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ }
+ else {
+ print( $_[0], "\n" );
+ }
+ };
#11...........
},
#9 dltc.dltc1
#10 dltc.dltc2
#11 logical_xor.def
+#12 csc.csc3
# To locate test #13 you can search for its name or the string '#13'
$rparams = {
'altc1' => "-atc -wtc=m",
'altc2' => "-altc -atc -wtc=m",
+ 'csc3' => "-csc -csci=2 -ncscb",
'def' => "",
'dltc1' => "-dtc -wtc=0",
'dltc2' => "-dtc -wtc=0 -ndltc",
);
----------
+ 'csc' => <<'----------',
+ sub message {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ }
+ else {
+ print( $_[0], "\n" );
+ }
+ } ## end sub message
+
+ my $message =sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ }
+ else {
+ print( $_[0], "\n" );
+ }
+ };
+----------
+
'dltc' => <<'----------',
$self->make_grammar(
{
$x ^^ $y and say "One of x or y is true, but not both";
#11...........
},
+
+ 'csc.csc3' => {
+ source => "csc",
+ params => "csc3",
+ expect => <<'#12...........',
+ sub message {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ } ## end if ( !defined( $_[0] ))
+ else {
+ print( $_[0], "\n" );
+ } ## end else [ if ( !defined( $_[0] ))
+ } ## end sub message
+
+ my $message = sub {
+ if ( !defined( $_[0] ) ) {
+ print("Hello, World\n");
+ } ## end if ( !defined( $_[0] ))
+ else {
+ print( $_[0], "\n" );
+ } ## end else [ if ( !defined( $_[0] ))
+ }; ## end $message = sub
+#12...........
+ },
};
my $ntests = 0 + keys %{$rtests};