97
97
/<<[ ] * [-\\ '] * [A-Za-z0-9_] / {
98
98
s /^ \( . * \) <<[ ] * [-\\ '] * \( [A-Za-z0-9_][A-Za-z0-9_] * \) '* /<\2 >\1 << /
99
99
s /[ ] * << //
100
- : hereslurp
100
+ : hered
101
101
N
102
102
/^ <\( [^ >] * \) >. * \n [ ] * \1 [ ] * $ /! {
103
103
s /\n . * $ //
104
- b hereslurp
104
+ b hered
105
105
}
106
106
s /^ <[^ >] * > //
107
107
s /\n . * $ //
131
131
b
132
132
133
133
: subshell
134
- # bare "(" line?
134
+ # bare "(" line? -- stash for later printing
135
135
/^ [ ] * ( [ ] * $ / {
136
- # stash for later printing
137
136
h
138
137
b nextline
139
138
}
@@ -150,7 +149,7 @@ s/.*\n//
150
149
151
150
: slurp
152
151
# incomplete line "...\"
153
- /\\ $ /b incomplete
152
+ /\\ $ /b icmplte
154
153
# multi-line quoted string "...\n..."?
155
154
/" /b dqstring
156
155
# multi-line quoted string '...\n...'? (but not contraction in string "it's")
@@ -172,7 +171,7 @@ s/.*\n//
172
171
/"[^ "] * #[^ "] * " /! s /[ ] #. * $ //
173
172
}
174
173
# one-liner "case ... esac"
175
- /^ [ ] * case[ ] * .. * esac /b checkchain
174
+ /^ [ ] * case[ ] * .. * esac /b chkchn
176
175
# multi-line "case ... esac"
177
176
/^ [ ] * case[ ] .. * [ ] in /b case
178
177
# multi-line "for ... done" or "while ... done"
@@ -201,32 +200,32 @@ s/.*\n//
201
200
/^ [ ] * fi[ ] * [<>|] /b done
202
201
/^ [ ] * fi[ ] * ) /b done
203
202
# nested one-liner "(...) &&"
204
- /^ [ ] * ( . * ) [ ] * &&[ ] * $ /b checkchain
203
+ /^ [ ] * ( . * ) [ ] * &&[ ] * $ /b chkchn
205
204
# nested one-liner "(...)"
206
- /^ [ ] * ( . * ) [ ] * $ /b checkchain
205
+ /^ [ ] * ( . * ) [ ] * $ /b chkchn
207
206
# nested one-liner "(...) >x" (or "2>x" or "<x" or "|x")
208
- /^ [ ] * ( . * ) [ ] * [0-9] * [<>|] /b checkchain
207
+ /^ [ ] * ( . * ) [ ] * [0-9] * [<>|] /b chkchn
209
208
# nested multi-line "(...\n...)"
210
209
/^ [ ] * ( /b nest
211
210
# multi-line "{...\n...}"
212
211
/^ [ ] * { /b block
213
212
# closing ")" on own line -- exit subshell
214
- /^ [ ] * ) /b closesolo
213
+ /^ [ ] * ) /b clssolo
215
214
# "$((...))" -- arithmetic expansion; not closing ")"
216
- /\$ (( [^ )][^ )] * )) [^ )] * $ /b checkchain
215
+ /\$ (( [^ )][^ )] * )) [^ )] * $ /b chkchn
217
216
# "$(...)" -- command substitution; not closing ")"
218
- /\$ ( [^ )][^ )] * ) [^ )] * $ /b checkchain
217
+ /\$ ( [^ )][^ )] * ) [^ )] * $ /b chkchn
219
218
# multi-line "$(...\n...)" -- command substitution; treat as nested subshell
220
219
/\$ ( [^ )] * $ /b nest
221
220
# "=(...)" -- Bash array assignment; not closing ")"
222
- /=( /b checkchain
221
+ /=( /b chkchn
223
222
# closing "...) &&"
224
223
/) [ ] * &&[ ] * $ /b close
225
224
# closing "...)"
226
225
/) [ ] * $ /b close
227
226
# closing "...) >x" (or "2>x" or "<x" or "|x")
228
227
/) [ ] * [<>|] /b close
229
- : checkchain
228
+ : chkchn
230
229
# mark suspect if line uses ";" internally rather than "&&" (but not ";" in a
231
230
# string and not ";;" in one-liner "case...esac")
232
231
/; /{
245
244
b slurp
246
245
247
246
# found incomplete line "...\" -- slurp up next line
248
- : incomplete
247
+ : icmplte
249
248
N
250
249
s /\\ \n //
251
250
b slurp
@@ -283,11 +282,11 @@ bfolded
283
282
: heredoc
284
283
s /^ \( . * \) <<[ ] * [-\\ '] * \( [A-Za-z0-9_][A-Za-z0-9_] * \) '* /<\2 >\1 << /
285
284
s /[ ] * << //
286
- : hereslurpsub
285
+ : heredsub
287
286
N
288
287
/^ <\( [^ >] * \) >. * \n [ ] * \1 [ ] * $ /! {
289
288
s /\n . * $ //
290
- b hereslurpsub
289
+ b heredsub
291
290
}
292
291
s /^ <[^ >] * > //
293
292
s /\n . * $ //
317
316
# is 'done' or 'fi' cuddled with ")" to close subshell?
318
317
/done. * ) /b close
319
318
/fi. * ) /b close
320
- b checkchain
319
+ b chkchn
321
320
322
321
# found nested multi-line "(...\n...)" -- pass through untouched
323
322
: nest
324
323
x
325
- : nestslurp
324
+ : nstslurp
326
325
n
327
326
# closing ")" on own line -- stop nested slurp
328
- /^ [ ] * ) /b nestclose
327
+ /^ [ ] * ) /b nstclose
329
328
# comment -- not closing ")" if in comment
330
- /^ [ ] * # /b nestcontinue
329
+ /^ [ ] * # /b nstcnt
331
330
# "$((...))" -- arithmetic expansion; not closing ")"
332
- /\$ (( [^ )][^ )] * )) [^ )] * $ /b nestcontinue
331
+ /\$ (( [^ )][^ )] * )) [^ )] * $ /b nstcnt
333
332
# "$(...)" -- command substitution; not closing ")"
334
- /\$ ( [^ )][^ )] * ) [^ )] * $ /b nestcontinue
333
+ /\$ ( [^ )][^ )] * ) [^ )] * $ /b nstcnt
335
334
# closing "...)" -- stop nested slurp
336
- /) /b nestclose
337
- : nestcontinue
335
+ /) /b nstclose
336
+ : nstcnt
338
337
x
339
- b nestslurp
340
- : nestclose
338
+ b nstslurp
339
+ : nstclose
341
340
s /^ />> /
342
341
# is it "))" which closes nested and parent subshells?
343
342
/) [ ] * ) /b slurp
344
- b checkchain
343
+ b chkchn
345
344
346
345
# found multi-line "{...\n...}" block -- pass through untouched
347
346
: block
348
347
x
349
348
n
350
349
# closing "}" -- stop block slurp
351
- /} /b checkchain
350
+ /} /b chkchn
352
351
b block
353
352
354
353
# found closing ")" on own line -- drop "suspect" from final line of subshell
355
354
# since that line legitimately lacks "&&" and exit subshell loop
356
- : closesolo
355
+ : clssolo
357
356
x
358
357
s /? !AMP? ! //
359
358
p
0 commit comments