]> git.donarmstrong.com Git - perltidy.git/commitdiff
prevent breaking package names with trailing dashes
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 26 Oct 2020 15:41:37 +0000 (08:41 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 26 Oct 2020 15:41:37 +0000 (08:41 -0700)
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index 1192a4b0d424991870d4375bcbf6c5ac6804eb9f..c788c5ca041efaf5af16ff0cc4150e98da18213d 100644 (file)
@@ -3227,6 +3227,11 @@ EOM
                 }
             }
 
+           # keep 'bareword-' together, but only if there is no space between
+           # the word and dash. Do not keep together if there is a space.
+            # example 'use perl6-alpha'
+            elsif ( $type eq 'w' && $next_type eq 'm' ) { $bond_str = NO_BREAK }
+
             # Breaking before a ? before a quote can cause trouble if
             # they are not separated by a blank.
             # Example: a syntax error occurs if you break before the ? here
index fe4972a1fa96f2d3382d6b3c7bdbbfa284375fbf..43f7cfb90823da18c7c7e429955d2fad38545a0e 100644 (file)
@@ -3202,6 +3202,17 @@ EOM
 
                     # treat bare word followed by open paren like qw(
                     if ( $next_nonblank_token eq '(' ) {
+
+                       # TODO: This works, but if $tok eq 'prototype' then we
+                       # should really parse the prototype separately here so
+                       # that we have its properties.  This requires updating
+                       # do_scan_sub to keep the subname available until we
+                       # see the opening brace.  So something like
+                        #   if ($tok eq 'prototype' ) {scan_prototype()}
+                        #   else {
+
+                       # All other attribute lists must be parsed as quotes
+                       # (see 'signatures.t' for good examples)
                         $in_quote                = $quote_items{'q'};
                         $allowed_quote_modifiers = $quote_modifiers{'q'};
                         $type                    = 'q';
index 1551c05ca01797f5e3e54b56da92f1c11466d796..866efc110f724c206e84ecf010d938bd0aaa4287 100644 (file)
@@ -2,10 +2,30 @@
 
 =over 4
 
+=item b<Prevent syntax error by breaking dashed package names>
+
+In stress testing perltidy with the -extrude option, the following test snippet 
+
+  use perl6-alpha;
+
+was broken into sepate lines
+
+  use
+  perl6
+  -
+  alpha
+  ;
+
+A rule was added to prevent breaking around a dash separating two barewords.
+Rerunning gives
+
+  use
+  perl6-alpha
+  ;
 
 =item b<Prevent syntax error by breaking dashed barewords>
 
-In random testing with the following test snippet with the -extrude option
+In stress testing perltidy with the -extrude option, using the following test snippet
 
   my %var;
   {
@@ -19,7 +39,7 @@ In random testing with the following test snippet with the -extrude option
       $var{m}   = 1;
   }
 
-a syntax error was created in the resulting file when newlines were placed
+a syntax error was created when newlines were placed
 before or after the dashes.  It is necessary to always keep a dash on the same
 line with its surrounding tokens.  A rule was added to do this.  The new
 'extruded' result for the above snippet is: