shell-dsl 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/commands/cd/cd.cjs +66 -0
- package/dist/cjs/src/commands/cd/cd.cjs.map +10 -0
- package/dist/cjs/src/commands/index.cjs +10 -2
- package/dist/cjs/src/commands/index.cjs.map +3 -3
- package/dist/cjs/src/commands/ls/ls.cjs +65 -42
- package/dist/cjs/src/commands/ls/ls.cjs.map +3 -3
- package/dist/cjs/src/commands/sed/sed.cjs +291 -76
- package/dist/cjs/src/commands/sed/sed.cjs.map +3 -3
- package/dist/cjs/src/commands/tr/tr.cjs +223 -0
- package/dist/cjs/src/commands/tr/tr.cjs.map +10 -0
- package/dist/cjs/src/commands/tree/tree.cjs +7 -4
- package/dist/cjs/src/commands/tree/tree.cjs.map +3 -3
- package/dist/cjs/src/interpreter/context.cjs +3 -2
- package/dist/cjs/src/interpreter/context.cjs.map +3 -3
- package/dist/cjs/src/interpreter/interpreter.cjs +4 -2
- package/dist/cjs/src/interpreter/interpreter.cjs.map +3 -3
- package/dist/cjs/src/parser/parser.cjs +11 -2
- package/dist/cjs/src/parser/parser.cjs.map +3 -3
- package/dist/cjs/src/types.cjs.map +2 -2
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/src/commands/cd/cd.mjs +36 -0
- package/dist/mjs/src/commands/cd/cd.mjs.map +10 -0
- package/dist/mjs/src/commands/index.mjs +10 -2
- package/dist/mjs/src/commands/index.mjs.map +3 -3
- package/dist/mjs/src/commands/ls/ls.mjs +65 -42
- package/dist/mjs/src/commands/ls/ls.mjs.map +3 -3
- package/dist/mjs/src/commands/sed/sed.mjs +291 -76
- package/dist/mjs/src/commands/sed/sed.mjs.map +3 -3
- package/dist/mjs/src/commands/tr/tr.mjs +193 -0
- package/dist/mjs/src/commands/tr/tr.mjs.map +10 -0
- package/dist/mjs/src/commands/tree/tree.mjs +7 -4
- package/dist/mjs/src/commands/tree/tree.mjs.map +3 -3
- package/dist/mjs/src/interpreter/context.mjs +3 -2
- package/dist/mjs/src/interpreter/context.mjs.map +3 -3
- package/dist/mjs/src/interpreter/interpreter.mjs +4 -2
- package/dist/mjs/src/interpreter/interpreter.mjs.map +3 -3
- package/dist/mjs/src/parser/parser.mjs +11 -2
- package/dist/mjs/src/parser/parser.mjs.map +3 -3
- package/dist/mjs/src/types.mjs.map +2 -2
- package/dist/types/src/commands/cd/cd.d.ts +2 -0
- package/dist/types/src/commands/index.d.ts +2 -0
- package/dist/types/src/commands/tr/tr.d.ts +2 -0
- package/dist/types/src/interpreter/context.d.ts +1 -0
- package/dist/types/src/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -56,40 +56,110 @@ function parseSubstitution(script) {
|
|
|
56
56
|
}
|
|
57
57
|
function parseCommand(script) {
|
|
58
58
|
const trimmed = script.trim();
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
globalFlag: false,
|
|
67
|
-
printFlag: false
|
|
68
|
-
};
|
|
69
|
-
} catch {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
59
|
+
if (trimmed.startsWith(":")) {
|
|
60
|
+
return {
|
|
61
|
+
type: "label",
|
|
62
|
+
label: trimmed.slice(1).trim(),
|
|
63
|
+
globalFlag: false,
|
|
64
|
+
printFlag: false
|
|
65
|
+
};
|
|
72
66
|
}
|
|
73
|
-
if (trimmed === "
|
|
74
|
-
return {
|
|
67
|
+
if (trimmed === "b" || trimmed.startsWith("b ") || trimmed.startsWith("b\t")) {
|
|
68
|
+
return {
|
|
69
|
+
type: "b",
|
|
70
|
+
label: trimmed.length > 1 ? trimmed.slice(1).trim() : undefined,
|
|
71
|
+
globalFlag: false,
|
|
72
|
+
printFlag: false
|
|
73
|
+
};
|
|
75
74
|
}
|
|
76
|
-
if (trimmed
|
|
77
|
-
|
|
75
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
76
|
+
const inner = trimmed.slice(1, -1).trim();
|
|
77
|
+
const parts = splitScriptParts(inner);
|
|
78
|
+
const children = [];
|
|
79
|
+
for (const part of parts) {
|
|
80
|
+
const cmd = parseCommand(part);
|
|
81
|
+
if (cmd)
|
|
82
|
+
children.push(cmd);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
type: "group",
|
|
86
|
+
children,
|
|
87
|
+
globalFlag: false,
|
|
88
|
+
printFlag: false
|
|
89
|
+
};
|
|
78
90
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
const simpleCommands = {
|
|
92
|
+
h: "h",
|
|
93
|
+
H: "H",
|
|
94
|
+
g: "g_hold",
|
|
95
|
+
G: "G",
|
|
96
|
+
x: "x",
|
|
97
|
+
n: "n",
|
|
98
|
+
N: "N",
|
|
99
|
+
P: "P",
|
|
100
|
+
D: "D",
|
|
101
|
+
d: "d",
|
|
102
|
+
p: "p"
|
|
103
|
+
};
|
|
104
|
+
if (simpleCommands[trimmed]) {
|
|
105
|
+
return {
|
|
106
|
+
type: simpleCommands[trimmed],
|
|
107
|
+
globalFlag: false,
|
|
108
|
+
printFlag: false
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const addressWithCmd = trimmed.match(/^\/(.+?)\/(!)?\s*(.*)$/);
|
|
112
|
+
if (addressWithCmd) {
|
|
113
|
+
const [, addressPatternStr, negation, rest] = addressWithCmd;
|
|
114
|
+
const negated = negation === "!";
|
|
115
|
+
const restTrimmed = rest.trim();
|
|
84
116
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
117
|
+
const addressPattern = new RegExp(addressPatternStr);
|
|
118
|
+
if (!restTrimmed)
|
|
119
|
+
return null;
|
|
120
|
+
if (simpleCommands[restTrimmed]) {
|
|
121
|
+
return {
|
|
122
|
+
type: simpleCommands[restTrimmed],
|
|
123
|
+
addressPattern,
|
|
124
|
+
negated,
|
|
125
|
+
globalFlag: false,
|
|
126
|
+
printFlag: false
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (restTrimmed === "b" || restTrimmed.startsWith("b ")) {
|
|
130
|
+
return {
|
|
131
|
+
type: "b",
|
|
132
|
+
addressPattern,
|
|
133
|
+
negated,
|
|
134
|
+
label: restTrimmed.length > 1 ? restTrimmed.slice(1).trim() : undefined,
|
|
135
|
+
globalFlag: false,
|
|
136
|
+
printFlag: false
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (restTrimmed.startsWith("{") && restTrimmed.endsWith("}")) {
|
|
140
|
+
const inner = restTrimmed.slice(1, -1).trim();
|
|
141
|
+
const parts = splitScriptParts(inner);
|
|
142
|
+
const children = [];
|
|
143
|
+
for (const part of parts) {
|
|
144
|
+
const cmd = parseCommand(part);
|
|
145
|
+
if (cmd)
|
|
146
|
+
children.push(cmd);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
type: "group",
|
|
150
|
+
addressPattern,
|
|
151
|
+
negated,
|
|
152
|
+
children,
|
|
153
|
+
globalFlag: false,
|
|
154
|
+
printFlag: false
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const subCmd2 = parseSubstitution(restTrimmed);
|
|
158
|
+
if (subCmd2) {
|
|
159
|
+
subCmd2.addressPattern = addressPattern;
|
|
160
|
+
subCmd2.negated = negated;
|
|
161
|
+
return subCmd2;
|
|
162
|
+
}
|
|
93
163
|
} catch {
|
|
94
164
|
return null;
|
|
95
165
|
}
|
|
@@ -103,8 +173,17 @@ function splitScriptParts(script) {
|
|
|
103
173
|
const parts = [];
|
|
104
174
|
let i = 0;
|
|
105
175
|
let current = "";
|
|
176
|
+
let braceDepth = 0;
|
|
106
177
|
while (i < script.length) {
|
|
107
|
-
if (script[i] === "
|
|
178
|
+
if (script[i] === "{") {
|
|
179
|
+
braceDepth++;
|
|
180
|
+
current += script[i];
|
|
181
|
+
i++;
|
|
182
|
+
} else if (script[i] === "}") {
|
|
183
|
+
braceDepth--;
|
|
184
|
+
current += script[i];
|
|
185
|
+
i++;
|
|
186
|
+
} else if (script[i] === "s" && braceDepth === 0 && i + 1 < script.length && !/[a-zA-Z0-9]/.test(script[i + 1])) {
|
|
108
187
|
const delim = script[i + 1];
|
|
109
188
|
let j = i + 2;
|
|
110
189
|
let delimCount = 0;
|
|
@@ -121,7 +200,7 @@ function splitScriptParts(script) {
|
|
|
121
200
|
j++;
|
|
122
201
|
current += script.slice(i, j);
|
|
123
202
|
i = j;
|
|
124
|
-
} else if (script[i] === ";") {
|
|
203
|
+
} else if (script[i] === ";" && braceDepth === 0) {
|
|
125
204
|
const trimmed2 = current.trim();
|
|
126
205
|
if (trimmed2)
|
|
127
206
|
parts.push(trimmed2);
|
|
@@ -194,9 +273,12 @@ function parseArgs(args) {
|
|
|
194
273
|
error: { type: "missing_value", option: "-e" }
|
|
195
274
|
};
|
|
196
275
|
}
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
276
|
+
const parts = splitScriptParts(script);
|
|
277
|
+
for (const part of parts) {
|
|
278
|
+
const cmd = parseCommand(part);
|
|
279
|
+
if (cmd)
|
|
280
|
+
options.commands.push(cmd);
|
|
281
|
+
}
|
|
200
282
|
break;
|
|
201
283
|
} else {
|
|
202
284
|
return {
|
|
@@ -249,37 +331,141 @@ function applySubstitution(line, cmd) {
|
|
|
249
331
|
return line.replace(cmd.pattern, cmd.replacement);
|
|
250
332
|
}
|
|
251
333
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
334
|
+
function addressMatches(cmd, state) {
|
|
335
|
+
if (!cmd.addressPattern) {
|
|
336
|
+
return cmd.negated ? false : true;
|
|
337
|
+
}
|
|
338
|
+
const matches = cmd.addressPattern.test(state.patternSpace);
|
|
339
|
+
return cmd.negated ? !matches : matches;
|
|
340
|
+
}
|
|
341
|
+
function findLabel(commands, label) {
|
|
342
|
+
for (let i = 0;i < commands.length; i++) {
|
|
343
|
+
if (commands[i].type === "label" && commands[i].label === label) {
|
|
344
|
+
return i;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return -1;
|
|
348
|
+
}
|
|
349
|
+
function executeCommands(commands, state, topLevel) {
|
|
350
|
+
let pc = 0;
|
|
351
|
+
while (pc < commands.length) {
|
|
352
|
+
const cmd = commands[pc];
|
|
353
|
+
if (cmd.type === "label") {
|
|
354
|
+
pc++;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (!addressMatches(cmd, state)) {
|
|
358
|
+
pc++;
|
|
258
359
|
continue;
|
|
259
360
|
}
|
|
260
361
|
switch (cmd.type) {
|
|
261
362
|
case "s":
|
|
262
|
-
|
|
363
|
+
state.patternSpace = applySubstitution(state.patternSpace, cmd);
|
|
263
364
|
break;
|
|
264
365
|
case "d":
|
|
265
|
-
deleted = true;
|
|
266
|
-
return {
|
|
366
|
+
state.deleted = true;
|
|
367
|
+
return { branchToEnd: false, deleted: true, nextLine: false, restart: false };
|
|
267
368
|
case "p":
|
|
268
|
-
|
|
369
|
+
state.output.push(state.patternSpace);
|
|
370
|
+
break;
|
|
371
|
+
case "h":
|
|
372
|
+
state.holdSpace = state.patternSpace;
|
|
373
|
+
break;
|
|
374
|
+
case "H":
|
|
375
|
+
state.holdSpace = state.holdSpace + `
|
|
376
|
+
` + state.patternSpace;
|
|
377
|
+
break;
|
|
378
|
+
case "g_hold":
|
|
379
|
+
state.patternSpace = state.holdSpace;
|
|
380
|
+
break;
|
|
381
|
+
case "G":
|
|
382
|
+
state.patternSpace = state.patternSpace + `
|
|
383
|
+
` + state.holdSpace;
|
|
384
|
+
break;
|
|
385
|
+
case "x": {
|
|
386
|
+
const tmp = state.patternSpace;
|
|
387
|
+
state.patternSpace = state.holdSpace;
|
|
388
|
+
state.holdSpace = tmp;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
case "n":
|
|
392
|
+
if (!state.suppressOutput) {
|
|
393
|
+
state.output.push(state.patternSpace);
|
|
394
|
+
}
|
|
395
|
+
state.lineIndex++;
|
|
396
|
+
if (state.lineIndex < state.lines.length) {
|
|
397
|
+
state.patternSpace = state.lines[state.lineIndex];
|
|
398
|
+
} else {
|
|
399
|
+
state.deleted = true;
|
|
400
|
+
return { branchToEnd: false, deleted: true, nextLine: false, restart: false };
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
case "N":
|
|
404
|
+
state.lineIndex++;
|
|
405
|
+
if (state.lineIndex < state.lines.length) {
|
|
406
|
+
state.patternSpace = state.patternSpace + `
|
|
407
|
+
` + state.lines[state.lineIndex];
|
|
408
|
+
} else {
|
|
409
|
+
if (!state.suppressOutput) {
|
|
410
|
+
state.output.push(state.patternSpace);
|
|
411
|
+
}
|
|
412
|
+
state.deleted = true;
|
|
413
|
+
return { branchToEnd: false, deleted: true, nextLine: false, restart: false };
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
case "P": {
|
|
417
|
+
const nlIdx = state.patternSpace.indexOf(`
|
|
418
|
+
`);
|
|
419
|
+
if (nlIdx >= 0) {
|
|
420
|
+
state.output.push(state.patternSpace.slice(0, nlIdx));
|
|
421
|
+
} else {
|
|
422
|
+
state.output.push(state.patternSpace);
|
|
423
|
+
}
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
case "D": {
|
|
427
|
+
const nlIdx2 = state.patternSpace.indexOf(`
|
|
428
|
+
`);
|
|
429
|
+
if (nlIdx2 >= 0) {
|
|
430
|
+
state.patternSpace = state.patternSpace.slice(nlIdx2 + 1);
|
|
431
|
+
state.restart = true;
|
|
432
|
+
return { branchToEnd: false, deleted: false, nextLine: false, restart: true };
|
|
433
|
+
} else {
|
|
434
|
+
state.deleted = true;
|
|
435
|
+
return { branchToEnd: false, deleted: true, nextLine: false, restart: false };
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
case "b":
|
|
439
|
+
if (cmd.label) {
|
|
440
|
+
if (topLevel) {
|
|
441
|
+
const idx = findLabel(commands, cmd.label);
|
|
442
|
+
if (idx >= 0) {
|
|
443
|
+
pc = idx;
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return { branchToEnd: true, branchLabel: cmd.label, deleted: false, nextLine: false, restart: false };
|
|
448
|
+
}
|
|
449
|
+
return { branchToEnd: true, deleted: false, nextLine: false, restart: false };
|
|
450
|
+
case "group":
|
|
451
|
+
if (cmd.children) {
|
|
452
|
+
const result = executeCommands(cmd.children, state, false);
|
|
453
|
+
if (result.deleted || result.branchToEnd || result.restart) {
|
|
454
|
+
if (result.branchLabel && topLevel) {
|
|
455
|
+
const idx = findLabel(commands, result.branchLabel);
|
|
456
|
+
if (idx >= 0) {
|
|
457
|
+
pc = idx;
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
269
464
|
break;
|
|
270
465
|
}
|
|
466
|
+
pc++;
|
|
271
467
|
}
|
|
272
|
-
|
|
273
|
-
return { output: null, deleted: true };
|
|
274
|
-
}
|
|
275
|
-
if (suppressOutput) {
|
|
276
|
-
return { output: printed ? currentLine : null, deleted: false };
|
|
277
|
-
}
|
|
278
|
-
if (printed) {
|
|
279
|
-
return { output: currentLine + `
|
|
280
|
-
` + currentLine, deleted: false };
|
|
281
|
-
}
|
|
282
|
-
return { output: currentLine, deleted: false };
|
|
468
|
+
return { branchToEnd: false, deleted: false, nextLine: false, restart: false };
|
|
283
469
|
}
|
|
284
470
|
var sed = async (ctx) => {
|
|
285
471
|
const { options, files, error } = parseArgs(ctx.args);
|
|
@@ -298,34 +484,59 @@ var sed = async (ctx) => {
|
|
|
298
484
|
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
299
485
|
lines.pop();
|
|
300
486
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
487
|
+
const allOutput = [];
|
|
488
|
+
const state = {
|
|
489
|
+
patternSpace: "",
|
|
490
|
+
holdSpace: "",
|
|
491
|
+
lineIndex: 0,
|
|
492
|
+
lines,
|
|
493
|
+
suppressOutput: options.suppressOutput,
|
|
494
|
+
output: [],
|
|
495
|
+
deleted: false,
|
|
496
|
+
restart: false
|
|
497
|
+
};
|
|
498
|
+
while (state.lineIndex < lines.length) {
|
|
499
|
+
state.patternSpace = lines[state.lineIndex];
|
|
500
|
+
state.deleted = false;
|
|
501
|
+
state.output = [];
|
|
502
|
+
let restarting = true;
|
|
503
|
+
while (restarting) {
|
|
504
|
+
restarting = false;
|
|
505
|
+
state.restart = false;
|
|
506
|
+
const result = executeCommands(options.commands, state, true);
|
|
507
|
+
if (result.restart) {
|
|
508
|
+
restarting = true;
|
|
509
|
+
allOutput.push(...state.output);
|
|
510
|
+
state.output = [];
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
if (result.deleted) {
|
|
514
|
+
allOutput.push(...state.output);
|
|
515
|
+
state.lineIndex++;
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
allOutput.push(...state.output);
|
|
519
|
+
if (!options.suppressOutput) {
|
|
520
|
+
allOutput.push(state.patternSpace);
|
|
521
|
+
}
|
|
522
|
+
state.lineIndex++;
|
|
306
523
|
}
|
|
307
524
|
}
|
|
525
|
+
return allOutput;
|
|
308
526
|
};
|
|
309
527
|
if (files.length === 0) {
|
|
310
528
|
const content = await ctx.stdin.text();
|
|
311
|
-
await processContent(content);
|
|
529
|
+
const outputLines = await processContent(content);
|
|
530
|
+
for (const line of outputLines) {
|
|
531
|
+
await ctx.stdout.writeText(line + `
|
|
532
|
+
`);
|
|
533
|
+
}
|
|
312
534
|
} else if (options.inPlace) {
|
|
313
535
|
for (const file of files) {
|
|
314
536
|
try {
|
|
315
537
|
const path = ctx.fs.resolve(ctx.cwd, file);
|
|
316
538
|
const content = await ctx.fs.readFile(path);
|
|
317
|
-
const
|
|
318
|
-
`);
|
|
319
|
-
if (lines.length > 0 && lines[lines.length - 1] === "") {
|
|
320
|
-
lines.pop();
|
|
321
|
-
}
|
|
322
|
-
const outputLines = [];
|
|
323
|
-
for (const line of lines) {
|
|
324
|
-
const { output } = processLine(line, options.commands, options.suppressOutput);
|
|
325
|
-
if (output !== null) {
|
|
326
|
-
outputLines.push(output);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
539
|
+
const outputLines = await processContent(content.toString());
|
|
329
540
|
const result = outputLines.length > 0 ? outputLines.join(`
|
|
330
541
|
`) + `
|
|
331
542
|
` : "";
|
|
@@ -342,7 +553,11 @@ var sed = async (ctx) => {
|
|
|
342
553
|
try {
|
|
343
554
|
const path = ctx.fs.resolve(ctx.cwd, file);
|
|
344
555
|
const content = await ctx.fs.readFile(path);
|
|
345
|
-
await processContent(content.toString());
|
|
556
|
+
const outputLines = await processContent(content.toString());
|
|
557
|
+
for (const line of outputLines) {
|
|
558
|
+
await ctx.stdout.writeText(line + `
|
|
559
|
+
`);
|
|
560
|
+
}
|
|
346
561
|
} catch (err) {
|
|
347
562
|
const message = err instanceof Error ? err.message : String(err);
|
|
348
563
|
await ctx.stderr.writeText(`sed: ${file}: ${message}
|
|
@@ -354,4 +569,4 @@ var sed = async (ctx) => {
|
|
|
354
569
|
return 0;
|
|
355
570
|
};
|
|
356
571
|
|
|
357
|
-
//# debugId=
|
|
572
|
+
//# debugId=54C2879933482FB364756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/commands/sed/sed.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Command } from \"../../types.cjs\";\n\ninterface SedCommand {\n type: \"s\" | \"d\" | \"p\";\n addressPattern?: RegExp;\n pattern?: RegExp;\n replacement?: string;\n globalFlag: boolean;\n printFlag: boolean;\n}\n\ninterface SedOptions {\n suppressOutput: boolean; // -n\n inPlace: boolean; // -i\n commands: SedCommand[];\n}\n\nfunction parseSubstitution(script: string): SedCommand | null {\n // Match s/pattern/replacement/flags format\n // Support different delimiters (first char after 's')\n const match = script.match(/^s(.)(.+?)\\1(.*?)\\1([gi]*)$/);\n if (!match) return null;\n\n const [, , rawPattern, rawReplacement, flags] = match;\n const globalFlag = flags!.includes(\"g\");\n const caseInsensitive = flags!.includes(\"i\");\n\n // Convert sed-style \\( \\) to JS ( ) for capture groups\n const patternStr = rawPattern!.replace(/\\\\\\(/g, \"(\").replace(/\\\\\\)/g, \")\");\n // Convert sed replacement to JS String.replace format:\n // 1. Mark backreferences \\1..\\9 with placeholders\n // 2. Escape $ so String.replace doesn't treat $$ as special\n // 3. Restore backreference placeholders as $1..$9\n const replacement = rawReplacement!\n .replace(/\\\\([0-9])/g, \"\\x00BACKREF$1\\x00\")\n .replace(/\\$/g, \"$$$$\")\n .replace(/\\x00BACKREF([0-9])\\x00/g, \"$$$1\");\n\n try {\n const regexFlags = caseInsensitive ? \"i\" : \"\";\n return {\n type: \"s\",\n pattern: new RegExp(patternStr, regexFlags),\n replacement,\n globalFlag,\n printFlag: false,\n };\n } catch {\n return null;\n }\n}\n\nfunction parseCommand(script: string): SedCommand | null {\n const trimmed = script.trim();\n\n // Check for address pattern (e.g., /foo/d or /foo/p)\n const addressMatch = trimmed.match(/^\\/(.+?)\\/([dp])$/);\n if (addressMatch) {\n const [, addressPatternStr, cmd] = addressMatch;\n try {\n return {\n type: cmd as \"d\" | \"p\",\n addressPattern: new RegExp(addressPatternStr!),\n globalFlag: false,\n printFlag: false,\n };\n } catch {\n return null;\n }\n }\n\n // Simple d or p command (applies to all lines)\n if (trimmed === \"d\") {\n return { type: \"d\", globalFlag: false, printFlag: false };\n }\n if (trimmed === \"p\") {\n return { type: \"p\", globalFlag: false, printFlag: false };\n }\n\n // Address pattern with substitution: /pattern/s/old/new/flags\n const addressSubMatch = trimmed.match(/^\\/(.+?)\\/s(.)(.+?)\\2(.*?)\\2([gi]*)$/);\n if (addressSubMatch) {\n const [, addressPatternStr, , patternStr, replacement, flags] = addressSubMatch;\n const globalFlag = flags!.includes(\"g\");\n const caseInsensitive = flags!.includes(\"i\");\n try {\n return {\n type: \"s\",\n addressPattern: new RegExp(addressPatternStr!),\n pattern: new RegExp(patternStr!, caseInsensitive ? \"i\" : \"\"),\n replacement: replacement!,\n globalFlag,\n printFlag: false,\n };\n } catch {\n return null;\n }\n }\n\n // Substitution command\n const subCmd = parseSubstitution(trimmed);\n if (subCmd) return subCmd;\n\n return null;\n}\n\nfunction splitScriptParts(script: string): string[] {\n // Split on ';' that are outside of s/// delimiters\n const parts: string[] = [];\n let i = 0;\n let current = \"\";\n while (i < script.length) {\n if (script[i] === \"s\" && i + 1 < script.length) {\n // Detect substitution command — consume s/pattern/replacement/flags\n const delim = script[i + 1]!;\n let j = i + 2;\n let delimCount = 0;\n while (j < script.length && delimCount < 2) {\n if (script[j] === \"\\\\\") {\n j += 2;\n continue;\n }\n if (script[j] === delim) delimCount++;\n j++;\n }\n // Consume trailing flags\n while (j < script.length && /[gi]/.test(script[j]!)) j++;\n current += script.slice(i, j);\n i = j;\n } else if (script[i] === \";\") {\n const trimmed = current.trim();\n if (trimmed) parts.push(trimmed);\n current = \"\";\n i++;\n } else {\n current += script[i];\n i++;\n }\n }\n const trimmed = current.trim();\n if (trimmed) parts.push(trimmed);\n return parts;\n}\n\ninterface ParseArgsResult {\n options: SedOptions;\n files: string[];\n error?: { type: \"unrecognized_option\" | \"missing_value\"; option: string };\n}\n\nfunction parseArgs(args: string[]): ParseArgsResult {\n const options: SedOptions = {\n suppressOutput: false,\n inPlace: false,\n commands: [],\n };\n const files: string[] = [];\n\n let i = 0;\n while (i < args.length) {\n const arg = args[i]!;\n\n // Handle -- to stop flag parsing\n if (arg === \"--\") {\n i++;\n // Rest are files or script\n while (i < args.length) {\n const remaining = args[i]!;\n if (options.commands.length === 0) {\n const parts = splitScriptParts(remaining);\n for (const part of parts) {\n const cmd = parseCommand(part);\n if (cmd) options.commands.push(cmd);\n }\n } else {\n files.push(remaining);\n }\n i++;\n }\n break;\n }\n\n // Long flag handling\n if (arg.startsWith(\"--\")) {\n return {\n options,\n files,\n error: { type: \"unrecognized_option\", option: arg },\n };\n }\n\n // Short flag handling\n if (arg.startsWith(\"-\") && arg.length > 1) {\n const flagChars = arg.slice(1);\n\n for (let j = 0; j < flagChars.length; j++) {\n const char = flagChars[j]!;\n\n if (char === \"n\") {\n options.suppressOutput = true;\n } else if (char === \"i\") {\n options.inPlace = true;\n } else if (char === \"e\") {\n // -e takes a script argument\n const restOfArg = flagChars.slice(j + 1);\n let script: string;\n\n if (restOfArg.length > 0) {\n script = restOfArg;\n } else if (i + 1 < args.length) {\n script = args[++i]!;\n } else {\n return {\n options,\n files,\n error: { type: \"missing_value\", option: \"-e\" },\n };\n }\n\n const cmd = parseCommand(script);\n if (cmd) options.commands.push(cmd);\n break; // -e consumes rest of this arg\n } else {\n return {\n options,\n files,\n error: { type: \"unrecognized_option\", option: `-${char}` },\n };\n }\n }\n i++;\n continue;\n }\n\n // Non-flag argument: either a script or a file\n if (options.commands.length === 0) {\n // First non-flag is the script — may contain ;-separated commands\n const parts = splitScriptParts(arg);\n for (const part of parts) {\n const cmd = parseCommand(part);\n if (cmd) options.commands.push(cmd);\n }\n } else {\n // Subsequent non-flags are files\n files.push(arg);\n }\n i++;\n }\n\n return { options, files };\n}\n\nfunction formatError(error: NonNullable<ParseArgsResult[\"error\"]>): string {\n let message: string;\n if (error.type === \"unrecognized_option\") {\n if (error.option.startsWith(\"--\")) {\n message = `sed: unrecognized option '${error.option}'\\n`;\n } else {\n message = `sed: invalid option -- '${error.option.slice(1)}'\\n`;\n }\n } else {\n message = `sed: option '${error.option}' requires an argument\\n`;\n }\n return message + `usage: sed [-ni] [-e script] script [file ...]\\n`;\n}\n\nfunction applySubstitution(line: string, cmd: SedCommand): string {\n if (!cmd.pattern) return line;\n\n if (cmd.globalFlag) {\n return line.replace(new RegExp(cmd.pattern.source, cmd.pattern.flags + \"g\"), cmd.replacement!);\n } else {\n return line.replace(cmd.pattern, cmd.replacement!);\n }\n}\n\nfunction processLine(\n line: string,\n commands: SedCommand[],\n suppressOutput: boolean\n): { output: string | null; deleted: boolean } {\n let currentLine = line;\n let deleted = false;\n let printed = false;\n\n for (const cmd of commands) {\n // Check address pattern first\n if (cmd.addressPattern && !cmd.addressPattern.test(currentLine)) {\n continue; // Skip this command if address doesn't match\n }\n\n switch (cmd.type) {\n case \"s\":\n currentLine = applySubstitution(currentLine, cmd);\n break;\n case \"d\":\n deleted = true;\n return { output: null, deleted: true };\n case \"p\":\n printed = true;\n break;\n }\n }\n\n if (deleted) {\n return { output: null, deleted: true };\n }\n\n if (suppressOutput) {\n // With -n, only output if explicitly printed\n return { output: printed ? currentLine : null, deleted: false };\n }\n\n // Without -n, always output (plus extra if printed)\n if (printed) {\n return { output: currentLine + \"\\n\" + currentLine, deleted: false };\n }\n return { output: currentLine, deleted: false };\n}\n\nexport const sed: Command = async (ctx) => {\n const { options, files, error } = parseArgs(ctx.args);\n\n if (error) {\n await ctx.stderr.writeText(formatError(error));\n return 1;\n }\n\n if (options.commands.length === 0) {\n await ctx.stderr.writeText(\"sed: missing script\\n\");\n return 1;\n }\n\n const processContent = async (content: string): Promise<void> => {\n const lines = content.split(\"\\n\");\n // Handle trailing newline\n if (lines.length > 0 && lines[lines.length - 1] === \"\") {\n lines.pop();\n }\n\n for (const line of lines) {\n const { output } = processLine(line, options.commands, options.suppressOutput);\n if (output !== null) {\n await ctx.stdout.writeText(output + \"\\n\");\n }\n }\n };\n\n if (files.length === 0) {\n // Read from stdin\n const content = await ctx.stdin.text();\n await processContent(content);\n } else if (options.inPlace) {\n // In-place editing: write results back to each file\n for (const file of files) {\n try {\n const path = ctx.fs.resolve(ctx.cwd, file);\n const content = await ctx.fs.readFile(path);\n const lines = content.toString().split(\"\\n\");\n if (lines.length > 0 && lines[lines.length - 1] === \"\") {\n lines.pop();\n }\n const outputLines: string[] = [];\n for (const line of lines) {\n const { output } = processLine(line, options.commands, options.suppressOutput);\n if (output !== null) {\n outputLines.push(output);\n }\n }\n const result = outputLines.length > 0 ? outputLines.join(\"\\n\") + \"\\n\" : \"\";\n await ctx.fs.writeFile(path, result);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`sed: ${file}: ${message}\\n`);\n return 1;\n }\n }\n } else {\n // Read from files\n for (const file of files) {\n try {\n const path = ctx.fs.resolve(ctx.cwd, file);\n const content = await ctx.fs.readFile(path);\n await processContent(content.toString());\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`sed: ${file}: ${message}\\n`);\n return 1;\n }\n }\n }\n\n return 0;\n};\n"
|
|
5
|
+
"import type { Command } from \"../../types.cjs\";\n\ninterface SedCommand {\n type: \"s\" | \"d\" | \"p\" | \"h\" | \"H\" | \"g_hold\" | \"G\" | \"x\" | \"n\" | \"N\" | \"P\" | \"D\" | \"b\" | \"label\" | \"group\";\n addressPattern?: RegExp;\n negated?: boolean;\n pattern?: RegExp;\n replacement?: string;\n globalFlag: boolean;\n printFlag: boolean;\n label?: string;\n children?: SedCommand[];\n}\n\ninterface SedOptions {\n suppressOutput: boolean; // -n\n inPlace: boolean; // -i\n commands: SedCommand[];\n}\n\nfunction parseSubstitution(script: string): SedCommand | null {\n const match = script.match(/^s(.)(.+?)\\1(.*?)\\1([gi]*)$/);\n if (!match) return null;\n\n const [, , rawPattern, rawReplacement, flags] = match;\n const globalFlag = flags!.includes(\"g\");\n const caseInsensitive = flags!.includes(\"i\");\n\n const patternStr = rawPattern!.replace(/\\\\\\(/g, \"(\").replace(/\\\\\\)/g, \")\");\n const replacement = rawReplacement!\n .replace(/\\\\([0-9])/g, \"\\x00BACKREF$1\\x00\")\n .replace(/\\$/g, \"$$$$\")\n .replace(/\\x00BACKREF([0-9])\\x00/g, \"$$$1\");\n\n try {\n const regexFlags = caseInsensitive ? \"i\" : \"\";\n return {\n type: \"s\",\n pattern: new RegExp(patternStr, regexFlags),\n replacement,\n globalFlag,\n printFlag: false,\n };\n } catch {\n return null;\n }\n}\n\nfunction parseCommand(script: string): SedCommand | null {\n const trimmed = script.trim();\n\n // Label command :name\n if (trimmed.startsWith(\":\")) {\n return {\n type: \"label\",\n label: trimmed.slice(1).trim(),\n globalFlag: false,\n printFlag: false,\n };\n }\n\n // Branch command: b or b label\n if (trimmed === \"b\" || trimmed.startsWith(\"b \") || trimmed.startsWith(\"b\\t\")) {\n return {\n type: \"b\",\n label: trimmed.length > 1 ? trimmed.slice(1).trim() : undefined,\n globalFlag: false,\n printFlag: false,\n };\n }\n\n // Group { ... }\n if (trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\")) {\n const inner = trimmed.slice(1, -1).trim();\n const parts = splitScriptParts(inner);\n const children: SedCommand[] = [];\n for (const part of parts) {\n const cmd = parseCommand(part);\n if (cmd) children.push(cmd);\n }\n return {\n type: \"group\",\n children,\n globalFlag: false,\n printFlag: false,\n };\n }\n\n // Simple single-char commands (no address)\n const simpleCommands: Record<string, SedCommand[\"type\"]> = {\n h: \"h\",\n H: \"H\",\n g: \"g_hold\",\n G: \"G\",\n x: \"x\",\n n: \"n\",\n N: \"N\",\n P: \"P\",\n D: \"D\",\n d: \"d\",\n p: \"p\",\n };\n if (simpleCommands[trimmed]) {\n return {\n type: simpleCommands[trimmed]!,\n globalFlag: false,\n printFlag: false,\n };\n }\n\n // Check for address pattern: /pattern/ followed by optional ! and command\n const addressWithCmd = trimmed.match(/^\\/(.+?)\\/(!)?\\s*(.*)$/);\n if (addressWithCmd) {\n const [, addressPatternStr, negation, rest] = addressWithCmd;\n const negated = negation === \"!\";\n const restTrimmed = rest!.trim();\n\n try {\n const addressPattern = new RegExp(addressPatternStr!);\n\n // /pattern/ alone — not valid, but handle gracefully\n if (!restTrimmed) return null;\n\n // /pattern/[!]d or /pattern/[!]p etc (simple commands)\n if (simpleCommands[restTrimmed]) {\n return {\n type: simpleCommands[restTrimmed]!,\n addressPattern,\n negated,\n globalFlag: false,\n printFlag: false,\n };\n }\n\n // /pattern/[!]b or /pattern/[!]b label\n if (restTrimmed === \"b\" || restTrimmed.startsWith(\"b \")) {\n return {\n type: \"b\",\n addressPattern,\n negated,\n label: restTrimmed.length > 1 ? restTrimmed.slice(1).trim() : undefined,\n globalFlag: false,\n printFlag: false,\n };\n }\n\n // /pattern/[!]{ ... }\n if (restTrimmed.startsWith(\"{\") && restTrimmed.endsWith(\"}\")) {\n const inner = restTrimmed.slice(1, -1).trim();\n const parts = splitScriptParts(inner);\n const children: SedCommand[] = [];\n for (const part of parts) {\n const cmd = parseCommand(part);\n if (cmd) children.push(cmd);\n }\n return {\n type: \"group\",\n addressPattern,\n negated,\n children,\n globalFlag: false,\n printFlag: false,\n };\n }\n\n // /pattern/[!]s/old/new/flags\n const subCmd = parseSubstitution(restTrimmed);\n if (subCmd) {\n subCmd.addressPattern = addressPattern;\n subCmd.negated = negated;\n return subCmd;\n }\n } catch {\n return null;\n }\n }\n\n // Substitution command (no address)\n const subCmd = parseSubstitution(trimmed);\n if (subCmd) return subCmd;\n\n return null;\n}\n\nfunction splitScriptParts(script: string): string[] {\n const parts: string[] = [];\n let i = 0;\n let current = \"\";\n let braceDepth = 0;\n\n while (i < script.length) {\n if (script[i] === \"{\") {\n braceDepth++;\n current += script[i];\n i++;\n } else if (script[i] === \"}\") {\n braceDepth--;\n current += script[i];\n i++;\n } else if (script[i] === \"s\" && braceDepth === 0 && i + 1 < script.length && !/[a-zA-Z0-9]/.test(script[i + 1]!)) {\n // Detect substitution command — consume s/pattern/replacement/flags\n const delim = script[i + 1]!;\n let j = i + 2;\n let delimCount = 0;\n while (j < script.length && delimCount < 2) {\n if (script[j] === \"\\\\\") {\n j += 2;\n continue;\n }\n if (script[j] === delim) delimCount++;\n j++;\n }\n // Consume trailing flags\n while (j < script.length && /[gi]/.test(script[j]!)) j++;\n current += script.slice(i, j);\n i = j;\n } else if (script[i] === \";\" && braceDepth === 0) {\n const trimmed = current.trim();\n if (trimmed) parts.push(trimmed);\n current = \"\";\n i++;\n } else {\n current += script[i];\n i++;\n }\n }\n const trimmed = current.trim();\n if (trimmed) parts.push(trimmed);\n return parts;\n}\n\ninterface ParseArgsResult {\n options: SedOptions;\n files: string[];\n error?: { type: \"unrecognized_option\" | \"missing_value\"; option: string };\n}\n\nfunction parseArgs(args: string[]): ParseArgsResult {\n const options: SedOptions = {\n suppressOutput: false,\n inPlace: false,\n commands: [],\n };\n const files: string[] = [];\n\n let i = 0;\n while (i < args.length) {\n const arg = args[i]!;\n\n if (arg === \"--\") {\n i++;\n while (i < args.length) {\n const remaining = args[i]!;\n if (options.commands.length === 0) {\n const parts = splitScriptParts(remaining);\n for (const part of parts) {\n const cmd = parseCommand(part);\n if (cmd) options.commands.push(cmd);\n }\n } else {\n files.push(remaining);\n }\n i++;\n }\n break;\n }\n\n if (arg.startsWith(\"--\")) {\n return {\n options,\n files,\n error: { type: \"unrecognized_option\", option: arg },\n };\n }\n\n if (arg.startsWith(\"-\") && arg.length > 1) {\n const flagChars = arg.slice(1);\n\n for (let j = 0; j < flagChars.length; j++) {\n const char = flagChars[j]!;\n\n if (char === \"n\") {\n options.suppressOutput = true;\n } else if (char === \"i\") {\n options.inPlace = true;\n } else if (char === \"e\") {\n const restOfArg = flagChars.slice(j + 1);\n let script: string;\n\n if (restOfArg.length > 0) {\n script = restOfArg;\n } else if (i + 1 < args.length) {\n script = args[++i]!;\n } else {\n return {\n options,\n files,\n error: { type: \"missing_value\", option: \"-e\" },\n };\n }\n\n const parts = splitScriptParts(script);\n for (const part of parts) {\n const cmd = parseCommand(part);\n if (cmd) options.commands.push(cmd);\n }\n break;\n } else {\n return {\n options,\n files,\n error: { type: \"unrecognized_option\", option: `-${char}` },\n };\n }\n }\n i++;\n continue;\n }\n\n if (options.commands.length === 0) {\n const parts = splitScriptParts(arg);\n for (const part of parts) {\n const cmd = parseCommand(part);\n if (cmd) options.commands.push(cmd);\n }\n } else {\n files.push(arg);\n }\n i++;\n }\n\n return { options, files };\n}\n\nfunction formatError(error: NonNullable<ParseArgsResult[\"error\"]>): string {\n let message: string;\n if (error.type === \"unrecognized_option\") {\n if (error.option.startsWith(\"--\")) {\n message = `sed: unrecognized option '${error.option}'\\n`;\n } else {\n message = `sed: invalid option -- '${error.option.slice(1)}'\\n`;\n }\n } else {\n message = `sed: option '${error.option}' requires an argument\\n`;\n }\n return message + `usage: sed [-ni] [-e script] script [file ...]\\n`;\n}\n\nfunction applySubstitution(line: string, cmd: SedCommand): string {\n if (!cmd.pattern) return line;\n\n if (cmd.globalFlag) {\n return line.replace(new RegExp(cmd.pattern.source, cmd.pattern.flags + \"g\"), cmd.replacement!);\n } else {\n return line.replace(cmd.pattern, cmd.replacement!);\n }\n}\n\ninterface SedState {\n patternSpace: string;\n holdSpace: string;\n lineIndex: number;\n lines: string[];\n suppressOutput: boolean;\n output: string[];\n deleted: boolean;\n restart: boolean; // for D command\n}\n\nfunction addressMatches(cmd: SedCommand, state: SedState): boolean {\n if (!cmd.addressPattern) {\n return cmd.negated ? false : true;\n }\n const matches = cmd.addressPattern.test(state.patternSpace);\n return cmd.negated ? !matches : matches;\n}\n\nfunction findLabel(commands: SedCommand[], label: string): number {\n for (let i = 0; i < commands.length; i++) {\n if (commands[i]!.type === \"label\" && commands[i]!.label === label) {\n return i;\n }\n }\n return -1;\n}\n\ninterface ExecResult {\n branchToEnd: boolean;\n branchLabel?: string;\n nextLine: boolean; // n command: output and advance\n deleted: boolean;\n restart: boolean; // D command\n}\n\nfunction executeCommands(\n commands: SedCommand[],\n state: SedState,\n topLevel: boolean\n): ExecResult {\n let pc = 0;\n while (pc < commands.length) {\n const cmd = commands[pc]!;\n\n // Labels are no-ops\n if (cmd.type === \"label\") {\n pc++;\n continue;\n }\n\n // Check address\n if (!addressMatches(cmd, state)) {\n pc++;\n continue;\n }\n\n switch (cmd.type) {\n case \"s\":\n state.patternSpace = applySubstitution(state.patternSpace, cmd);\n break;\n case \"d\":\n state.deleted = true;\n return { branchToEnd: false, deleted: true, nextLine: false, restart: false };\n case \"p\":\n state.output.push(state.patternSpace);\n break;\n case \"h\":\n state.holdSpace = state.patternSpace;\n break;\n case \"H\":\n state.holdSpace = state.holdSpace + \"\\n\" + state.patternSpace;\n break;\n case \"g_hold\":\n state.patternSpace = state.holdSpace;\n break;\n case \"G\":\n state.patternSpace = state.patternSpace + \"\\n\" + state.holdSpace;\n break;\n case \"x\": {\n const tmp = state.patternSpace;\n state.patternSpace = state.holdSpace;\n state.holdSpace = tmp;\n break;\n }\n case \"n\":\n // Output current pattern space, then read next line\n if (!state.suppressOutput) {\n state.output.push(state.patternSpace);\n }\n state.lineIndex++;\n if (state.lineIndex < state.lines.length) {\n state.patternSpace = state.lines[state.lineIndex]!;\n } else {\n // No more lines\n state.deleted = true;\n return { branchToEnd: false, deleted: true, nextLine: false, restart: false };\n }\n break;\n case \"N\":\n // Append next line to pattern space\n state.lineIndex++;\n if (state.lineIndex < state.lines.length) {\n state.patternSpace = state.patternSpace + \"\\n\" + state.lines[state.lineIndex]!;\n } else {\n // No more lines: output pattern space and exit (POSIX behavior)\n if (!state.suppressOutput) {\n state.output.push(state.patternSpace);\n }\n state.deleted = true;\n return { branchToEnd: false, deleted: true, nextLine: false, restart: false };\n }\n break;\n case \"P\": {\n // Print up to first \\n\n const nlIdx = state.patternSpace.indexOf(\"\\n\");\n if (nlIdx >= 0) {\n state.output.push(state.patternSpace.slice(0, nlIdx));\n } else {\n state.output.push(state.patternSpace);\n }\n break;\n }\n case \"D\": {\n // Delete up to first \\n, restart; if no \\n, delete all\n const nlIdx2 = state.patternSpace.indexOf(\"\\n\");\n if (nlIdx2 >= 0) {\n state.patternSpace = state.patternSpace.slice(nlIdx2 + 1);\n state.restart = true;\n return { branchToEnd: false, deleted: false, nextLine: false, restart: true };\n } else {\n state.deleted = true;\n return { branchToEnd: false, deleted: true, nextLine: false, restart: false };\n }\n }\n case \"b\":\n if (cmd.label) {\n // Branch to label — only works at top level\n if (topLevel) {\n const idx = findLabel(commands, cmd.label);\n if (idx >= 0) {\n pc = idx;\n continue;\n }\n }\n // Label not found or not top-level: branch to end\n return { branchToEnd: true, branchLabel: cmd.label, deleted: false, nextLine: false, restart: false };\n }\n // No label: branch to end of script\n return { branchToEnd: true, deleted: false, nextLine: false, restart: false };\n case \"group\":\n if (cmd.children) {\n const result = executeCommands(cmd.children, state, false);\n if (result.deleted || result.branchToEnd || result.restart) {\n // Propagate branch labels up for top-level resolution\n if (result.branchLabel && topLevel) {\n const idx = findLabel(commands, result.branchLabel);\n if (idx >= 0) {\n pc = idx;\n continue;\n }\n }\n return result;\n }\n }\n break;\n }\n pc++;\n }\n return { branchToEnd: false, deleted: false, nextLine: false, restart: false };\n}\n\nexport const sed: Command = async (ctx) => {\n const { options, files, error } = parseArgs(ctx.args);\n\n if (error) {\n await ctx.stderr.writeText(formatError(error));\n return 1;\n }\n\n if (options.commands.length === 0) {\n await ctx.stderr.writeText(\"sed: missing script\\n\");\n return 1;\n }\n\n const processContent = async (content: string): Promise<string[]> => {\n const lines = content.split(\"\\n\");\n if (lines.length > 0 && lines[lines.length - 1] === \"\") {\n lines.pop();\n }\n\n const allOutput: string[] = [];\n const state: SedState = {\n patternSpace: \"\",\n holdSpace: \"\",\n lineIndex: 0,\n lines,\n suppressOutput: options.suppressOutput,\n output: [],\n deleted: false,\n restart: false,\n };\n\n while (state.lineIndex < lines.length) {\n state.patternSpace = lines[state.lineIndex]!;\n state.deleted = false;\n state.output = [];\n\n // Execute commands, possibly restarting on D\n let restarting = true;\n while (restarting) {\n restarting = false;\n state.restart = false;\n const result = executeCommands(options.commands, state, true);\n\n if (result.restart) {\n restarting = true;\n // output collected so far in this cycle goes out\n allOutput.push(...state.output);\n state.output = [];\n continue;\n }\n\n if (result.deleted) {\n allOutput.push(...state.output);\n state.lineIndex++;\n break;\n }\n\n // Normal end: collect printed lines, then auto-print\n allOutput.push(...state.output);\n if (!options.suppressOutput) {\n allOutput.push(state.patternSpace);\n }\n state.lineIndex++;\n }\n }\n\n return allOutput;\n };\n\n if (files.length === 0) {\n const content = await ctx.stdin.text();\n const outputLines = await processContent(content);\n for (const line of outputLines) {\n await ctx.stdout.writeText(line + \"\\n\");\n }\n } else if (options.inPlace) {\n for (const file of files) {\n try {\n const path = ctx.fs.resolve(ctx.cwd, file);\n const content = await ctx.fs.readFile(path);\n const outputLines = await processContent(content.toString());\n const result = outputLines.length > 0 ? outputLines.join(\"\\n\") + \"\\n\" : \"\";\n await ctx.fs.writeFile(path, result);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`sed: ${file}: ${message}\\n`);\n return 1;\n }\n }\n } else {\n for (const file of files) {\n try {\n const path = ctx.fs.resolve(ctx.cwd, file);\n const content = await ctx.fs.readFile(path);\n const outputLines = await processContent(content.toString());\n for (const line of outputLines) {\n await ctx.stdout.writeText(line + \"\\n\");\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n await ctx.stderr.writeText(`sed: ${file}: ${message}\\n`);\n return 1;\n }\n }\n }\n\n return 0;\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAS,iBAAiB,CAAC,QAAmC;AAAA,EAG5D,MAAM,QAAQ,OAAO,MAAM,6BAA6B;AAAA,EACxD,IAAI,CAAC;AAAA,IAAO,OAAO;AAAA,EAEnB,WAAW,YAAY,gBAAgB,SAAS;AAAA,EAChD,MAAM,aAAa,MAAO,SAAS,GAAG;AAAA,EACtC,MAAM,kBAAkB,MAAO,SAAS,GAAG;AAAA,EAG3C,MAAM,aAAa,WAAY,QAAQ,SAAS,GAAG,EAAE,QAAQ,SAAS,GAAG;AAAA,EAKzE,MAAM,cAAc,eACjB,QAAQ,cAAc,mBAAmB,EACzC,QAAQ,OAAO,MAAM,EACrB,QAAQ,2BAA2B,MA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