-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
shell.d.ts
92 lines (77 loc) Β· 2.31 KB
/
shell.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// From the top to the bottom:
//
// - A shell line is composed of multiple command lines, first separated by ";" and then chained by "&&" / "||"
// - A command line is composed of multiple commands chained by "|" / "|&"
// - A command is composed of multiple arguments separated by spaces
// - An argument can be a value argument (sent to the underlying program), or a redirection
// - A value argument is a combination of argument segments
export type ArgumentSegment =
| {type: `text`, text: string}
| {type: `glob`, pattern: string}
| {type: `shell`, shell: ShellLine, quoted: boolean}
| {type: `variable`, name: string, defaultValue?: Array<ValueArgument>, alternativeValue?: Array<ValueArgument>, quoted: boolean}
| {type: `arithmetic`, arithmetic: ArithmeticExpression};
export type Argument =
| RedirectArgument
| ValueArgument;
export type RedirectArgument = {
type: `redirection`;
subtype: `>` | `<` | '>&' | '<&' | `>>` | `<<<`;
fd: number | null;
args: Array<ValueArgument>;
};
export type ValueArgument =
| {type: `argument`, segments: Array<ArgumentSegment>};
export type EnvSegment = {
name: string;
args: [] | [ValueArgument];
};
export type Command = {
type: `command`;
args: Array<Argument>;
envs: Array<EnvSegment>;
} | {
type: `subshell`;
subshell: ShellLine;
args: Array<RedirectArgument>;
} | {
type: `group`;
group: ShellLine;
args: Array<RedirectArgument>;
} | {
type: `envs`;
envs: Array<EnvSegment>;
};
export type CommandChain = Command & {
then?: CommandChainThen;
};
export type CommandChainThen = {
type: `|&` | `|`;
chain: CommandChain;
};
export type CommandLine = {
chain: CommandChain;
then?: CommandLineThen;
};
export type CommandLineThen = {
type: `&&` | `||`;
line: CommandLine;
};
export type ShellLine = Array<{
type: ';' | '&';
command: CommandLine;
}>;
export type ArithmeticPrimary = {
type: `number`;
value: number;
} | {
type: `variable`;
name: string;
};
export type ArithmeticOperatorExpression = {
type: `multiplication` | `division` | `addition` | `subtraction`;
left: ArithmeticExpression;
right: ArithmeticExpression;
};
export type ArithmeticExpression = ArithmeticPrimary | ArithmeticOperatorExpression;
export declare const parse: (code: string, options: {isGlobPattern: (arg: string) => boolean}) => ShellLine;