# sub set_forced_breakpoint
# CODE SECTION 9: Process batches of code
# sub grind_batch_of_CODE
-# CODE SECTION 10: Code to break long statments
+# CODE SECTION 10: Code to break long statements
# sub break_long_lines
# CODE SECTION 11: Code to break long lists
# sub break_lists
# Initialized in sub prepare_cuddled_block_types
$rcuddled_block_types,
- # Initialized and configured in check_optioms
+ # Initialized and configured in check_options
%outdent_keyword,
%keyword_paren_inner_tightness,
# Map related block names into a common name to allow vertical alignment
# used by sub make_alignment_patterns. Note: this is normally unchanged,
- # but it contains 'grep' and can be re-initized in
+ # but it contains 'grep' and can be re-initialized in
# sub initialize_grep_and_friends in a testing mode.
%block_type_map = (
'unless' => 'if',
if ( defined($opt) && $opt > 0 && $break_before_container_types{$tok} )
{
- # (1) -lp is not compatable with opt=2, silently set to opt=0
+ # (1) -lp is not compatible with opt=2, silently set to opt=0
# (2) opt=0 and 2 give same result if -i=-ci; but opt=0 is faster
if ( $opt == 2 ) {
if ( $rOpts->{'line-up-parentheses'}
# { ... }
# Also, I prefer not to put a ? and # together because ? used to be
- # a pattern delmiter and spacing was used if guessing was needed.
+ # a pattern delimiter and spacing was used if guessing was needed.
if ( $typer eq '#' ) {
# real tokens
$right_bond_strength{'b'} = NO_BREAK;
- # try not to break on exponentation
+ # try not to break on exponentiation
@q = qw# ** .. ... <=> #;
@left_bond_strength{@q} = (STRONG) x scalar(@q);
@right_bond_strength{@q} = (STRONG) x scalar(@q);
# },
# };
- # SIMPLFIED METHOD: the simplified method uses a wildcard for
+ # SIMPLIFIED METHOD: the simplified method uses a wildcard for
# the starting block type and puts all cuddled blocks together:
# my $rcuddled_block_types = {
# '*' => {
# 'IO' = Indent Only - line goes out unchanged except for indentation
# 'NIN' = No Internal Newlines - line does not get broken
# 'VER' = VERSION statement
- # '' = ordinary line of code with no restructions
+ # '' = ordinary line of code with no restrictions
my $ix_line = -1;
foreach my $line_of_tokens ( @{$rlines} ) {
# '$var = s/xxx/yyy/;'
# in case it should have been '$var =~ s/xxx/yyy/;'
- # Start by looking for a token begining with one of: s y m / tr
+ # Start by looking for a token beginning with one of: s y m / tr
return
unless ( $is_s_y_m_slash{ substr( $token, 0, 1 ) }
|| substr( $token, 0, 2 ) eq 'tr' );
# An error here means that sub write_line() did not correctly
# package the tokenized lines as it received them. If we
# get a fault here it has not output a continuous sequence
- # of K values. Or a line of CODE may have been mismarked as
+ # of K values. Or a line of CODE may have been mis-marked as
# something else. There is no good way to continue after such an
# error.
# FIXME: Calling Fault will produce zero output; it would be best to
# Remove unnecessary semicolons, but not after bare
# blocks, where it could be unsafe if the brace is
- # mistokenized.
+ # mis-tokenized.
if (
$rOpts->{'delete-semicolons'}
&& (
# We will define a list to be a container with one or more commas
# and no semicolons. Note that we have included the semicolons
- # in a 'for' container in the simicolon count to keep c-style for
+ # in a 'for' container in the semicolon count to keep c-style for
# statements from being formatted as lists.
if ( ( $comma_count || $fat_comma_count ) && !$semicolon_count ) {
$is_list = 1;
- # We need to do one more check for a perenthesized list:
+ # We need to do one more check for a parenthesized list:
# At an opening paren following certain tokens, such as 'if',
# we do not want to format the contents as a list.
if ( $rLL_new->[$K_opening]->[_TOKEN_] eq '(' ) {
# flags.
my ($self) = @_;
- # This count is used to eliminate needless calls for weld checks elsewere
+ # This count is used to eliminate needless calls for weld checks elsewhere
$total_weld_count = 0;
return if ( $rOpts->{'indent-only'} );
# more complicated method has been developed.
# We are trying to avoid creating bad two-line welds when we are
- # working on long, previously unwelded input text, such as
+ # working on long, previously un-welded input text, such as
# INPUT (example of a long input line weld candidate):
## $mutation->transpos( $self->RNA->position($mutation->label, $atg_label));
}
# The last check we can make is to see if this container could fit on a
- # single line. Use the least possble indentation in the estmate (ci=0),
+ # single line. Use the least possible indentation estimate, ci=0,
# so we are not subtracting $ci * $rOpts_continuation_indentation from
- # tablulated $maximum_text_length value.
+ # tabulated $maximum_text_length value.
my $maximum_text_length = $maximum_text_length_at_level[$level];
my $K_closing = $K_closing_container->{$seqno};
my $length = $self->cumulative_length_before_K($K_closing) -
# The following variable can be used to allow a little extra space to
# avoid blinkers. A value $len_tol = 20 fixed the following
# fixes cases: b1025 b1026 b1027 b1028 b1029 b1030 but NOT b1031.
- # It turned out that the real problem was misparsing a list brace as
+ # It turned out that the real problem was mis-parsing a list brace as
# a code block in a 'use' statement when the line length was extremely
# small. A value of 0 works now, but a slightly larger value can
# be used to minimize the chance of a blinker.
# Minimum space reserved for contents of a code block. A value of 40 has given
# reasonable results. With a large line length, say -l=120, this will not
-# normally be noticable but it will prevent making a mess in some edge cases.
+# normally be noticeable but it will prevent making a mess in some edge cases.
use constant MIN_BLOCK_LEN => 40;
my %is_handle_type;
# limit.
# The basic idea is that at each node in the tree we imagine that we have a
- # fork with a handle and collapsable prongs:
+ # fork with a handle and collapsible prongs:
#
# |------------
# |--------
&& $K_terminal > $K_first );
}
- # Use length to terminal comma if interrupded list rule applies
+ # Use length to terminal comma if interrupted list rule applies
if ( @stack && $stack[-1]->[_interrupted_list_rule_] ) {
my $K_c = $stack[-1]->[_K_c_];
if (
$len = $token_length;
}
- # include everthing to end of line after a here target
+ # include everything to end of line after a here target
elsif ( $type eq 'h' ) {
$len = $rLL->[$K_last]->[_CUMULATIVE_LENGTH_] -
$rLL->[ $KK - 1 ]->[_CUMULATIVE_LENGTH_];
# Definitions:
# ($ibeg, $iend) = starting and ending line indexes of this entire group
# $count = total number of keywords seen in this entire group
- # $level_beg = indententation level of this group
+ # $level_beg = indentation level of this group
# @group = [ $i, $token, $count ] =list of all keywords & blanks
# @subgroup = $j, index of group where token changes
# @iblanks = line indexes of blank lines in input stream in this group
elsif ( $ibeg >= 0 ) {
# - bail out on a large level change; we may have walked into a
- # data structure or anoymous sub code.
+ # data structure or anonymous sub code.
if ( $level > $level_beg + 1 || $level < $level_beg ) {
$end_group->(1);
next;
if ( $max_index_to_go < 0 ) {
- # This is harmless but should be elimintated in development
+ # This is harmless but should be eliminated in development
if (DEVEL_MODE) {
Fault("End batch called with nothing to do; please fix\n");
}
# So this routine is just making an initial set of required line
# breaks, basically regardless of the maximum requested line length.
- # The subsequent stage of formating make additional line breaks
+ # The subsequent stage of formatting make additional line breaks
# appropriate for lists and logical structures, and to keep line
# lengths below the requested maximum line length.
# Compare input/output indentation except for:
# - hanging side comments
- # - continuation lines (habe unknown amount of initial blank space)
+ # - continuation lines (have unknown amount of initial blank space)
# - and lines which are quotes (because they may have been outdented)
my $guessed_indentation_level =
$line_of_tokens->{_guessed_indentation_level};
# keep going
}
- # if no more tokens, postpone decision until re-entring
+ # if no more tokens, postpone decision until re-entering
elsif ( ( $next_nonblank_token_type eq 'b' )
&& $rOpts_add_newlines )
{
# For signatures and extended syntax ...
# If this brace follows a parenthesized list, we should look back to
# find the keyword before the opening paren because otherwise we might
- # form a one line block which stays intack, and cause the parenthesized
+ # form a one line block which stays intact, and cause the parenthesized
# expression to break open. That looks bad.
if ( $tokens_to_go[$i_start] eq ')' ) {
# - 'grind_batch_of_CODE' determines which tokens will form the OUTPUT
# lines.
- # So sub 'process_line_of_CODE' builds up the longest possible continouus
+ # So sub 'process_line_of_CODE' builds up the longest possible continuous
# sequences of tokens, regardless of line length, and then
# grind_batch_of_CODE breaks these sequences back down into the new output
# lines.
}
my $Klimit = $self->[_Klimit_];
- # The local batch tokens must be a continous part of the global token
+ # The local batch tokens must be a continuous part of the global token
# array.
my $KK;
foreach my $ii ( 0 .. $max_index_to_go ) {
# suggested by issue c118, which pushed about 5.e5 lines through here
# and caused an excessive run time.
- # Three lines of defence have been put in place to prevent excessive
+ # Three lines of defense have been put in place to prevent excessive
# run times:
# 1. do nothing if formatting under stress (c118 was under stress)
# 2. break into small sub-sections to decrease the maximum n-squared.
elsif ( $is_opening_token{$token} ) {
- # do requeste -lp breaks at the OPENING token for BROKEN
+ # do requested -lp breaks at the OPENING token for BROKEN
# blocks. NOTE: this can be done for both -lp and -xlp,
# but only -xlp can really take advantage of this. So this
# is currently restricted to -xlp to avoid excess changes to
# or if this is not a sequenced item
|| !$last_nonblank_seqno
- # or this continer is excluded by user rules
+ # or this container is excluded by user rules
# or contains here-docs or multiline qw text
|| defined($last_nonblank_seqno)
&& $ris_excluded_lp_container->{$last_nonblank_seqno}
# to pass nesting depths to the vertical aligner. They remain invariant
# under all formatting operations. Previously, level values were sent
# to the aligner. But they can be altered in welding and other
- # opeartions, and this can lead to alignement errors.
+ # operations, and this can lead to alignment errors.
my $nesting_depth_beg = $nesting_depth_to_go[$ibeg];
my $nesting_depth_end = $nesting_depth_to_go[$iend];
$i_good_paren++;
}
- # Initializtion for 'elsif' patch: remember the paren range of
+ # Initialization for 'elsif' patch: remember the paren range of
# an elsif, and do not make alignments within them because this
# can cause loss of padding and overall brace alignment in the
# vertical aligner.
# YVES patch 1 of 2:
# Undo ci of line with leading closing eval brace,
- # but not beyond the indention of the line with
+ # but not beyond the indentation of the line with
# the opening brace.
if (
$block_type_beg eq 'eval'
my $tok = $token_beg;
my $cti = $closing_token_indentation{$tok};
- # Fix the value of 'cti' for an isloated non-welded closing qw
+ # Fix the value of 'cti' for an isolated non-welded closing qw
# delimiter.
if ( $seqno_qw_closing && $ibeg_weld_fix == $ibeg ) {
}
}
- # Full indentaion of closing tokens (-icb and -icp or -cti=2)
+ # Full indentation of closing tokens (-icb and -icp or -cti=2)
else {
# handle -icb (indented closing code block braces)
# Patch to make a line which is the end of a qw quote work with the
# -lp option. Make $token_beg look like a closing token as some
- # type even if it is not. This veriable will become
+ # type even if it is not. This variable will become
# $last_leading_token at the end of this loop. Then, if the -lp
# style is selected, and the next line is also a
# closing token, it will not get more indentation than this line.
my ($self) = @_;
# Report any tokenization errors and return a flag '$severe_error'.
- # Set $severe_error = 1 if the tokenizations errors are so severe that
+ # Set $severe_error = 1 if the tokenization errors are so severe that
# the formatter should not attempt to format the file. Instead, it will
# just output the file verbatim.
check_final_nesting_depths();
# Likewise, large numbers of brace errors usually indicate non-perl
- # scirpts, so set the severe error flag at a low number. This is similar
+ # scripts, so set the severe error flag at a low number. This is similar
# to the level check, but different because braces may balance but be
# incorrectly interlaced.
if ( $tokenizer_self->[_true_brace_error_count_] > 2 ) {
# mistaking {s} in the following for a quoted bare word:
# for(@[){s}bla}BLA}
# Also treat q in something like var{-q} as a bare word, not
- # a qoute operator
+ # a quote operator
elsif (
$next_nonblank_token eq '}'
&& (
$type = 'w';
}
- # Scan a bare word following a -> as an identifir; it could
+ # Scan a bare word following a -> as an identifier; it could
# have a long package name. Fixes c037, c041.
elsif ( $last_nonblank_token eq '->' ) {
scan_bare_identifier();
$op_expected = OPERATOR;
}
- # Patch to allow a ? following 'split' to be a depricated pattern
+ # Patch to allow a ? following 'split' to be a deprecated pattern
# delimiter. This patch is coordinated with the omission of split
# from the list
# %is_keyword_rejecting_question_as_pattern_delimiter. This patch
# Exception to weird parsing rules for 'x(' ... see case b1205:
# In something like 'print $vv x(...' the x is an operator;
- # Likewise in 'print $vv x$ww' the x is an operatory (case b1207)
+ # Likewise in 'print $vv x$ww' the x is an operator (case b1207)
# otherwise x follows the weird parsing rules.
elsif ( $tok eq 'x' && $next_type =~ /^[\(\$\@\%]$/ ) {
$op_expected = OPERATOR;
# snippet is an anonymous hash ref and not a code block!
# print 'hi' if { x => 1, }->{x};
# We can identify this situation because the last nonblank type
- # will be a keyword (instead of a closing peren)
+ # will be a keyword (instead of a closing paren)
if (
$last_nonblank_type eq 'k'
&& ( $last_nonblank_token eq 'if'
if ( $paren_type && $is_sort_map_grep{$paren_type} ) {
# We will mark this as a code block but use type 't' instead
- # of the name of the contining function. This will allow for
+ # of the name of the containing function. This will allow for
# correct parsing but will usually produce better formatting.
# Braces with block type 't' are not broken open automatically
# in the formatter as are other code block types, and this usually
# Patched for RT #95708
if (
- # it is a comma which is not a pattern delimeter except for qw
+ # it is a comma which is not a pattern delimiter except for qw
(
$pre_types[$j] eq ','
## !~ /^(s|m|y|tr|qr|q|qq|qx)$/
# These are keywords for which an arg may optionally be omitted. They are
# currently only used to disambiguate a ? used as a ternary from one used
- # as a (depricated) pattern delimiter. In the future, they might be used
+ # as a (deprecated) pattern delimiter. In the future, they might be used
# to give a warning about ambiguous syntax before a /.
# Note: split has been omitted (see not below).
my @keywords_taking_optional_arg = qw(
@is_keyword_taking_optional_arg{@keywords_taking_optional_arg} =
(1) x scalar(@keywords_taking_optional_arg);
- # This list is used to decide if a pattern delmited by question marks,
+ # This list is used to decide if a pattern delimited by question marks,
# ?pattern?, can follow one of these keywords. Note that from perl 5.22
# on, a ?pattern? is not recognized, so we can be much more strict than
# with a /pattern/. Note that 'split' is not in this list. In current
#
# The sub valign_input collects lines into groups. When a group reaches
# the maximum possible size it is processed for alignment and output.
-# The maximum group size is reached whenerver there is a change in indentation
+# The maximum group size is reached whenever there is a change in indentation
# level, a blank line, a block comment, or an external flush call. The calling
# routine may also force a break in alignment at any time.
#
# flush() is the external call to completely empty the pipeline.
my ($self) = @_;
- # push things out the pipline...
+ # push things out the pipeline...
# push out any current group lines
$self->_flush_group_lines();
# If this line has no matching tokens, then flush out the lines
# BEFORE this line unless both it and the previous line have side
- # comments. This prevents this line from pushing side coments out
+ # comments. This prevents this line from pushing side comments out
# to the right.
elsif ( $new_line->get_jmax() == 1 ) {
# two isolated (list) lines
# imax_min = number of common alignment tokens
# Return:
- # $pad_max = maximum suggested pad distnce
+ # $pad_max = maximum suggested pad distance
# = 0 if alignment not recommended
# Note that this is only for two lines which do not have alignment tokens
# in common with any other lines. It is intended for lists, but it might
# my $unknown6 = pack( "VV", 0x00, 0x1000 );
# On the other hand, it is okay to keep matching at the same
- # level such as in a simple list of commas and/or fat arrors.
+ # level such as in a simple list of commas and/or fat commas.
my $is_blocked = defined( $blocking_level[$ng] )
&& $lev > $blocking_level[$ng];
# Do not let one or two lines with a **different number of
# alignments** open up a big gap in a large block. For
# example, we will prevent something like this, where the first
- # line prys open the rest:
+ # line pries open the rest:
# $worksheet->write( "B7", "http://www.perl.com", undef, $format );
# $worksheet->write( "C7", "", $format );
# );
# In the above example, all lines have three commas at the lowest depth
- # (zero), so if there were no other alignements, these lines would all
+ # (zero), so if there were no other alignments, these lines would all
# align considering only the zero depth alignment token. But some lines
# have additional comma alignments at the next depth, so we need to decide
# if we should drop those to keep the top level alignments, or keep those
# construction. The children nodes have links up to the parent node which
# created them. Now make links in the opposite direction, so the parents
# can find the children. We store the range of children nodes ($nc_beg,
- # $nc_end) of each parent with two additional indexes in the orignal array.
+ # $nc_end) of each parent with two additional indexes in the original array.
# These will be undef if no children.
foreach my $depth ( reverse( 1 .. $MAX_DEPTH ) ) {
next unless defined( $match_tree[$depth] );
# and fake side comments. This has the consequence that the lengths of
# long lines without real side comments can cause 'push' all side comments
# to the right. This seems unusual, but testing with and without this
- # feature shows that it is usually better this way. Othewise, side
+ # feature shows that it is usually better this way. Otherwise, side
# comments can be hidden between long lines without side comments and
# thus be harder to read.