|
1 |
| -export type CommandSegment = string | |
2 |
| -{type: `shell`, shell: ShellLine, quoted: boolean} | |
3 |
| -{type: `variable`, name: string, defaultValue?: Array<Array<CommandSegment>>, quoted: boolean}; |
| 1 | +// From the top to the bottom: |
| 2 | +// |
| 3 | +// - A shell line is composed of multiple command lines, first separated by ";" and then chained by "&&" / "||" |
| 4 | +// - A command line is composed of multiple commands chained by "|" / "|&" |
| 5 | +// - A command is composed of multiple arguments separated by spaces |
| 6 | +// - An argument can be a value argument (sent to the underlying program), or a redirection |
| 7 | +// - A value argument is a combination of argument segments |
| 8 | + |
| 9 | +export type ArgumentSegment = |
| 10 | + | {type: `text`, text: string} |
| 11 | + | {type: `shell`, shell: ShellLine, quoted: boolean} |
| 12 | + | {type: `variable`, name: string, defaultValue?: Array<ValueArgument>, quoted: boolean}; |
| 13 | + |
| 14 | +export type Argument = |
| 15 | + | {type: `redirection`, subtype: `>` | `<` | `>>` | `<<<`, args: Array<ValueArgument>} |
| 16 | + | ValueArgument; |
| 17 | + |
| 18 | +export type ValueArgument = |
| 19 | +| {type: `argument`, segments: Array<ArgumentSegment>}; |
| 20 | + |
| 21 | +export type EnvSegment = { |
| 22 | + name: string, |
| 23 | + args: [] | [ValueArgument], |
| 24 | +}; |
4 | 25 |
|
5 | 26 | export type Command = {
|
6 | 27 | type: `command`,
|
7 |
| - args: Array<Array<CommandSegment>>, |
| 28 | + args: Array<Argument>, |
8 | 29 | envs: Array<EnvSegment>,
|
9 | 30 | } | {
|
10 | 31 | type: `subshell`,
|
@@ -36,9 +57,3 @@ export type CommandLineThen = {
|
36 | 57 | export type ShellLine = Array<CommandLine>;
|
37 | 58 |
|
38 | 59 | export declare const parse: (code: string) => ShellLine;
|
39 |
| - |
40 |
| -export type EnvSegment = { |
41 |
| - name: string, |
42 |
| - args: Array<Array<CommandSegment>>, |
43 |
| -}; |
44 |
| - |
|
0 commit comments