%is_keyword_returning_list,
%is_if_unless_and_or_last_next_redo_return,
%is_if_elsif_else_unless_while_until_for_foreach,
+ %is_if_unless_while_until_for,
%is_last_next_redo_return,
%is_sort_map_grep,
%is_sort_map_grep_eval,
@is_if_elsif_else_unless_while_until_for_foreach{@q} =
(1) x scalar(@q);
+ @q = qw(if unless while until for);
+ @is_if_unless_while_until_for{@q} =
+ (1) x scalar(@q);
+
@q = qw(last next redo return);
@is_last_next_redo_return{@q} = (1) x scalar(@q);
$str =~ s/\s+$//;
return unless ($str);
- # There are four container tokens.
+ # There are four container tokens.
my %token_keys = (
'(' => '(',
'[' => '[',
# DO-NOT-WELD RULE 5: do not include welds excluded by user
if ( !$do_not_weld && %weld_nested_exclusion_rules ) {
$do_not_weld ||=
- $self->is_excluded_weld( $Kouter_opening,
- $starting_new_weld );
- $do_not_weld ||=
- $self->is_excluded_weld( $Kinner_opening, 0 );
+ $self->is_excluded_weld( $Kouter_opening, $starting_new_weld );
+ $do_not_weld ||= $self->is_excluded_weld( $Kinner_opening, 0 );
}
if ($do_not_weld) {
# output a blank line before block comments
if (
# unless we follow a blank or comment line
- $self->[_last_line_leading_type_] !~ /^[#b]$/
+ $self->[_last_line_leading_type_] ne '#'
+ && $self->[_last_line_leading_type_] ne 'b'
# only if allowed
&& $rOpts->{'blanks-before-comments'}
# break before certain key blocks except one-liners
if ( $leading_type eq 'k' ) {
- if ( $leading_token =~ /^(BEGIN|END)$/ ) {
+ if ( $leading_token eq 'BEGIN' || $leading_token eq 'END' )
+ {
$want_blank = $rOpts->{'blank-lines-before-subs'}
if ( terminal_type_i( $imin, $imax ) ne '}' );
}
my ( $self, $saw_good_break, $rcolon_list ) = @_;
-# @{$rcolon_list} is a list of all the ? and : tokens in the batch, in order.
-# Previously, it was obtained with this very inefficient code:
-# my @colon_list = grep { /^[\?\:]$/ } @types_to_go[ 0 .. $max_index_to_go ];
+ # @{$rcolon_list} is a list of all the ? and : tokens in the batch, in
+ # order.
use constant DEBUG_BREAKPOINTS => 0;
&& $i_next_nonblank <= $imax
&& ( $want_break_before{$next_nonblank_type}
|| $token_lengths_to_go[$i_next_nonblank] > 2
- || $next_nonblank_type =~ /^[\,\(\[\{L]$/ )
+ || $next_nonblank_type eq ','
+ || $is_opening_type{$next_nonblank_type} )
)
{
$strength -= $tiny_bias;
# the next line and we already have a possible break
if (
!$must_break
- && ( $next_nonblank_type =~ /^[\;\,]$/ )
+ && ( $next_nonblank_type eq ';' || $next_nonblank_type eq ',' )
&& (
(
$leading_spaces +
# before the closing bracket or not.
if ( !$too_long
&& $i_test + 1 < $imax
- && $next_nonblank_type !~ /^[,\}\]\)R]$/ )
+ && $next_nonblank_type ne ','
+ && !$is_closing_type{$next_nonblank_type} )
{
$too_long = $next_length >= $maximum_line_length;
}
&& $too_long
&& $i_lowest == $i_test
&& $token_lengths_to_go[$i_test] > 1
- && $next_nonblank_type =~ /^[\;\,]$/ )
+ && ( $next_nonblank_type eq ';' || $next_nonblank_type eq ',' )
+ )
{
$too_long = 0;
}
+ # we are done if...
last
if (
- ( $i_test == $imax ) # we're done if no more tokens,
- || (
- ( $i_lowest >= 0 ) # or no more space and we have a break
- && $too_long
- )
+
+ # ... no more space and we have a break
+ $too_long && $i_lowest >= 0
+
+ # ... or no more tokens
+ || $i_test == $imax
);
}
# set a forced breakpoint at a container opening, if necessary, to
# signal a break at a closing container. Excepting '(' for now.
- if ( $tokens_to_go[$i_lowest] =~ /^[\{\[]$/
- && !$forced_breakpoint_to_go[$i_lowest] )
+ if (
+ (
+ $tokens_to_go[$i_lowest] eq '{'
+ || $tokens_to_go[$i_lowest] eq '['
+ )
+ && !$forced_breakpoint_to_go[$i_lowest]
+ )
{
$self->set_closing_breakpoint($i_lowest);
}
&& $i > 0
# if one of these keywords:
- && $token =~ /^(if|unless|while|until|for)$/
+ # /^(if|unless|while|until|for)$/
+ && $is_if_unless_while_until_for{$token}
# but do not break at something like '1 while'
&& ( $last_nonblank_type ne 'n' || $i > 2 )
my $inc = ( $type eq ':' ) ? 0 : 1;
$self->set_forced_breakpoint( $i - $inc );
}
- } ## end if ( $token =~ /^[\)\]\}\:]$/[{[(])
+ } ## end if ( $is_closing_sequence_token{$token} )
# set breaks at ?/: if they will get separated (and are
# not a ?/: chain), or if the '?' is at the end of the
? $i_opening - 2
: $i_opening - 1;
- if ( $types_to_go[$i_prev] eq ','
- && $types_to_go[ $i_prev - 1 ] =~ /^[\)\}]$/ )
+ if (
+ $types_to_go[$i_prev] eq ','
+ && ( $types_to_go[ $i_prev - 1 ] eq ')'
+ || $types_to_go[ $i_prev - 1 ] eq '}' )
+ )
{
$self->set_forced_breakpoint($i_prev);
}
# on a line
|| ( $type eq 'Q'
&& $i_opening >= $max_index_to_go - 2
- && $token =~ /^['"]$/ )
+ && ( $token eq "'" || $token eq '"' ) )
);
} ## end for ( my $dd = $current_depth...)
$self->[_last_output_short_opening_token_]
# line ends in opening token
- = $type_end =~ /^[\{\(\[L]$/
+ # /^[\{\(\[L]$/
+ = $is_opening_type{$type_end}
# and either
&& (
# or is a single token followed by opening token.
# Note that sub identifiers have blanks like 'sub doit'
- || ( $Kend - $Kbeg <= 2 && $token_beg !~ /\s+/ )
+ # $token_beg !~ /\s+/
+ || ( $Kend - $Kbeg <= 2 && index( $token_beg, ' ' ) < 0 )
)
# and limit total to 10 character widths
# my ( $a, $b, $c, $d, $e, $f ) = @_;
# }
if ( $raw_tok eq '(' ) {
- my $ci = $ci_levels_to_go[$ibeg];
- if ( $container_name{$depth} =~ /^\+(if|unless)/
- && $ci )
+ if ( $ci_levels_to_go[$ibeg]
+ && $container_name{$depth} =~ /^\+(if|unless)/ )
{
$tok .= $container_name{$depth};
}
# remove sub names to allow one-line sub braces to align
# regardless of name
- #if ( $block_type =~ /^sub / ) { $block_type = 'sub' }
if ( $block_type =~ /$SUB_PATTERN/ ) { $block_type = 'sub' }
# allow all control-type blocks to align
# Mark most things before arrows as a quote to
# get them to line up. Testfile: mixed.pl.
- # $type =~ /^[wnC]$/
+ # $type =~ /^[wnC]$/
if ( $i < $iend - 1 && $is_w_n_C{$type} ) {
my $next_type = $types_to_go[ $i + 1 ];
my $i_next_nonblank =
}
# Finally, remove any leading arrows
- $name =~ s/^->//;
+ if ( substr( $name, 0, 2 ) eq '->' ) {
+ $name = substr( $name, 2 );
+ }
return $name;
}
# For -lp formatting se use $ibeg_weld_fix to get around the problem
# that with -lp type formatting the opening and closing tokens to not
# have sequence numbers.
- if ( $type_beg eq 'q' && $token_beg =~ /^[\)\}\]\>]/ ) {
+ if ( $type_beg eq 'q'
+ && ( $is_closing_token{$token_beg} || $token_beg eq '>' ) )
+ {
my $K_next_nonblank = $self->K_next_code($K_beg);
if ( defined($K_next_nonblank) ) {
my $type_sequence = $rLL->[$K_next_nonblank]->[_TYPE_SEQUENCE_];
}
# if we are at a closing token of some type..
- if ( $type_beg =~ /^[\)\}\]R]$/ ) {
+ if ( $is_closing_type{$type_beg} ) {
# get the indentation of the line containing the corresponding
# opening token
# Patch for -wn=2, multiple welded closing tokens
|| ( $i_terminal > $ibeg
- && $types_to_go[$iend] =~ /^[\)\}\]R]$/ )
+ && $is_closing_type{ $types_to_go[$iend] } )
)
{
# indented, but this is better than frequently leaving it not
# indented enough.
my $last_spaces = get_spaces($last_indentation_written);
- if ( $last_leading_token !~ /^[\}\]\)]$/ ) {
+ if ( !$is_closing_token{$last_leading_token} ) {
$last_spaces +=
get_recoverable_spaces($last_indentation_written);
}