117117/^ [ ] * !* [ ] * ( .. * ) [ ] * [0-9] * [<>|&] /b oneline
118118
119119# multi-line "(...\n...)"
120- /^ [ ] * ( /b subshell
120+ /^ [ ] * ( /b subsh
121121
122122# innocuous line -- print it and advance to next line
123123b
130130}
131131b
132132
133- : subshell
133+ : subsh
134134# bare "(" line? -- stash for later printing
135135/^ [ ] * ( [ ] * $ / {
136136 h
137- b nextline
137+ b nextln
138138}
139139# "(..." line -- split off and stash "(", then process "..." as its own line
140140x
143143s /( //
144144b slurp
145145
146- : nextline
146+ : nextln
147147N
148148s /. * \n //
149149
150150: slurp
151151# incomplete line "...\"
152152/\\ $ /b icmplte
153153# multi-line quoted string "...\n..."?
154- /" /b dqstring
154+ /" /b dqstr
155155# multi-line quoted string '...\n...'? (but not contraction in string "it's")
156156/' /{
157- /"[^ '"] * '[^ '"] * " /! b sqstring
157+ /"[^ '"] * '[^ '"] * " /! b sqstr
158158}
159159: folded
160160# here-doc -- swallow it
@@ -163,8 +163,8 @@ s/.*\n//
163163# before closing ")", "done", "elsif", "else", or "fi" will need to be
164164# re-visited to drop "suspect" marking since final line of those constructs
165165# legitimately lacks "&&", so "suspect" mark must be removed
166- /^ [ ] * # /b nextline
167- /^ [ ] * $ /b nextline
166+ /^ [ ] * # /b nextln
167+ /^ [ ] * $ /b nextln
168168# in-line comment -- strip it (but not "#" in a string, Bash ${#...} array
169169# length, or Perforce "//depot/path#42" revision in filespec)
170170/[ ] # /{
@@ -175,22 +175,22 @@ s/.*\n//
175175# multi-line "case ... esac"
176176/^ [ ] * case[ ] .. * [ ] in /b case
177177# multi-line "for ... done" or "while ... done"
178- /^ [ ] * for[ ] .. * [ ] in /b continue
179- /^ [ ] * while[ ] /b continue
180- /^ [ ] * do[ ] /b continue
181- /^ [ ] * do[ ] * $ /b continue
182- /;[ ] * do /b continue
178+ /^ [ ] * for[ ] .. * [ ] in /b cont
179+ /^ [ ] * while[ ] /b cont
180+ /^ [ ] * do[ ] /b cont
181+ /^ [ ] * do[ ] * $ /b cont
182+ /;[ ] * do /b cont
183183/^ [ ] * done[ ] * &&[ ] * $ /b done
184184/^ [ ] * done[ ] * $ /b done
185185/^ [ ] * done[ ] * [<>|] /b done
186186/^ [ ] * done[ ] * ) /b done
187- /|| [ ] * exit[ ] /b continue
188- /|| [ ] * exit[ ] * $ /b continue
187+ /|| [ ] * exit[ ] /b cont
188+ /|| [ ] * exit[ ] * $ /b cont
189189# multi-line "if...elsif...else...fi"
190- /^ [ ] * if[ ] /b continue
191- /^ [ ] * then[ ] /b continue
192- /^ [ ] * then[ ] * $ /b continue
193- /;[ ] * then /b continue
190+ /^ [ ] * if[ ] /b cont
191+ /^ [ ] * then[ ] /b cont
192+ /^ [ ] * then[ ] * $ /b cont
193+ /;[ ] * then /b cont
194194/^ [ ] * elif[ ] /b else
195195/^ [ ] * elif[ ] * $ /b else
196196/^ [ ] * else[ ] /b else
@@ -234,10 +234,10 @@ s/.*\n//
234234 }
235235}
236236# line ends with pipe "...|" -- valid; not missing "&&"
237- /| [ ] * $ /b continue
237+ /| [ ] * $ /b cont
238238# missing end-of-line "&&" -- mark suspect
239239/&&[ ] * $ /! s /^ /?!AMP?! /
240- : continue
240+ : cont
241241# retrieve and print previous line
242242x
243243n
@@ -250,29 +250,29 @@ s/\\\n//
250250b slurp
251251
252252# check for multi-line double-quoted string "...\n..." -- fold to one line
253- : dqstring
253+ : dqstr
254254# remove all quote pairs
255255s /"\( [^ "] * \) " /@!\1 @! /g
256256# done if no dangling quote
257257/" /! b dqdone
258258# otherwise, slurp next line and try again
259259N
260260s /\n //
261- b dqstring
261+ b dqstr
262262: dqdone
263263s /@! /" /g
264264b folded
265265
266266# check for multi-line single-quoted string '...\n...' -- fold to one line
267- : sqstring
267+ : sqstr
268268# remove all quote pairs
269269s /'\( [^ '] * \) ' /@!\1 @! /g
270270# done if no dangling quote
271271/' /! b sqdone
272272# otherwise, slurp next line and try again
273273N
274274s /\n //
275- b sqstring
275+ b sqstr
276276: sqdone
277277s /@! /' /g
278278b folded
@@ -282,11 +282,11 @@ bfolded
282282: heredoc
283283s /^ \( . * \) <<[ ] * [-\\ '"] * \( [A-Za-z0-9_][A-Za-z0-9_] * \) ['"] * /<\2 >\1 << /
284284s /[ ] * << //
285- : heredsub
285+ : hdocsub
286286N
287287/^ <\( [^ >] * \) >. * \n [ ] * \1 [ ] * $ /! {
288288 s /\n . * $ //
289- b heredsub
289+ b hdocsub
290290}
291291s /^ <[^ >] * > //
292292s /\n . * $ //
@@ -305,7 +305,7 @@ bcase
305305x
306306s /? !AMP? ! //
307307x
308- b continue
308+ b cont
309309
310310# found "done" closing for-loop or while-loop, or "fi" closing if-then -- drop
311311# "suspect" from final contained line since that line legitimately lacks "&&"
@@ -321,22 +321,22 @@ bchkchn
321321# found nested multi-line "(...\n...)" -- pass through untouched
322322: nest
323323x
324- : nstslurp
324+ : nstslrp
325325n
326326# closing ")" on own line -- stop nested slurp
327- /^ [ ] * ) /b nstclose
327+ /^ [ ] * ) /b nstcl
328328# comment -- not closing ")" if in comment
329329/^ [ ] * # /b nstcnt
330330# "$((...))" -- arithmetic expansion; not closing ")"
331331/\$ (( [^ )][^ )] * )) [^ )] * $ /b nstcnt
332332# "$(...)" -- command substitution; not closing ")"
333333/\$ ( [^ )][^ )] * ) [^ )] * $ /b nstcnt
334334# closing "...)" -- stop nested slurp
335- /) /b nstclose
335+ /) /b nstcl
336336: nstcnt
337337x
338- b nstslurp
339- : nstclose
338+ b nstslrp
339+ : nstcl
340340s /^ />> /
341341# is it "))" which closes nested and parent subshells?
342342/) [ ] * ) /b slurp
0 commit comments