@taliesinb/mash 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +275 -2
- package/bin/mash.ts +253 -0
- package/dist/bin/mash.d.ts +39 -0
- package/dist/bin/mash.d.ts.map +1 -0
- package/dist/bin/mash.js +281 -0
- package/dist/bin/mash.js.map +1 -0
- package/dist/src/analysis/analyze.d.ts +97 -0
- package/dist/src/analysis/analyze.d.ts.map +1 -0
- package/dist/src/analysis/analyze.js +1406 -0
- package/dist/src/analysis/analyze.js.map +1 -0
- package/dist/src/analysis/fs.d.ts +39 -0
- package/dist/src/analysis/fs.d.ts.map +1 -0
- package/dist/src/analysis/fs.js +117 -0
- package/dist/src/analysis/fs.js.map +1 -0
- package/dist/src/analysis/outputs.d.ts +16 -0
- package/dist/src/analysis/outputs.d.ts.map +1 -0
- package/dist/src/analysis/outputs.js +277 -0
- package/dist/src/analysis/outputs.js.map +1 -0
- package/dist/src/analysis/value.d.ts +76 -0
- package/dist/src/analysis/value.d.ts.map +1 -0
- package/dist/src/analysis/value.js +248 -0
- package/dist/src/analysis/value.js.map +1 -0
- package/dist/src/behaviors/defs/core.d.ts +15 -0
- package/dist/src/behaviors/defs/core.d.ts.map +1 -0
- package/dist/src/behaviors/defs/core.js +1084 -0
- package/dist/src/behaviors/defs/core.js.map +1 -0
- package/dist/src/behaviors/defs/devtools.d.ts +9 -0
- package/dist/src/behaviors/defs/devtools.d.ts.map +1 -0
- package/dist/src/behaviors/defs/devtools.js +432 -0
- package/dist/src/behaviors/defs/devtools.js.map +1 -0
- package/dist/src/behaviors/defs/macos.d.ts +12 -0
- package/dist/src/behaviors/defs/macos.d.ts.map +1 -0
- package/dist/src/behaviors/defs/macos.js +454 -0
- package/dist/src/behaviors/defs/macos.js.map +1 -0
- package/dist/src/behaviors/defs/tools.d.ts +9 -0
- package/dist/src/behaviors/defs/tools.d.ts.map +1 -0
- package/dist/src/behaviors/defs/tools.js +639 -0
- package/dist/src/behaviors/defs/tools.js.map +1 -0
- package/dist/src/behaviors/dsl.d.ts +95 -0
- package/dist/src/behaviors/dsl.d.ts.map +1 -0
- package/dist/src/behaviors/dsl.js +267 -0
- package/dist/src/behaviors/dsl.js.map +1 -0
- package/dist/src/behaviors/index.d.ts +12 -0
- package/dist/src/behaviors/index.d.ts.map +1 -0
- package/dist/src/behaviors/index.js +18 -0
- package/dist/src/behaviors/index.js.map +1 -0
- package/dist/src/behaviors/registry.d.ts +45 -0
- package/dist/src/behaviors/registry.d.ts.map +1 -0
- package/dist/src/behaviors/registry.js +266 -0
- package/dist/src/behaviors/registry.js.map +1 -0
- package/dist/src/behaviors/roles.d.ts +29 -0
- package/dist/src/behaviors/roles.d.ts.map +1 -0
- package/dist/src/behaviors/roles.js +198 -0
- package/dist/src/behaviors/roles.js.map +1 -0
- package/dist/src/behaviors/types.d.ts +120 -0
- package/dist/src/behaviors/types.d.ts.map +1 -0
- package/dist/src/behaviors/types.js +12 -0
- package/dist/src/behaviors/types.js.map +1 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +24 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/integrations/deepsea.d.ts +121 -0
- package/dist/src/integrations/deepsea.d.ts.map +1 -0
- package/dist/src/integrations/deepsea.js +199 -0
- package/dist/src/integrations/deepsea.js.map +1 -0
- package/dist/src/machine.d.ts +139 -0
- package/dist/src/machine.d.ts.map +1 -0
- package/dist/src/machine.js +400 -0
- package/dist/src/machine.js.map +1 -0
- package/dist/src/parser/ast.d.ts +369 -0
- package/dist/src/parser/ast.d.ts.map +1 -0
- package/dist/src/parser/ast.js +17 -0
- package/dist/src/parser/ast.js.map +1 -0
- package/dist/src/parser/parser.d.ts +48 -0
- package/dist/src/parser/parser.d.ts.map +1 -0
- package/dist/src/parser/parser.js +1950 -0
- package/dist/src/parser/parser.js.map +1 -0
- package/dist/src/policy/effects.d.ts +86 -0
- package/dist/src/policy/effects.d.ts.map +1 -0
- package/dist/src/policy/effects.js +53 -0
- package/dist/src/policy/effects.js.map +1 -0
- package/dist/src/policy/policy.d.ts +130 -0
- package/dist/src/policy/policy.d.ts.map +1 -0
- package/dist/src/policy/policy.js +532 -0
- package/dist/src/policy/policy.js.map +1 -0
- package/dist/src/printer/doc.d.ts +151 -0
- package/dist/src/printer/doc.d.ts.map +1 -0
- package/dist/src/printer/doc.js +409 -0
- package/dist/src/printer/doc.js.map +1 -0
- package/dist/src/printer/highlight.d.ts +53 -0
- package/dist/src/printer/highlight.d.ts.map +1 -0
- package/dist/src/printer/highlight.js +339 -0
- package/dist/src/printer/highlight.js.map +1 -0
- package/dist/src/printer/html.d.ts +72 -0
- package/dist/src/printer/html.d.ts.map +1 -0
- package/dist/src/printer/html.js +423 -0
- package/dist/src/printer/html.js.map +1 -0
- package/dist/src/printer/print.d.ts +63 -0
- package/dist/src/printer/print.d.ts.map +1 -0
- package/dist/src/printer/print.js +484 -0
- package/dist/src/printer/print.js.map +1 -0
- package/dist/src/printer/summary.d.ts +50 -0
- package/dist/src/printer/summary.d.ts.map +1 -0
- package/dist/src/printer/summary.js +621 -0
- package/dist/src/printer/summary.js.map +1 -0
- package/dist/src/trace/events.d.ts +183 -0
- package/dist/src/trace/events.d.ts.map +1 -0
- package/dist/src/trace/events.js +9 -0
- package/dist/src/trace/events.js.map +1 -0
- package/dist/src/trace/progress.d.ts +58 -0
- package/dist/src/trace/progress.d.ts.map +1 -0
- package/dist/src/trace/progress.js +83 -0
- package/dist/src/trace/progress.js.map +1 -0
- package/dist/src/vm/arith.d.ts +29 -0
- package/dist/src/vm/arith.d.ts.map +1 -0
- package/dist/src/vm/arith.js +258 -0
- package/dist/src/vm/arith.js.map +1 -0
- package/dist/src/vm/builtins.d.ts +31 -0
- package/dist/src/vm/builtins.d.ts.map +1 -0
- package/dist/src/vm/builtins.js +1773 -0
- package/dist/src/vm/builtins.js.map +1 -0
- package/dist/src/vm/emulate.d.ts +75 -0
- package/dist/src/vm/emulate.d.ts.map +1 -0
- package/dist/src/vm/emulate.js +380 -0
- package/dist/src/vm/emulate.js.map +1 -0
- package/dist/src/vm/expand.d.ts +68 -0
- package/dist/src/vm/expand.d.ts.map +1 -0
- package/dist/src/vm/expand.js +744 -0
- package/dist/src/vm/expand.js.map +1 -0
- package/dist/src/vm/external.d.ts +34 -0
- package/dist/src/vm/external.d.ts.map +1 -0
- package/dist/src/vm/external.js +228 -0
- package/dist/src/vm/external.js.map +1 -0
- package/dist/src/vm/fifo.d.ts +66 -0
- package/dist/src/vm/fifo.d.ts.map +1 -0
- package/dist/src/vm/fifo.js +232 -0
- package/dist/src/vm/fifo.js.map +1 -0
- package/dist/src/vm/interp.d.ts +209 -0
- package/dist/src/vm/interp.d.ts.map +1 -0
- package/dist/src/vm/interp.js +1641 -0
- package/dist/src/vm/interp.js.map +1 -0
- package/dist/src/vm/io.d.ts +180 -0
- package/dist/src/vm/io.d.ts.map +1 -0
- package/dist/src/vm/io.js +502 -0
- package/dist/src/vm/io.js.map +1 -0
- package/dist/src/vm/pattern.d.ts +46 -0
- package/dist/src/vm/pattern.d.ts.map +1 -0
- package/dist/src/vm/pattern.js +498 -0
- package/dist/src/vm/pattern.js.map +1 -0
- package/dist/src/vm/proc.d.ts +94 -0
- package/dist/src/vm/proc.d.ts.map +1 -0
- package/dist/src/vm/proc.js +130 -0
- package/dist/src/vm/proc.js.map +1 -0
- package/dist/src/vm/state.d.ts +104 -0
- package/dist/src/vm/state.d.ts.map +1 -0
- package/dist/src/vm/state.js +233 -0
- package/dist/src/vm/state.js.map +1 -0
- package/dist/src/vm/test.d.ts +11 -0
- package/dist/src/vm/test.d.ts.map +1 -0
- package/dist/src/vm/test.js +277 -0
- package/dist/src/vm/test.js.map +1 -0
- package/package.json +63 -4
- package/src/analysis/analyze.ts +1395 -0
- package/src/analysis/fs.ts +121 -0
- package/src/analysis/outputs.ts +242 -0
- package/src/analysis/value.ts +264 -0
- package/src/behaviors/defs/core.ts +970 -0
- package/src/behaviors/defs/devtools.ts +400 -0
- package/src/behaviors/defs/macos.ts +426 -0
- package/src/behaviors/defs/tools.ts +596 -0
- package/src/behaviors/dsl.ts +293 -0
- package/src/behaviors/index.ts +19 -0
- package/src/behaviors/registry.ts +261 -0
- package/src/behaviors/roles.ts +187 -0
- package/src/behaviors/types.ts +127 -0
- package/src/index.ts +27 -0
- package/src/integrations/deepsea.ts +259 -0
- package/src/machine.ts +483 -0
- package/src/parser/ast.ts +472 -0
- package/src/parser/parser.ts +1826 -0
- package/src/policy/effects.ts +102 -0
- package/src/policy/policy.ts +578 -0
- package/src/printer/doc.ts +454 -0
- package/src/printer/highlight.ts +283 -0
- package/src/printer/html.ts +441 -0
- package/src/printer/print.ts +528 -0
- package/src/printer/summary.ts +601 -0
- package/src/trace/events.ts +102 -0
- package/src/trace/progress.ts +119 -0
- package/src/vm/arith.ts +236 -0
- package/src/vm/builtins.ts +1590 -0
- package/src/vm/emulate.ts +337 -0
- package/src/vm/expand.ts +721 -0
- package/src/vm/external.ts +265 -0
- package/src/vm/fifo.ts +226 -0
- package/src/vm/interp.ts +1623 -0
- package/src/vm/io.ts +570 -0
- package/src/vm/pattern.ts +477 -0
- package/src/vm/proc.ts +147 -0
- package/src/vm/state.ts +267 -0
- package/src/vm/test.ts +253 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Syntax classes for every character of a parsed script, from the AST (not
|
|
3
|
+
* regexes). Outer constructs are painted first and inner ones override, so
|
|
4
|
+
* `"$x"` as an argument is a string with a variable inside.
|
|
5
|
+
*
|
|
6
|
+
* Class names (short, semantic; styled by HTML_CSS in html.ts):
|
|
7
|
+
* kw keywords and grouping (`if`, `do`, `{`, `[[`)
|
|
8
|
+
* op control operators (`|`, `&&`, `;`, `;;`)
|
|
9
|
+
* cmd command names flag options (`-x`, `--long`)
|
|
10
|
+
* str quoted strings esc escapes (`\x`)
|
|
11
|
+
* var parameter expansions sub `$( )`, backquotes, `<( )`
|
|
12
|
+
* ar arithmetic num numbers in arithmetic
|
|
13
|
+
* asg assignment names rd redirections and here-doc delimiters
|
|
14
|
+
* hd here-doc bodies cm comments
|
|
15
|
+
* fn function names ct line continuations (`\`)
|
|
16
|
+
* dir directory arguments file file arguments, redirection targets
|
|
17
|
+
* re search patterns code program text (`sed`/`awk`/`jq` programs, `python -c`, `bash -c`)
|
|
18
|
+
* sc subcommands (`git status`, `npm run build`, `docker compose up`)
|
|
19
|
+
*
|
|
20
|
+
* Argument roles (`dir`, `file`, `re`, `code`, and `cmd` for nested commands
|
|
21
|
+
* such as `timeout 5 npx vitest`) come from the behavior definitions
|
|
22
|
+
* (src/behaviors/roles.ts); they recolor plain and quoted text but keep
|
|
23
|
+
* variables and substitutions inside the word.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type * as A from '../parser/ast.ts'
|
|
27
|
+
import { literalOf } from '../parser/parser.ts'
|
|
28
|
+
import { argRoles } from '../behaviors/roles.ts'
|
|
29
|
+
import type { ArgRole } from '../behaviors/types.ts'
|
|
30
|
+
|
|
31
|
+
export const CLASS_NAMES = ['', 'kw', 'op', 'cmd', 'flag', 'str', 'esc', 'var', 'sub', 'ar', 'num', 'asg', 'rd', 'hd', 'cm', 'fn', 'dir', 'file', 're', 'code', 'sc'] as const
|
|
32
|
+
export type ClassName = (typeof CLASS_NAMES)[number]
|
|
33
|
+
|
|
34
|
+
const INDEX = new Map<string, number>(CLASS_NAMES.map((c, i) => [c, i]))
|
|
35
|
+
const ROLE_CLASS: Record<ArgRole, ClassName> = { dir: 'dir', file: 'file', pattern: 're', code: 'code', cmd: 'cmd', subcommand: 'sc' }
|
|
36
|
+
/** Classes a role may recolor (variables, substitutions, arithmetic stay). */
|
|
37
|
+
const RECOLOR = new Set([INDEX.get('')!, INDEX.get('str')!, INDEX.get('esc')!])
|
|
38
|
+
|
|
39
|
+
/** Roles of a simple command's words (aligned with `c.words`), from the behavior definitions. */
|
|
40
|
+
export function simpleCommandRoles(c: A.SimpleCommand): (ArgRole | undefined)[] {
|
|
41
|
+
const words = c.words.map((w) => (w.type === 'Word' ? literalOf(w) ?? undefined : undefined))
|
|
42
|
+
if (words[0] === undefined) return words.map(() => undefined)
|
|
43
|
+
return argRoles(words)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class Highlight {
|
|
47
|
+
private readonly cls: Uint8Array
|
|
48
|
+
readonly source: string
|
|
49
|
+
|
|
50
|
+
constructor(script: A.Script, source: string) {
|
|
51
|
+
this.source = source
|
|
52
|
+
this.cls = new Uint8Array(source.length)
|
|
53
|
+
for (const s of script.body) this.stmt(s)
|
|
54
|
+
for (const c of script.comments ?? []) this.paint(c.span.start, c.span.end, 'cm')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The class runs covering `[start, end)`. */
|
|
58
|
+
runs(start: number, end: number): { text: string; cls: ClassName }[] {
|
|
59
|
+
const out: { text: string; cls: ClassName }[] = []
|
|
60
|
+
let i = start
|
|
61
|
+
while (i < end) {
|
|
62
|
+
const c = this.cls[i]
|
|
63
|
+
let j = i + 1
|
|
64
|
+
while (j < end && this.cls[j] === c) j++
|
|
65
|
+
out.push({ text: this.source.slice(i, j), cls: CLASS_NAMES[c] })
|
|
66
|
+
i = j
|
|
67
|
+
}
|
|
68
|
+
return out
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Recolor the plain and quoted characters of a span. */
|
|
72
|
+
private recolor(start: number, end: number, cls: ClassName): void {
|
|
73
|
+
const v = INDEX.get(cls) ?? 0
|
|
74
|
+
for (let i = Math.max(0, start); i < Math.min(end, this.cls.length); i++) if (RECOLOR.has(this.cls[i])) this.cls[i] = v
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private paint(start: number, end: number, cls: ClassName): void {
|
|
78
|
+
const v = INDEX.get(cls) ?? 0
|
|
79
|
+
for (let i = Math.max(0, start); i < Math.min(end, this.cls.length); i++) this.cls[i] = v
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private stmts(list: A.Stmt[]): void {
|
|
83
|
+
for (const s of list) this.stmt(s)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private stmt(s: A.Stmt): void {
|
|
87
|
+
this.command(s.command)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private command(c: A.Command): void {
|
|
91
|
+
switch (c.type) {
|
|
92
|
+
case 'SimpleCommand': {
|
|
93
|
+
for (const a of c.assigns) this.assign(a)
|
|
94
|
+
let first = true
|
|
95
|
+
let roles: (ArgRole | undefined)[] = []
|
|
96
|
+
try {
|
|
97
|
+
roles = simpleCommandRoles(c)
|
|
98
|
+
} catch {
|
|
99
|
+
// display only
|
|
100
|
+
}
|
|
101
|
+
c.words.forEach((w, i) => {
|
|
102
|
+
if (w.type === 'Assign') {
|
|
103
|
+
this.assign(w)
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
const text = this.source.slice(w.span.start, w.span.end)
|
|
107
|
+
this.word(w, first ? 'cmd' : /^-./.test(text) ? 'flag' : '')
|
|
108
|
+
first = false
|
|
109
|
+
const role = roles[i]
|
|
110
|
+
if (role && i > 0) this.recolor(w.span.start, w.span.end, ROLE_CLASS[role])
|
|
111
|
+
})
|
|
112
|
+
for (const r of c.redirs) this.redirect(r)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
case 'Pipeline':
|
|
116
|
+
for (const st of c.stages) this.command(st)
|
|
117
|
+
return
|
|
118
|
+
case 'AndOr':
|
|
119
|
+
for (const it of c.items) this.command(it)
|
|
120
|
+
return
|
|
121
|
+
case 'FunctionDef':
|
|
122
|
+
this.paint(c.span.start, c.body.span.start, 'fn')
|
|
123
|
+
this.command(c.body)
|
|
124
|
+
return
|
|
125
|
+
case 'Subshell':
|
|
126
|
+
case 'Group':
|
|
127
|
+
this.stmts(c.body)
|
|
128
|
+
break
|
|
129
|
+
case 'If':
|
|
130
|
+
for (const cl of c.clauses) {
|
|
131
|
+
this.stmts(cl.cond)
|
|
132
|
+
this.stmts(cl.body)
|
|
133
|
+
}
|
|
134
|
+
if (c.elseBody) this.stmts(c.elseBody)
|
|
135
|
+
break
|
|
136
|
+
case 'Loop':
|
|
137
|
+
this.stmts(c.cond)
|
|
138
|
+
this.stmts(c.body)
|
|
139
|
+
break
|
|
140
|
+
case 'For':
|
|
141
|
+
case 'Select':
|
|
142
|
+
for (const w of c.items ?? []) this.word(w, '')
|
|
143
|
+
this.stmts(c.body)
|
|
144
|
+
break
|
|
145
|
+
case 'ArithFor': {
|
|
146
|
+
this.paint(c.span.start, c.span.start + 3, 'kw')
|
|
147
|
+
const exprs = [c.init, c.cond, c.step].filter((e): e is A.ArithExpr => e !== null)
|
|
148
|
+
const from = exprs.length ? exprs[exprs.length - 1].span.end : c.span.start
|
|
149
|
+
const close = this.source.indexOf('))', from)
|
|
150
|
+
this.paint(c.span.start + 3, close + 2, 'ar')
|
|
151
|
+
for (const e of exprs) this.arith(e)
|
|
152
|
+
this.stmts(c.body)
|
|
153
|
+
break
|
|
154
|
+
}
|
|
155
|
+
case 'Case':
|
|
156
|
+
this.word(c.word, '')
|
|
157
|
+
for (const it of c.items) {
|
|
158
|
+
for (const p of it.patterns) this.word(p, '')
|
|
159
|
+
this.stmts(it.body)
|
|
160
|
+
}
|
|
161
|
+
break
|
|
162
|
+
case 'ArithCommand': {
|
|
163
|
+
const end = c.redirs[0]?.span.start ?? c.span.end
|
|
164
|
+
this.paint(c.span.start, end, 'ar')
|
|
165
|
+
this.arith(c.expr)
|
|
166
|
+
break
|
|
167
|
+
}
|
|
168
|
+
case 'CondCommand': {
|
|
169
|
+
const end = this.source.lastIndexOf(']]', c.redirs[0]?.span.start ?? c.span.end)
|
|
170
|
+
this.paint(c.span.start, c.span.start + 2, 'kw')
|
|
171
|
+
if (end >= 0) this.paint(end, end + 2, 'kw')
|
|
172
|
+
this.cond(c.expr)
|
|
173
|
+
break
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
for (const r of c.redirs) this.redirect(r)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private assign(a: A.Assign): void {
|
|
180
|
+
const valueStart = a.value ? a.value.span.start : a.span.end
|
|
181
|
+
this.paint(a.span.start, valueStart, 'asg')
|
|
182
|
+
if (a.index) this.word(a.index, '')
|
|
183
|
+
if (!a.value) return
|
|
184
|
+
if (a.value.type === 'Word') this.word(a.value, '')
|
|
185
|
+
else for (const el of a.value.elems) {
|
|
186
|
+
if (el.index) this.word(el.index, '')
|
|
187
|
+
this.word(el.value, '')
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private redirect(r: A.Redirect): void {
|
|
192
|
+
this.paint(r.span.start, r.target.span.start, 'rd')
|
|
193
|
+
if (r.heredoc) {
|
|
194
|
+
this.paint(r.target.span.start, r.target.span.end, 'rd')
|
|
195
|
+
const b = r.heredoc.body
|
|
196
|
+
this.paint(b.span.start, b.span.end, 'hd')
|
|
197
|
+
if (!r.heredoc.quoted) this.parts(b.parts)
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
this.word(r.target, '')
|
|
201
|
+
// a file target; an fd duplication (`2>&1`, `>&-`) is all redirection
|
|
202
|
+
if (/&$/.test(this.source.slice(r.span.start, r.target.span.start).trim())) this.recolor(r.target.span.start, r.target.span.end, 'rd')
|
|
203
|
+
else this.recolor(r.target.span.start, r.target.span.end, 'file')
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private word(w: A.Word, base: ClassName): void {
|
|
207
|
+
if (base) this.paint(w.span.start, w.span.end, base)
|
|
208
|
+
this.parts(w.parts)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private parts(parts: A.WordPart[]): void {
|
|
212
|
+
for (const p of parts) {
|
|
213
|
+
switch (p.type) {
|
|
214
|
+
case 'Lit':
|
|
215
|
+
break
|
|
216
|
+
case 'SglQuoted':
|
|
217
|
+
this.paint(p.span.start, p.span.end, 'str')
|
|
218
|
+
break
|
|
219
|
+
case 'Escaped':
|
|
220
|
+
this.paint(p.span.start, p.span.end, 'esc')
|
|
221
|
+
break
|
|
222
|
+
case 'DblQuoted':
|
|
223
|
+
this.paint(p.span.start, p.span.end, 'str')
|
|
224
|
+
this.parts(p.parts)
|
|
225
|
+
break
|
|
226
|
+
case 'ParamExp':
|
|
227
|
+
this.paint(p.span.start, p.span.end, 'var')
|
|
228
|
+
if (p.index) this.parts(p.index.parts)
|
|
229
|
+
if (p.op && 'word' in p.op && p.op.word) this.parts(p.op.word.parts)
|
|
230
|
+
if (p.op && p.op.kind === 'replace') {
|
|
231
|
+
this.parts(p.op.pattern.parts)
|
|
232
|
+
if (p.op.replacement) this.parts(p.op.replacement.parts)
|
|
233
|
+
}
|
|
234
|
+
if (p.op && (p.op.kind === 'removePrefix' || p.op.kind === 'removeSuffix')) this.parts(p.op.pattern.parts)
|
|
235
|
+
break
|
|
236
|
+
case 'CmdSubst':
|
|
237
|
+
if (p.backquote) {
|
|
238
|
+
this.paint(p.span.start, p.span.start + 1, 'sub')
|
|
239
|
+
this.paint(p.span.end - 1, p.span.end, 'sub')
|
|
240
|
+
} else {
|
|
241
|
+
this.paint(p.span.start, p.span.start + 2, 'sub')
|
|
242
|
+
this.paint(p.span.end - 1, p.span.end, 'sub')
|
|
243
|
+
}
|
|
244
|
+
this.stmts(p.body)
|
|
245
|
+
break
|
|
246
|
+
case 'ProcSubst':
|
|
247
|
+
this.paint(p.span.start, p.span.start + 2, 'sub')
|
|
248
|
+
this.paint(p.span.end - 1, p.span.end, 'sub')
|
|
249
|
+
this.stmts(p.body)
|
|
250
|
+
break
|
|
251
|
+
case 'ArithExp':
|
|
252
|
+
this.paint(p.span.start, p.span.end, 'ar')
|
|
253
|
+
this.arith(p.expr)
|
|
254
|
+
break
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private arith(e: A.ArithExpr): void {
|
|
260
|
+
switch (e.type) {
|
|
261
|
+
case 'ArithNum': this.paint(e.span.start, e.span.end, 'num'); break
|
|
262
|
+
case 'ArithVar': this.paint(e.span.start, e.span.start + e.name.length, 'var'); if (e.index) this.arith(e.index); break
|
|
263
|
+
case 'ArithWord': this.parts(e.word.parts); break
|
|
264
|
+
case 'ArithUnary': this.arith(e.operand); break
|
|
265
|
+
case 'ArithBinary': this.arith(e.left); this.arith(e.right); break
|
|
266
|
+
case 'ArithAssign': this.arith(e.target); this.arith(e.value); break
|
|
267
|
+
case 'ArithTernary': this.arith(e.cond); this.arith(e.then); this.arith(e.else); break
|
|
268
|
+
case 'ArithIncDec': this.arith(e.target); break
|
|
269
|
+
case 'ArithGroup': this.arith(e.expr); break
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private cond(e: A.CondExpr): void {
|
|
274
|
+
switch (e.type) {
|
|
275
|
+
case 'CondWord': this.word(e.word, ''); break
|
|
276
|
+
case 'CondUnary': this.paint(e.span.start, e.operand.span.start, 'op'); this.word(e.operand, ''); break
|
|
277
|
+
case 'CondBinary': this.word(e.left, ''); this.paint(e.left.span.end, e.right.span.start, 'op'); this.word(e.right, e.op === '=~' ? 'str' : ''); break
|
|
278
|
+
case 'CondNot': this.paint(e.span.start, e.span.start + 1, 'op'); this.cond(e.operand); break
|
|
279
|
+
case 'CondAndOr': this.cond(e.left); this.paint(e.left.span.end, e.right.span.start, 'op'); this.cond(e.right); break
|
|
280
|
+
case 'CondGroup': this.cond(e.expr); break
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|