Related issues arise with other binary operator symbols, such as + and -, and in older versions of perl there could be problems with ternary operators. So to avoid changing program behavior, perltidy has the simple rule that whitespace around possible filehandles is left unchanged. Likewise, whitespace around barewords is left unchanged. The reason is that if the barewords are defined in other modules, or in code that has not even been written yet, perltidy will not have seen their prototypes and must treat them cautiously.
+In perltidy this is implemented in the tokenizer by marking token following a
+B<print> keyword as a special type B<Z>. When formatting is being done,
+whitespace following this token type is generally left unchanged as a precaution
+against changing program behavior. This is excessively conservative but simple
+and easy to implement. Keywords which are treated similarly to B<print> include
+B<printf>, B<sort>, B<exec>, B<system>. Changes in spacing around parameters
+following these keywords may have to be made manually. For example, the space,
+or lack of space, after the parameter $foo in the following line will be
+unchanged in formatting.
+
+ system($foo );
+ system($foo);
+
+To find if a token is of type B<Z> you can use B<perltidy -DEBUG>. For the
+first line above the result is
+
+ 1: system($foo );
+ 1: kkkkkk{ZZZZb};
+
+which shows that B<system> is type B<k> (keyword) and $foo is type B<Z>.
+
+
=item Note2: Perltidy's whitespace rules are not perfect
Despite these precautions, it is still possible to introduce syntax errors with
_ris_bli_container_ => $i++,
_rparent_of_seqno_ => $i++,
_rchildren_of_seqno_ => $i++,
+ _ris_list_by_seqno_ => $i++,
_rbreak_container_ => $i++,
_rshort_nested_ => $i++,
_length_function_ => $i++,
$self->[_ris_bli_container_] = {};
$self->[_rparent_of_seqno_] = {};
$self->[_rchildren_of_seqno_] = {};
+ $self->[_ris_list_by_seqno_] = {};
$self->[_rbreak_container_] = {}; # prevent one-line blocks
$self->[_rshort_nested_] = {}; # blocks not forced open
$self->[_length_function_] = $length_function;
$self->[_K_first_seq_item_] = $KNEXT;
}
+ # find and remember lists by sequence number
+ # TODO: eventually this should hold a name for the list
+ my $ris_list_by_seqno = {};
+ foreach my $seqno ( keys %{$K_opening_container} ) {
+ my $K_opening = $K_opening_container->{$seqno};
+ my $block_type = $rLL_new->[$K_opening]->[_BLOCK_TYPE_];
+ next if ($block_type);
+ my $rtype_count = $rtype_count_by_seqno->{$seqno};
+ next unless ($rtype_count);
+ my $fat_comma_count = $rtype_count->{'=>'};
+ my $comma_count = $rtype_count->{','};
+ my $is_list = ( $fat_comma_count || $comma_count && $comma_count > 1 );
+ $ris_list_by_seqno->{$seqno} = $is_list;
+ }
+
# Reset memory to be the new array
$self->[_rLL_] = $rLL_new;
my $Klimit;
$self->[_rhas_broken_container_] = $rhas_broken_container;
$self->[_rparent_of_seqno_] = $rparent_of_seqno;
$self->[_rchildren_of_seqno_] = $rchildren_of_seqno;
+ $self->[_ris_list_by_seqno_] = $ris_list_by_seqno;
# DEBUG OPTION: make sure the new array looks okay.
# This is no longer needed but should be retained for future development.
# Return true if the immediate contents of a container appears to be a
# list.
-
my ( $self, $seqno ) = @_;
return unless defined($seqno);
-
- my $K_opening_container = $self->[_K_opening_container_];
- my $K_opening = $K_opening_container->{$seqno};
- return unless ( defined($K_opening) );
-
- my $rLL = $self->[_rLL_];
- my $block_type = $rLL->[$K_opening]->[_BLOCK_TYPE_];
- return if ($block_type);
-
- my $token = $rLL->[$K_opening]->[_TOKEN_];
- return if ( $token eq ':' );
-
- # We will require at least 2 commas or 1 fat comma in the
- # immediate lower level.
- my $rtype_count_by_seqno = $self->[_rtype_count_by_seqno_];
- my $fat_comma_count = $rtype_count_by_seqno->{$seqno}->{'=>'};
- my $comma_count = $rtype_count_by_seqno->{$seqno}->{','};
- my $is_list = ( $fat_comma_count || $comma_count && $comma_count > 1 );
- return $is_list;
+ return $self->[_ris_list_by_seqno_]->{$seqno};
}
sub resync_lines_and_tokens {
&& $i_break_right <= $i_l )
{
splice( @{$ri_first}, $line_number, 1, ( $i_f, $i_break_right ) );
- splice( @{$ri_last}, $line_number, 1, ( $i_break_left, $i_l ) );
+ splice( @{$ri_last}, $line_number, 1, ( $i_break_left, $i_l ) );
}
}
return;