Message ID | f5dbcbf78db127d738c11a1aca416201298426cf.1661992197.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | fb41727b7ed7f62d121cd846f826fb1c62d1bc6a |
Headers | show |
Series | make test "linting" more comprehensive | expand |
Hi Eric, On Thu, 1 Sep 2022, Eric Sunshine via GitGitGadget wrote: > contrib/buildsystems/CMakeLists.txt | 2 +- > t/Makefile | 49 +- > t/README | 5 - > t/chainlint.pl | 730 ++++++++++++++++++ > t/chainlint.sed | 399 ---------- > t/chainlint/blank-line-before-esac.expect | 18 + > t/chainlint/blank-line-before-esac.test | 19 + > t/chainlint/block.expect | 15 +- > t/chainlint/block.test | 15 +- > t/chainlint/chain-break-background.expect | 9 + > t/chainlint/chain-break-background.test | 10 + > t/chainlint/chain-break-continue.expect | 12 + > t/chainlint/chain-break-continue.test | 13 + > t/chainlint/chain-break-false.expect | 9 + > t/chainlint/chain-break-false.test | 10 + > t/chainlint/chain-break-return-exit.expect | 19 + > t/chainlint/chain-break-return-exit.test | 23 + > t/chainlint/chain-break-status.expect | 9 + > t/chainlint/chain-break-status.test | 11 + > t/chainlint/chained-block.expect | 9 + > t/chainlint/chained-block.test | 11 + > t/chainlint/chained-subshell.expect | 10 + > t/chainlint/chained-subshell.test | 13 + > .../command-substitution-subsubshell.expect | 2 + > .../command-substitution-subsubshell.test | 3 + > t/chainlint/complex-if-in-cuddled-loop.expect | 2 +- > t/chainlint/double-here-doc.expect | 2 + > t/chainlint/double-here-doc.test | 12 + > t/chainlint/dqstring-line-splice.expect | 3 + > t/chainlint/dqstring-line-splice.test | 7 + > t/chainlint/dqstring-no-interpolate.expect | 11 + > t/chainlint/dqstring-no-interpolate.test | 15 + > t/chainlint/empty-here-doc.expect | 3 + > t/chainlint/empty-here-doc.test | 5 + > t/chainlint/exclamation.expect | 4 + > t/chainlint/exclamation.test | 8 + > t/chainlint/for-loop-abbreviated.expect | 5 + > t/chainlint/for-loop-abbreviated.test | 6 + > t/chainlint/for-loop.expect | 4 +- > t/chainlint/function.expect | 11 + > t/chainlint/function.test | 13 + > t/chainlint/here-doc-indent-operator.expect | 5 + > t/chainlint/here-doc-indent-operator.test | 13 + > t/chainlint/here-doc-multi-line-string.expect | 3 +- > t/chainlint/if-condition-split.expect | 7 + > t/chainlint/if-condition-split.test | 8 + > t/chainlint/if-in-loop.expect | 2 +- > t/chainlint/if-in-loop.test | 2 +- > t/chainlint/loop-detect-failure.expect | 15 + > t/chainlint/loop-detect-failure.test | 17 + > t/chainlint/loop-detect-status.expect | 18 + > t/chainlint/loop-detect-status.test | 19 + > t/chainlint/loop-in-if.expect | 2 +- > t/chainlint/loop-upstream-pipe.expect | 10 + > t/chainlint/loop-upstream-pipe.test | 11 + > t/chainlint/multi-line-string.expect | 11 +- > t/chainlint/nested-loop-detect-failure.expect | 31 + > t/chainlint/nested-loop-detect-failure.test | 35 + > t/chainlint/nested-subshell.expect | 2 +- > t/chainlint/one-liner-for-loop.expect | 9 + > t/chainlint/one-liner-for-loop.test | 10 + > t/chainlint/return-loop.expect | 5 + > t/chainlint/return-loop.test | 6 + > t/chainlint/semicolon.expect | 2 +- > t/chainlint/sqstring-in-sqstring.expect | 4 + > t/chainlint/sqstring-in-sqstring.test | 5 + > t/chainlint/t7900-subtree.expect | 13 +- > t/chainlint/token-pasting.expect | 27 + > t/chainlint/token-pasting.test | 32 + > t/chainlint/while-loop.expect | 4 +- > t/t0027-auto-crlf.sh | 7 +- > t/t3070-wildmatch.sh | 5 - > t/test-lib.sh | 12 +- > 73 files changed, 1439 insertions(+), 449 deletions(-) > create mode 100755 t/chainlint.pl > delete mode 100644 t/chainlint.sed > create mode 100644 t/chainlint/blank-line-before-esac.expect > create mode 100644 t/chainlint/blank-line-before-esac.test > create mode 100644 t/chainlint/chain-break-background.expect > create mode 100644 t/chainlint/chain-break-background.test > create mode 100644 t/chainlint/chain-break-continue.expect > create mode 100644 t/chainlint/chain-break-continue.test > create mode 100644 t/chainlint/chain-break-false.expect > create mode 100644 t/chainlint/chain-break-false.test > create mode 100644 t/chainlint/chain-break-return-exit.expect > create mode 100644 t/chainlint/chain-break-return-exit.test > create mode 100644 t/chainlint/chain-break-status.expect > create mode 100644 t/chainlint/chain-break-status.test > create mode 100644 t/chainlint/chained-block.expect > create mode 100644 t/chainlint/chained-block.test > create mode 100644 t/chainlint/chained-subshell.expect > create mode 100644 t/chainlint/chained-subshell.test > create mode 100644 t/chainlint/command-substitution-subsubshell.expect > create mode 100644 t/chainlint/command-substitution-subsubshell.test > create mode 100644 t/chainlint/double-here-doc.expect > create mode 100644 t/chainlint/double-here-doc.test > create mode 100644 t/chainlint/dqstring-line-splice.expect > create mode 100644 t/chainlint/dqstring-line-splice.test > create mode 100644 t/chainlint/dqstring-no-interpolate.expect > create mode 100644 t/chainlint/dqstring-no-interpolate.test > create mode 100644 t/chainlint/empty-here-doc.expect > create mode 100644 t/chainlint/empty-here-doc.test > create mode 100644 t/chainlint/exclamation.expect > create mode 100644 t/chainlint/exclamation.test > create mode 100644 t/chainlint/for-loop-abbreviated.expect > create mode 100644 t/chainlint/for-loop-abbreviated.test > create mode 100644 t/chainlint/function.expect > create mode 100644 t/chainlint/function.test > create mode 100644 t/chainlint/here-doc-indent-operator.expect > create mode 100644 t/chainlint/here-doc-indent-operator.test > create mode 100644 t/chainlint/if-condition-split.expect > create mode 100644 t/chainlint/if-condition-split.test > create mode 100644 t/chainlint/loop-detect-failure.expect > create mode 100644 t/chainlint/loop-detect-failure.test > create mode 100644 t/chainlint/loop-detect-status.expect > create mode 100644 t/chainlint/loop-detect-status.test > create mode 100644 t/chainlint/loop-upstream-pipe.expect > create mode 100644 t/chainlint/loop-upstream-pipe.test > create mode 100644 t/chainlint/nested-loop-detect-failure.expect > create mode 100644 t/chainlint/nested-loop-detect-failure.test > create mode 100644 t/chainlint/one-liner-for-loop.expect > create mode 100644 t/chainlint/one-liner-for-loop.test > create mode 100644 t/chainlint/return-loop.expect > create mode 100644 t/chainlint/return-loop.test > create mode 100644 t/chainlint/sqstring-in-sqstring.expect > create mode 100644 t/chainlint/sqstring-in-sqstring.test > create mode 100644 t/chainlint/token-pasting.expect > create mode 100644 t/chainlint/token-pasting.test This looks like it was a lot of work. And that it would be a lot of work to review, too, and certainly even more work to maintain. Are we really sure that we want to burden the Git project with this much stuff that is not actually related to Git's core functionality? It would be one thing if we could use a well-maintained third-party tool to do this job. But adding this to our plate? I hope we can avoid that. Ciao, Dscho
On Fri, Sep 2, 2022 at 8:42 AM Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote: > On Thu, 1 Sep 2022, Eric Sunshine via GitGitGadget wrote: > > t/chainlint.pl | 730 ++++++++++++++++++ > > t/chainlint.sed | 399 ---------- > > t/chainlint/blank-line-before-esac.expect | 18 + > > t/chainlint/blank-line-before-esac.test | 19 + > > ... > > This looks like it was a lot of work. And that it would be a lot of work > to review, too, and certainly even more work to maintain. > > Are we really sure that we want to burden the Git project with this much > stuff that is not actually related to Git's core functionality? > > It would be one thing if we could use a well-maintained third-party tool > to do this job. But adding this to our plate? I hope we can avoid that. I understand your concerns about review and maintenance burden, and you're not the first to make such observations; when chainlint.sed was submitted, it was greeted with similar concerns[1,2], all very understandable. The key takeaway[3] from that conversation, though, was that, unlike user-facing features which must be reviewed in detail and maintained in perpetuity, this is a mere developer aid which can be easily ejected from the project if it ever becomes a maintenance burden or shows itself to be unreliable. Potential maintenance burden aside, a very real benefit of such a tool is that it should help prevent bugs from slipping into the project going forward[4], which is indeed the aim of all our developer-focused aids. In more practical terms, despite initial concerns, in the 4+ years since its introduction, the maintenance cost of chainlint.sed has been nearly zero. Very early on, there was a report[5] that chainlint.sed was showing a false-positive in a `contrib` test script; the developer quickly responded with a fix[6]. The only other maintenance issues were a couple dead-simple changes[7,8] to shorten "labels" to support older versions of `sed`. (As for the chainlint self-tests, the maintenance cost has been exactly zero). My hope is that chainlint.pl should have a similar track-record, but it can easily be dropped from the project if not. [1]: https://lore.kernel.org/git/xmqqk1q11mkj.fsf@gitster-ct.c.googlers.com/ [2]: https://lore.kernel.org/git/20180712165608.GA10515@sigill.intra.peff.net/ [3]: https://lore.kernel.org/git/CAPig+cRmAkiYqFXwRAkQALDoOo-79r2iAumdEJEZhBnETvL-fw@mail.gmail.com/ [4]: https://lore.kernel.org/git/xmqqin5kw7q3.fsf@gitster-ct.c.googlers.com/ [5]: https://lore.kernel.org/git/20180730181356.GA156463@aiede.svl.corp.google.com/ [6]: https://lore.kernel.org/git/20180807082135.60913-1-sunshine@sunshineco.com/ [7]: https://lore.kernel.org/git/20180824152016.20286-5-avarab@gmail.com/ [8]: https://lore.kernel.org/git/d15ed626de65c51ef2ba31020eeb2111fb8e091f.1596675905.git.gitgitgadget@gmail.com/
On Fri, Sep 02, 2022 at 02:16:21PM -0400, Eric Sunshine wrote: > > It would be one thing if we could use a well-maintained third-party tool > > to do this job. But adding this to our plate? I hope we can avoid that. > > I understand your concerns about review and maintenance burden, and > you're not the first to make such observations; when chainlint.sed was > submitted, it was greeted with similar concerns[1,2], all very > understandable. The key takeaway[3] from that conversation, though, > was that, unlike user-facing features which must be reviewed in detail > and maintained in perpetuity, this is a mere developer aid which can > be easily ejected from the project if it ever becomes a maintenance > burden or shows itself to be unreliable. Potential maintenance burden > aside, a very real benefit of such a tool is that it should help > prevent bugs from slipping into the project going forward[4], which is > indeed the aim of all our developer-focused aids. Thanks for this response and especially the links. My initial gut response was similar to Dscho's. Which is not surprising, because it apparently was also my initial response to chainlint.sed back then. ;) But I do think that chainlint.sed has proven itself to be both useful and not much of a maintenance burden. My only real complaint was the additional runtime in a few corner cases, and that is exactly what you're addressing here. I'm not excited about carefully reviewing it. At the same time, given the low stakes, I'm kind of willing to accept that between the tests and the results of running it on the current code base, the proof is in the pudding. -Peff
Jeff King <peff@peff.net> writes: > Thanks for this response and especially the links. My initial gut > response was similar to Dscho's. Which is not surprising, because it > apparently was also my initial response to chainlint.sed back then. ;) > > But I do think that chainlint.sed has proven itself to be both useful > and not much of a maintenance burden. My only real complaint was the > additional runtime in a few corner cases, and that is exactly what > you're addressing here. I have nothing to add to the above ;-) Thanks all (including Dscho who made us be more explicit in pros-and-cons).
diff --git a/t/chainlint.sed b/t/chainlint.sed deleted file mode 100644 index dc4ce37cb51..00000000000 --- a/t/chainlint.sed +++ /dev/null @@ -1,399 +0,0 @@ -#------------------------------------------------------------------------------ -# Detect broken &&-chains in tests. -# -# At present, only &&-chains in subshells are examined by this linter; -# top-level &&-chains are instead checked directly by the test framework. Like -# the top-level &&-chain linter, the subshell linter (intentionally) does not -# check &&-chains within {...} blocks. -# -# Checking for &&-chain breakage is done line-by-line by pure textual -# inspection. -# -# Incomplete lines (those ending with "\") are stitched together with following -# lines to simplify processing, particularly of "one-liner" statements. -# Top-level here-docs are swallowed to avoid false positives within the -# here-doc body, although the statement to which the here-doc is attached is -# retained. -# -# Heuristics are used to detect end-of-subshell when the closing ")" is cuddled -# with the final subshell statement on the same line: -# -# (cd foo && -# bar) -# -# in order to avoid misinterpreting the ")" in constructs such as "x=$(...)" -# and "case $x in *)" as ending the subshell. -# -# Lines missing a final "&&" are flagged with "?!AMP?!", as are lines which -# chain commands with ";" internally rather than "&&". A line may be flagged -# for both violations. -# -# Detection of a missing &&-link in a multi-line subshell is complicated by the -# fact that the last statement before the closing ")" must not end with "&&". -# Since processing is line-by-line, it is not known whether a missing "&&" is -# legitimate or not until the _next_ line is seen. To accommodate this, within -# multi-line subshells, each line is stored in sed's "hold" area until after -# the next line is seen and processed. If the next line is a stand-alone ")", -# then a missing "&&" on the previous line is legitimate; otherwise a missing -# "&&" is a break in the &&-chain. -# -# ( -# cd foo && -# bar -# ) -# -# In practical terms, when "bar" is encountered, it is flagged with "?!AMP?!", -# but when the stand-alone ")" line is seen which closes the subshell, the -# "?!AMP?!" violation is removed from the "bar" line (retrieved from the "hold" -# area) since the final statement of a subshell must not end with "&&". The -# final line of a subshell may still break the &&-chain by using ";" internally -# to chain commands together rather than "&&", but an internal "?!AMP?!" is -# never removed from a line even though a line-ending "?!AMP?!" might be. -# -# Care is taken to recognize the last _statement_ of a multi-line subshell, not -# necessarily the last textual _line_ within the subshell, since &&-chaining -# applies to statements, not to lines. Consequently, blank lines, comment -# lines, and here-docs are swallowed (but not the command to which the here-doc -# is attached), leaving the last statement in the "hold" area, not the last -# line, thus simplifying &&-link checking. -# -# The final statement before "done" in for- and while-loops, and before "elif", -# "else", and "fi" in if-then-else likewise must not end with "&&", thus -# receives similar treatment. -# -# Swallowing here-docs with arbitrary tags requires a bit of finesse. When a -# line such as "cat <<EOF" is seen, the here-doc tag is copied to the front of -# the line enclosed in angle brackets as a sentinel, giving "<EOF>cat <<EOF". -# As each subsequent line is read, it is appended to the target line and a -# (whitespace-loose) back-reference match /^<(.*)>\n\1$/ is attempted to see if -# the content inside "<...>" matches the entirety of the newly-read line. For -# instance, if the next line read is "some data", when concatenated with the -# target line, it becomes "<EOF>cat <<EOF\nsome data", and a match is attempted -# to see if "EOF" matches "some data". Since it doesn't, the next line is -# attempted. When a line consisting of only "EOF" (and possible whitespace) is -# encountered, it is appended to the target line giving "<EOF>cat <<EOF\nEOF", -# in which case the "EOF" inside "<...>" does match the text following the -# newline, thus the closing here-doc tag has been found. The closing tag line -# and the "<...>" prefix on the target line are then discarded, leaving just -# the target line "cat <<EOF". -#------------------------------------------------------------------------------ - -# incomplete line -- slurp up next line -:squash -/\\$/ { - N - s/\\\n// - bsquash -} - -# here-doc -- swallow it to avoid false hits within its body (but keep the -# command to which it was attached) -/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/ { - /"[^"]*<<[^"]*"/bnotdoc - s/^\(.*<<-*[ ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1\2/ - :hered - N - /^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{ - s/\n.*$// - bhered - } - s/^<[^>]*>// - s/\n.*$// -} -:notdoc - -# one-liner "(...) &&" -/^[ ]*!*[ ]*(..*)[ ]*&&[ ]*$/boneline - -# same as above but without trailing "&&" -/^[ ]*!*[ ]*(..*)[ ]*$/boneline - -# one-liner "(...) >x" (or "2>x" or "<x" or "|x" or "&" -/^[ ]*!*[ ]*(..*)[ ]*[0-9]*[<>|&]/boneline - -# multi-line "(...\n...)" -/^[ ]*(/bsubsh - -# innocuous line -- print it and advance to next line -b - -# found one-liner "(...)" -- mark suspect if it uses ";" internally rather than -# "&&" (but not ";" in a string) -:oneline -/;/{ - /"[^"]*;[^"]*"/!s/;/; ?!AMP?!/ -} -b - -:subsh -# bare "(" line? -- stash for later printing -/^[ ]*([ ]*$/ { - h - bnextln -} -# "(..." line -- "(" opening subshell cuddled with command; temporarily replace -# "(" with sentinel "^" and process the line as if "(" had been seen solo on -# the preceding line; this temporary replacement prevents several rules from -# accidentally thinking "(" introduces a nested subshell; "^" is changed back -# to "(" at output time -x -s/.*// -x -s/(/^/ -bslurp - -:nextln -N -s/.*\n// - -:slurp -# incomplete line "...\" -/\\$/bicmplte -# multi-line quoted string "...\n..."? -/"/bdqstr -# multi-line quoted string '...\n...'? (but not contraction in string "it's") -/'/{ - /"[^'"]*'[^'"]*"/!bsqstr -} -:folded -# here-doc -- swallow it (but not "<<" in a string) -/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/{ - /"[^"]*<<[^"]*"/!bheredoc -} -# comment or empty line -- discard since final non-comment, non-empty line -# before closing ")", "done", "elsif", "else", or "fi" will need to be -# re-visited to drop "suspect" marking since final line of those constructs -# legitimately lacks "&&", so "suspect" mark must be removed -/^[ ]*#/bnextln -/^[ ]*$/bnextln -# in-line comment -- strip it (but not "#" in a string, Bash ${#...} array -# length, or Perforce "//depot/path#42" revision in filespec) -/[ ]#/{ - /"[^"]*#[^"]*"/!s/[ ]#.*$// -} -# one-liner "case ... esac" -/^[ ^]*case[ ]*..*esac/bchkchn -# multi-line "case ... esac" -/^[ ^]*case[ ]..*[ ]in/bcase -# multi-line "for ... done" or "while ... done" -/^[ ^]*for[ ]..*[ ]in/bcont -/^[ ^]*while[ ]/bcont -/^[ ]*do[ ]/bcont -/^[ ]*do[ ]*$/bcont -/;[ ]*do/bcont -/^[ ]*done[ ]*&&[ ]*$/bdone -/^[ ]*done[ ]*$/bdone -/^[ ]*done[ ]*[<>|]/bdone -/^[ ]*done[ ]*)/bdone -/||[ ]*exit[ ]/bcont -/||[ ]*exit[ ]*$/bcont -# multi-line "if...elsif...else...fi" -/^[ ^]*if[ ]/bcont -/^[ ]*then[ ]/bcont -/^[ ]*then[ ]*$/bcont -/;[ ]*then/bcont -/^[ ]*elif[ ]/belse -/^[ ]*elif[ ]*$/belse -/^[ ]*else[ ]/belse -/^[ ]*else[ ]*$/belse -/^[ ]*fi[ ]*&&[ ]*$/bdone -/^[ ]*fi[ ]*$/bdone -/^[ ]*fi[ ]*[<>|]/bdone -/^[ ]*fi[ ]*)/bdone -# nested one-liner "(...) &&" -/^[ ^]*(.*)[ ]*&&[ ]*$/bchkchn -# nested one-liner "(...)" -/^[ ^]*(.*)[ ]*$/bchkchn -# nested one-liner "(...) >x" (or "2>x" or "<x" or "|x") -/^[ ^]*(.*)[ ]*[0-9]*[<>|]/bchkchn -# nested multi-line "(...\n...)" -/^[ ^]*(/bnest -# multi-line "{...\n...}" -/^[ ^]*{/bblock -# closing ")" on own line -- exit subshell -/^[ ]*)/bclssolo -# "$((...))" -- arithmetic expansion; not closing ")" -/\$(([^)][^)]*))[^)]*$/bchkchn -# "$(...)" -- command substitution; not closing ")" -/\$([^)][^)]*)[^)]*$/bchkchn -# multi-line "$(...\n...)" -- command substitution; treat as nested subshell -/\$([^)]*$/bnest -# "=(...)" -- Bash array assignment; not closing ")" -/=(/bchkchn -# closing "...) &&" -/)[ ]*&&[ ]*$/bclose -# closing "...)" -/)[ ]*$/bclose -# closing "...) >x" (or "2>x" or "<x" or "|x") -/)[ ]*[<>|]/bclose -:chkchn -# mark suspect if line uses ";" internally rather than "&&" (but not ";" in a -# string and not ";;" in one-liner "case...esac") -/;/{ - /;;/!{ - /"[^"]*;[^"]*"/!s/;/; ?!AMP?!/ - } -} -# line ends with pipe "...|" -- valid; not missing "&&" -/|[ ]*$/bcont -# missing end-of-line "&&" -- mark suspect -/&&[ ]*$/!s/$/ ?!AMP?!/ -:cont -# retrieve and print previous line -x -s/^\([ ]*\)^/\1(/ -s/?!HERE?!/<</g -n -bslurp - -# found incomplete line "...\" -- slurp up next line -:icmplte -N -s/\\\n// -bslurp - -# check for multi-line double-quoted string "...\n..." -- fold to one line -:dqstr -# remove all quote pairs -s/"\([^"]*\)"/@!\1@!/g -# done if no dangling quote -/"/!bdqdone -# otherwise, slurp next line and try again -N -s/\n// -bdqstr -:dqdone -s/@!/"/g -bfolded - -# check for multi-line single-quoted string '...\n...' -- fold to one line -:sqstr -# remove all quote pairs -s/'\([^']*\)'/@!\1@!/g -# done if no dangling quote -/'/!bsqdone -# otherwise, slurp next line and try again -N -s/\n// -bsqstr -:sqdone -s/@!/'/g -bfolded - -# found here-doc -- swallow it to avoid false hits within its body (but keep -# the command to which it was attached) -:heredoc -s/^\(.*\)<<\(-*[ ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\3>\1?!HERE?!\2\3/ -:hdocsub -N -/^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{ - s/\n.*$// - bhdocsub -} -s/^<[^>]*>// -s/\n.*$// -bfolded - -# found "case ... in" -- pass through untouched -:case -x -s/^\([ ]*\)^/\1(/ -s/?!HERE?!/<</g -n -:cascom -/^[ ]*#/{ - N - s/.*\n// - bcascom -} -/^[ ]*esac/bslurp -bcase - -# found "else" or "elif" -- drop "suspect" from final line before "else" since -# that line legitimately lacks "&&" -:else -x -s/\( ?!AMP?!\)* ?!AMP?!$// -x -bcont - -# found "done" closing for-loop or while-loop, or "fi" closing if-then -- drop -# "suspect" from final contained line since that line legitimately lacks "&&" -:done -x -s/\( ?!AMP?!\)* ?!AMP?!$// -x -# is 'done' or 'fi' cuddled with ")" to close subshell? -/done.*)/bclose -/fi.*)/bclose -bchkchn - -# found nested multi-line "(...\n...)" -- pass through untouched -:nest -x -:nstslrp -s/^\([ ]*\)^/\1(/ -s/?!HERE?!/<</g -n -:nstcom -# comment -- not closing ")" if in comment -/^[ ]*#/{ - N - s/.*\n// - bnstcom -} -# closing ")" on own line -- stop nested slurp -/^[ ]*)/bnstcl -# "$((...))" -- arithmetic expansion; not closing ")" -/\$(([^)][^)]*))[^)]*$/bnstcnt -# "$(...)" -- command substitution; not closing ")" -/\$([^)][^)]*)[^)]*$/bnstcnt -# closing "...)" -- stop nested slurp -/)/bnstcl -:nstcnt -x -bnstslrp -:nstcl -# is it "))" which closes nested and parent subshells? -/)[ ]*)/bslurp -bchkchn - -# found multi-line "{...\n...}" block -- pass through untouched -:block -x -s/^\([ ]*\)^/\1(/ -s/?!HERE?!/<</g -n -:blkcom -/^[ ]*#/{ - N - s/.*\n// - bblkcom -} -# closing "}" -- stop block slurp -/}/bchkchn -bblock - -# found closing ")" on own line -- drop "suspect" from final line of subshell -# since that line legitimately lacks "&&" and exit subshell loop -:clssolo -x -s/\( ?!AMP?!\)* ?!AMP?!$// -s/^\([ ]*\)^/\1(/ -s/?!HERE?!/<</g -p -x -s/^\([ ]*\)^/\1(/ -s/?!HERE?!/<</g -b - -# found closing "...)" -- exit subshell loop -:close -x -s/^\([ ]*\)^/\1(/ -s/?!HERE?!/<</g -p -x -s/^\([ ]*\)^/\1(/ -s/?!HERE?!/<</g -b