]> git.donarmstrong.com Git - perltidy.git/commitdiff
modify -nib to be exact match, not just leading match
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 2 Sep 2020 15:10:39 +0000 (08:10 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 2 Sep 2020 15:10:39 +0000 (08:10 -0700)
bin/perltidy
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm

index 5303d5bdaee1aff0c7c990bb1205087739842620..bdaf4187869435d23bb1b414dd19cef00f30508a 100755 (executable)
@@ -874,9 +874,9 @@ The B<-nibp=string> parameter may be used to change the marker for
 non-indenting braces.  The default is equivalent to -nibp='#<<<'.  The string
 that you enter must begin with a # and should be in quotes as necessary to get
 past the command shell of your system.  This string is the leading text of a
-regex pattern that is constructed by appending pre-pending a '^', so you must
-also include backslashes for characters to be taken literally rather than as
-patterns.
+regex pattern that is constructed by appending pre-pending a '^' and appending
+a'\s', so you must also include backslashes for characters to be taken
+literally rather than as patterns.
 
 For example, to match the side comment '#++', the parameter would be
   
index 91012a263f70a754a30ac46b75207e2ae2e4c4d1..48ec1c0142c13e0257cbc8720ef5bfa44f10dcf0 100644 (file)
@@ -459,20 +459,14 @@ sub trim {
 }
 
 sub max {
-    my @vals = @_;
-    my $max  = shift @vals;
-    foreach my $val (@vals) {
-        $max = ( $max < $val ) ? $val : $max;
-    }
+    my $max  = shift; 
+    for (@_) { $max = $_ > $max ? $_ : $max };
     return $max;
 }
 
 sub min {
-    my @vals = @_;
-    my $min  = shift @vals;
-    foreach my $val (@vals) {
-        $min = ( $min > $val ) ? $val : $min;
-    }
+    my $min  = shift; 
+    for (@_) { $min = $_ < $min ? $_ : $min };
     return $min;
 }
 
@@ -4623,17 +4617,30 @@ sub non_indenting_braces {
 
     my $is_non_indenting_brace = sub {
         my ($KK)       = @_;
+
+        # looking for an opening block brace
         my $token      = $rLL->[$KK]->[_TOKEN_];
         my $block_type = $rLL->[$KK]->[_BLOCK_TYPE_];
         return unless ( $token eq '{' && $block_type );
-        my $line_index = $rLL->[$KK]->[_LINE_INDEX_];
+
+        # followed by a comment
         my $K_sc       = $self->K_next_nonblank($KK);
         return unless defined($K_sc);
-        my $line_index_sc = $rLL->[$K_sc]->[_LINE_INDEX_];
-        return unless ( $line_index_sc == $line_index );
         my $type_sc = $rLL->[$K_sc]->[_TYPE_];
         return unless ( $type_sc eq '#' );
+
+        # on the same line
+        my $line_index = $rLL->[$KK]->[_LINE_INDEX_];
+        my $line_index_sc = $rLL->[$K_sc]->[_LINE_INDEX_];
+        return unless ( $line_index_sc == $line_index );
+
+        # get the side comment text
         my $token_sc = $rLL->[$K_sc]->[_TOKEN_];
+
+        # The pattern ends in \s but we have removed the newline, so
+        # we added it back for the match. That way we require an exact
+        # match to the special string and also allow additional text.
+        $token_sc .= "\n";
         return ( $token_sc =~ /$non_indenting_brace_pattern/ );
     };
 
@@ -6556,8 +6563,11 @@ sub make_format_skipping_pattern {
 
 sub make_non_indenting_brace_pattern {
 
-    # create the pattern used to identify static side comments
-    $non_indenting_brace_pattern = '^#<<<';
+    # Create the pattern used to identify static side comments.
+    # Note that we are ending the pattern in a \s. This will allow
+    # the pattern to be followed by a space and some text, or a newline.
+    # The pattern is used in sub 'non_indenting_braces'
+    $non_indenting_brace_pattern = '^#<<<\s';
 
     # allow the user to change it
     if ( $rOpts->{'non-indenting-brace-prefix'} ) {
@@ -6566,7 +6576,7 @@ sub make_non_indenting_brace_pattern {
         if ( $prefix !~ /^#/ ) {
             Die("ERROR: the -nibp parameter '$prefix' must begin with '#'\n");
         }
-        my $pattern = '^' . $prefix;
+        my $pattern = '^' . $prefix . '\s';
         if ( bad_pattern($pattern) ) {
             Die(
 "ERROR: the -nibp prefix '$prefix' causes the invalid regex '$pattern'\n"
index 16e5af4c96b40ff5b7ce0eeee146a6bd6690035e..898dc741978b89a0f9a88a42e630d12abc19b8ec 100644 (file)
@@ -136,7 +136,7 @@ use constant MAX_NAG_MESSAGES => 6;
 
 BEGIN {
 
-    # Array index names for token variables
+    # Array index names for $self
     my $i = 0;
     use constant {
         _rhere_target_list_                  => $i++,