$block_type,
$current_depth,
$depth,
- $i,
$i_last_colon,
$i_line_end,
$i_line_start,
return;
} ## end sub check_for_new_minimum_depth
- # routine to decide which commas to break at within a container;
- # returns:
- # $bp_count = number of comma breakpoints set
- # $do_not_break_apart = a flag indicating if container need not
- # be broken open
sub set_comma_breakpoints {
- my ( $self, $dd, $rbond_strength_bias ) = @_;
+ my ( $self, $i, $dd, $rbond_strength_bias ) = @_;
+
+ # Decide which commas to break at within a container
+ # Given:
+ # $i = index of current token in main loop over tokens, or
+ # = $max_index_to_go + 1 for post-loop operations (c410)
+ # $dd = stack depth
+ # $rbond-strength_bias = ref to array of bond strength biases which
+ # may be updated for commas not in lists
+ # Return:
+ # $bp_count = number of comma breakpoints set
+ # $do_not_break_apart = a flag indicating if container need not
+ # be broken open
my $bp_count = 0;
my $do_not_break_apart = 0;
$block_type = SPACE;
$current_depth = $starting_depth;
- $i = -1;
$i_last_colon = -1;
$i_line_end = -1;
$i_line_start = -1;
#----------------------------------------
# Main loop over all tokens in this batch
#----------------------------------------
- while ( ++$i <= $max_index_to_go ) {
+ foreach my $i ( 0 .. $max_index_to_go ) {
if ( $type ne 'b' ) {
$i_last_nonblank_token = $i - 1;
$last_nonblank_type = $type;
# Check for a good old breakpoint ..
if ( $old_breakpoint_to_go[$i] ) {
( $i_want_previous_break, $i_old_assignment_break ) =
- $self->examine_old_breakpoint( $i_next_nonblank,
+ $self->examine_old_breakpoint( $i, $i_next_nonblank,
$i_want_previous_break, $i_old_assignment_break );
}
# Loop Section B: Handle a sequenced token
#-----------------------------------------
if ($type_sequence) {
- $self->break_lists_type_sequence();
+ $self->break_lists_type_sequence($i);
}
#------------------------------------------
# hardened against bad input syntax: depth jump must be 1 and type
# must be opening..fixes c102
if ( $depth == $current_depth + 1 && $is_opening_type{$type} ) {
- $self->break_lists_increasing_depth();
+ $self->break_lists_increasing_depth($i);
}
#------------------------------------------
# Note that $rbond_strength_bias will not get changed by this
# call. It gets changed in the call to set_comma_breakpoints
# at the end of this routine for commas not in lists.
- $self->break_lists_decreasing_depth($rbond_strength_bias);
+ $self->break_lists_decreasing_depth( $i, $rbond_strength_bias );
$comma_follows_last_closing_token =
$next_nonblank_type eq ',' || $next_nonblank_type eq '=>';
# handle any commas
elsif ( $type eq ',' ) {
- $self->study_comma($comma_follows_last_closing_token);
+ $self->study_comma( $i, $comma_follows_last_closing_token );
}
# handle comma-arrow
EOM
}
- } ## end while ( ++$i <= $max_index_to_go)
-
- #-------------------------------------------
- # END of loop over all tokens in this batch
- #-------------------------------------------
+ } ## end main loop over tokens
#----------------------------------------
# Now set breaks for any unfinished lists
$interrupted_list[$dd] = 1;
$has_broken_sublist[$dd] = 1 if ( $dd < $current_depth );
- $self->set_comma_breakpoints( $dd, $rbond_strength_bias )
- if ( $item_count_stack[$dd] );
+ if ( $item_count_stack[$dd] ) {
+ $self->set_comma_breakpoints( $max_index_to_go + 1,
+ $dd, $rbond_strength_bias );
+
+ }
$self->set_logical_breakpoints($dd)
if ( $has_old_logical_breakpoints[$dd] );
$self->set_for_semicolon_breakpoints($dd);
# study and store info for a list comma
- my ( $self, $comma_follows_last_closing_token ) = @_;
+ my ( $self, $i, $comma_follows_last_closing_token ) = @_;
$last_dot_index[$depth] = undef;
$last_comma_index[$depth] = $i;
sub examine_old_breakpoint {
- my ( $self, $i_next_nonblank, $i_want_previous_break,
+ my ( $self, $i, $i_next_nonblank, $i_want_previous_break,
$i_old_assignment_break )
= @_;
sub break_lists_type_sequence {
- my ($self) = @_;
+ my ( $self, $i ) = @_;
# We have encountered a sequenced token while setting list breakpoints
sub break_lists_increasing_depth {
- my ($self) = @_;
+ my ( $self, $i ) = @_;
#--------------------------------------------
# prepare for a new list when depth increases
sub break_lists_decreasing_depth {
- my ( $self, $rbond_strength_bias ) = @_;
+ my ( $self, $i, $rbond_strength_bias ) = @_;
# We have arrived at a closing container token in sub break_lists:
# the token at index $i is one of these: ')','}', ']'
# Set breaks at commas to display a table of values if appropriate
#-----------------------------------------------------------------
my ( $bp_count, $do_not_break_apart ) = ( 0, 0 );
- ( $bp_count, $do_not_break_apart ) =
- $self->set_comma_breakpoints( $current_depth, $rbond_strength_bias )
- if ( $item_count_stack[$current_depth] );
+ if ( $item_count_stack[$current_depth] ) {
+ ( $bp_count, $do_not_break_apart ) =
+ $self->set_comma_breakpoints( $i, $current_depth,
+ $rbond_strength_bias );
+ }
#-----------------------------------------------------------
# Now set flags needed to decide if we should break open the
# Rule.
#-------------------------------------------------------------
if ($has_broken_sublist) {
-
$self->apply_broken_sublist_rule( $rhash_A, $interrupted );
-
return;
}
$tol += 1;
}
+ # c410: check for $i_closing_paren > $max_index_to_go
my $i_opening_minus = $self->find_token_starting_list($i_opening_paren);
- my $excess =
- $self->excess_line_length( $i_opening_minus, $i_closing_paren );
+ my $iend = min( $i_closing_paren, $max_index_to_go );
+ my $excess = $self->excess_line_length( $i_opening_minus, $iend );
return if ( $excess + $tol <= 0 );
#---------------------------------------
( $types_to_go[ $i_last_comma + 1 ] eq 'b' )
? $i_last_comma + 1
: $i_last_comma;
+
+ # NOTE: $i_closing_paren = $max_index_to_go+1 for a list which does
+ # not end in a closing paren. So the following test works (c410)
my $i_e =
( $types_to_go[ $i_closing_paren - 1 ] eq 'b' )
? $i_closing_paren - 2