]> git.donarmstrong.com Git - perltidy.git/commitdiff
extend capability of the -wnxl flag
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 21 Nov 2020 00:41:01 +0000 (16:41 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 21 Nov 2020 00:41:01 +0000 (16:41 -0800)
bin/perltidy
docs/BugLog.html
docs/ChangeLog.html
docs/perltidy.html
lib/Perl/Tidy/Formatter.pm

index 821e450790b40fcb0cedb567922c447176a226f9..0622a563bee139235e9cb0b6c271fab46b191d2a 100755 (executable)
@@ -2445,30 +2445,30 @@ any other container stacking flags.  This is because any welding is done first.
 =item B<-wnxl=s>,  B<--weld-nested-exclusion-list> 
 
 The B<-wnxl=s> flag provides some control over the types of containers which
-can be welded.  The B<-wn> flag by default is "greedy" in welding
-adjacent containers.  If it welds more types of containers than desired,
-this flag can reduce the amount of welding by specifying a list of
-things which should B<not> be welded. 
+can be welded.  The B<-wn> flag by default is "greedy" in welding adjacent
+containers.  If it welds more types of containers than desired, this flag
+provides a capability to reduce the amount of welding by specifying a list
+of things which should B<not> be welded. 
 
-The logic in perltidy to apply this is straightforward.  As each token is being
-considered for joining a weld, any exclusion rules are consulted and used to
-reject the weld if necessary.
+The logic in perltidy to apply this is straightforward.  As each container
+token is being considered for joining a weld, any exclusion rules are consulted
+and used to reject the weld if necessary.
 
 This list is a string with space-separated items.  Each item consists of up to
 three pieces of information: (1) an optional positiion, (2) an optional
 preceding type, and (3) a container type.
 
-The required piece of information, a container type, is one of '(', '[', '{' or
-'q'.  The first three of these are container tokens and the last represents a
-quoted list.  For example the string
+The only required piece of information is a container type, which is one of
+'(', '[', '{' or 'q'.  The first three of these are container tokens and the
+last represents a quoted list.  For example the string
 
   -wnxl='[ { q'
 
 means do B<NOT> include square-bracets, braces, or quotes in any welds.  The only unspecified
 container is '(', so this string means that only welds involving parens will be made. 
 
-To illustrate this terminology, following welded snippet consists of 
-a chain of three welded containers with types '(' '[' and 'q':
+To illustrate, following welded snippet consists of a chain of three welded
+containers with types '(' '[' and 'q':
 
     # perltidy -wn
     skip_symbols( [ qw(
@@ -2487,20 +2487,26 @@ indicator which is either '^', to indicate the first token of a welded
 sequence, or '.', to indicate an interior token of a welded sequence.  (Since
 a quoted string 'q' always ends a chain it does need a position indicator).
 
-If we do not want a sequence of welded containers to start with a square
-bracket we could use
+For example, if we do not want a sequence of welded containers to start with a
+square bracket we could use
 
   -wnxl='^['
 
 In the above snippet, there is a square bracket but it does not start the chain,
-so the formatting would be unchanged with this restriction.
+so the formatting would be unchanged if it were formatted with this restriction.
 
 A third optional item of information which can be given is an alphanumeric
-letter which limits the selection depending on the type of token immediately
-before the container.  If given, it goes just before the container symbol.
-There are, at present, just two possible letters: 'k' matches if the previous
-token is a perl builtin keyword (such as 'if', 'while'), and 'K' matches if the
-previous token is not a keyword. 
+letter which is used to limit the selection further depending on the type of
+token immediately before the container.  If given, it goes just before the
+container symbol.  The possible letters are currently 'k', 'K', 'f', 'F',
+'w', and 'W', with these meanings:
+
+ 'k' matches if the previous nonblank token is a perl builtin keyword (such as 'if', 'while'), 
+ 'K' matches if 'k' does not, meaning that the previous token is not a keyword.
+ 'f' matches if the previous token is a function other than a keyword.
+ 'F' matches if 'f' does not.
+ 'w' matches if either 'k' or 'f' match.
+ 'W' matches if 'w' does not.
 
 For example, compare
 
@@ -2519,7 +2525,7 @@ with
 
 The first case does maximum welding. In the second case the leading paren is
 retained by the rule (it would have been rejected if preceded by a non-keyword)
-but the curly brace is rejected.
+but the curly brace is rejected by the rule.
 
 Here are some additional example strings and their meanings:
 
index 187a45850a48939c7e6bbaf10d2e4bf124cf0321..bc184552e28711827a3493d6d3a8d65afc75ca3a 100644 (file)
 
 <dl>
 
+<dt id="fixed-problem-with-vertical-alignments-involving-if-statements"><b>fixed problem with vertical alignments involving &#39;if&#39; statements</b></dt>
+<dd>
+
+<p>An update was made to break vertical alignment when a new sequence of if-like statements or ternary statements is encountered. This situation was causing a loss of alignment in some cases. For example</p>
+
+<pre><code>  OLD:
+    $m1 = 0;
+    if ( $value =~ /\bset\b/i )      { $m0 = 1; }
+    if ( $value =~ /\barithmetic/i ) { $m1 = 1; }
+    if    ( $m0 &amp;&amp; !$m1 ) { $CONFIG[1] = 0; }
+    elsif ( !$m0 &amp;&amp; $m1 ) { $CONFIG[1] = 1; }
+    else                  { $ok        = 0; last; }
+
+ NEW:
+    $m1 = 0;
+    if    ( $value =~ /\bset\b/i )      { $m0        = 1; }
+    if    ( $value =~ /\barithmetic/i ) { $m1        = 1; }
+    if    ( $m0 &amp;&amp; !$m1 )               { $CONFIG[1] = 0; }
+    elsif ( !$m0 &amp;&amp; $m1 )               { $CONFIG[1] = 1; }
+    else                                { $ok        = 0; last; }</code></pre>
+
+<p>This update was made 15 Nov 2020.</p>
+
+</dd>
+<dt id="added-option--wnxl-s-to-give-control-of-welding-by-the--wn-parameter"><b>added option -wnxl=s to give control of welding by the -wn parameter</b></dt>
+<dd>
+
+<p>The parameter string can restrict the types of containers which are welded. This was added 11 Nov 2020 in &#39;added -wnxl=s for control of -wn&#39;, 2e642d2.</p>
+
+</dd>
+<dt id="merged-pull-request-git-46"><b>merged pull request git #46</b></dt>
+<dd>
+
+<p>The man page gave the incorrect string for -fse. This was fixed 11 Nov 2020 in 1f9869e.</p>
+
+</dd>
 <dt id="recognize-overloaded-RPerl-operators-to-avoid-error-messages"><b>recognize overloaded RPerl operators to avoid error messages</b></dt>
 <dd>
 
index d03a02672e480d58e3b23ea4851133444fbc1109..57847dc18a035fc7c0a664b5353ab4ea52328548 100644 (file)
@@ -61,7 +61,7 @@
 
 - Added 'state' as a keyword.
 
-- This version is about 15% faster than previous versions due to some optimizations
+- This version is about 20% faster than the previous version due to optimizations
   made with the help of Devel::NYTProf.
 
 - Line breaks are now automatically placed after 'use overload' to 
index 299e002037096463575dd624a696ca58fbfa8744..edcbeda82bac309b20b5f2c5222903bd1b6e45a5 100644 (file)
 <dt id="wnxl-s---weld-nested-exclusion-list"><b>-wnxl=s</b>, <b>--weld-nested-exclusion-list</b></dt>
 <dd>
 
-<p>The <b>-wnxl=s</b> flag provides some control over the types of containers which can be welded. The <b>-wn</b> flag by default is &quot;greedy&quot; in welding adjacent containers. If it welds more types of containers than desired, this flag can reduce the amount of welding by specifying a list of things which should <b>not</b> be welded.</p>
+<p>The <b>-wnxl=s</b> flag provides some control over the types of containers which can be welded. The <b>-wn</b> flag by default is &quot;greedy&quot; in welding adjacent containers. If it welds more types of containers than desired, this flag provides a capability to reduce the amount of welding by specifying a list of things which should <b>not</b> be welded.</p>
 
-<p>The logic in perltidy to apply this is straightforward. As each token is being considered for joining a weld, any exclusion rules are consulted and used to reject the weld if necessary.</p>
+<p>The logic in perltidy to apply this is straightforward. As each container token is being considered for joining a weld, any exclusion rules are consulted and used to reject the weld if necessary.</p>
 
 <p>This list is a string with space-separated items. Each item consists of up to three pieces of information: (1) an optional positiion, (2) an optional preceding type, and (3) a container type.</p>
 
-<p>The required piece of information, a container type, is one of &#39;(&#39;, &#39;[&#39;, &#39;{&#39; or &#39;q&#39;. The first three of these are container tokens and the last represents a quoted list. For example the string</p>
+<p>The only required piece of information is a container type, which is one of &#39;(&#39;, &#39;[&#39;, &#39;{&#39; or &#39;q&#39;. The first three of these are container tokens and the last represents a quoted list. For example the string</p>
 
 <pre><code>  -wnxl=&#39;[ { q&#39;</code></pre>
 
 <p>means do <b>NOT</b> include square-bracets, braces, or quotes in any welds. The only unspecified container is &#39;(&#39;, so this string means that only welds involving parens will be made.</p>
 
-<p>To illustrate this terminology, following welded snippet consists of a chain of three welded containers with types &#39;(&#39; &#39;[&#39; and &#39;q&#39;:</p>
+<p>To illustrate, following welded snippet consists of a chain of three welded containers with types &#39;(&#39; &#39;[&#39; and &#39;q&#39;:</p>
 
 <pre><code>    # perltidy -wn
     skip_symbols( [ qw(
 
 <p>Any of the container types &#39;[&#39;, &#39;{&#39;, and &#39;(&#39; may be prefixed with a position indicator which is either &#39;^&#39;, to indicate the first token of a welded sequence, or &#39;.&#39;, to indicate an interior token of a welded sequence. (Since a quoted string &#39;q&#39; always ends a chain it does need a position indicator).</p>
 
-<p>If we do not want a sequence of welded containers to start with a square bracket we could use</p>
+<p>For example, if we do not want a sequence of welded containers to start with a square bracket we could use</p>
 
 <pre><code>  -wnxl=&#39;^[&#39;</code></pre>
 
-<p>In the above snippet, there is a square bracket but it does not start the chain, so the formatting would be unchanged with this restriction.</p>
+<p>In the above snippet, there is a square bracket but it does not start the chain, so the formatting would be unchanged if it were formatted with this restriction.</p>
 
-<p>A third optional item of information which can be given is an alphanumeric letter which limits the selection depending on the type of token immediately before the container. If given, it goes just before the container symbol. There are, at present, just two possible letters: &#39;k&#39; matches if the previous token is a perl builtin keyword (such as &#39;if&#39;, &#39;while&#39;), and &#39;K&#39; matches if the previous token is not a keyword.</p>
+<p>A third optional item of information which can be given is an alphanumeric letter which is used to limit the selection further depending on the type of token immediately before the container. If given, it goes just before the container symbol. The possible letters are currently &#39;k&#39;, &#39;K&#39;, &#39;f&#39;, &#39;F&#39;, &#39;w&#39;, and &#39;W&#39;, with these meanings:</p>
+
+<pre><code> &#39;k&#39; matches if the previous nonblank token is a perl builtin keyword (such as &#39;if&#39;, &#39;while&#39;), 
+ &#39;K&#39; matches if &#39;k&#39; does not, meaning that the previous token is not a keyword.
+ &#39;f&#39; matches if the previous token is a function other than a keyword.
+ &#39;F&#39; matches if &#39;f&#39; does not.
+ &#39;w&#39; matches if either &#39;k&#39; or &#39;f&#39; match.
+ &#39;W&#39; matches if &#39;w&#39; does not.</code></pre>
 
 <p>For example, compare</p>
 
                   {&#39;username&#39;} }
         ) )</code></pre>
 
-<p>The first case does maximum welding. In the second case the leading paren is retained by the rule (it would have been rejected if preceded by a non-keyword) but the curly brace is rejected.</p>
+<p>The first case does maximum welding. In the second case the leading paren is retained by the rule (it would have been rejected if preceded by a non-keyword) but the curly brace is rejected by the rule.</p>
 
 <p>Here are some additional example strings and their meanings:</p>
 
index d66fd1f33701ee36731fb7f2d5fafa6c9a6620de..34173067ab6fad66a375206507a141d277eb5adb 100644 (file)
@@ -1535,7 +1535,7 @@ sub initialize_weld_nested_exclusion_rules {
     # with spaces separating any number of items.  Each item consists of three
     # pieces of information:
     # <optional position> <optional type> <type of container>
-    # <     ^ or .      > <    k or K   > <     ( [ {       >
+    # <     ^ or .      > <[k K f F w W]> <     ( [ {       >
 
     # The last character is the required container type and must be one of:
     # ( = paren
@@ -1551,6 +1551,10 @@ sub initialize_weld_nested_exclusion_rules {
     # token selects to which the rule applies:
     # k = any keyword
     # K = any non-keyword
+    # f = function
+    # F = not a function call
+    # w = function or keyword
+    # W = not a function or keyword
     #     no letter means any preceding type matches
 
     # Examples:
@@ -1587,7 +1591,7 @@ sub initialize_weld_nested_exclusion_rules {
         my $pos    = '*';
         my $select = '*';
         if ($item) {
-            if ( $item =~ /^([\^\.])?([kK])?$/ ) {
+            if ( $item =~ /^([\^\.])?([kKfFwW])?$/ ) {
                 $pos    = $1 if ($1);
                 $select = $2 if ($2);
             }
@@ -6325,14 +6329,35 @@ sub is_excluded_weld {
     my $flag = $is_leading ? $rflags->[0] : $rflags->[1];
     return 0 unless ( defined($flag) );
     return 1 if $flag eq '*';
-    my $Kp     = $self->K_previous_nonblank($KK);
-    my $type_p = 'b';
-    if ( defined($Kp) ) { $type_p = $rLL->[$Kp]->[_TYPE_] }
 
-    if ( $flag eq 'k' && $type_p eq 'k' || $flag eq 'K' && $type_p ne 'k' ) {
-        return 1;
-    }
-    return 0;
+    my ( $is_f, $is_k, $is_w );
+    my $Kp = $self->K_previous_nonblank($KK);
+    if ( defined($Kp) ) {
+        my $type_p  = $rLL->[$Kp]->[_TYPE_];
+        my $token_p = $rLL->[$Kp]->[_TOKEN_];
+
+        # keyword?
+        $is_k = $type_p eq 'k';
+
+        # function call? Use the same definition as used for
+        # the parameter 'space-function-paren'
+        $is_f =
+             $type_p =~ /^[wUG]$/
+          || $type_p eq '->'
+          || $type_p =~ /^[wi]$/ && $token_p =~ /^(\&|->)/;
+
+        # either keyword or function call?
+        $is_w = $is_k || $is_f;
+    }
+
+    my $match;
+    if    ( $flag eq 'k' ) { $match = $is_k }
+    elsif ( $flag eq 'K' ) { $match = !$is_k }
+    elsif ( $flag eq 'f' ) { $match = $is_f }
+    elsif ( $flag eq 'F' ) { $match = !$is_f }
+    elsif ( $flag eq 'w' ) { $match = $is_w }
+    elsif ( $flag eq 'W' ) { $match = !$is_w }
+    return $match;
 }
 
 sub weld_nested_containers {