-
-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathutils.ts
More file actions
60 lines (60 loc) · 1.54 KB
/
Copy pathutils.ts
File metadata and controls
60 lines (60 loc) · 1.54 KB
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
export function traverseGrammarPatterns(a: any, callback: (pattern: string) => any | void): void {
if (Array.isArray(a)) {
a.forEach((j: any) => {
traverseGrammarPatterns(j, callback)
})
return
}
if (!a || typeof a !== 'object')
return
if (a.foldingStartMarker) {
const pattern = callback(a.foldingStartMarker)
if (pattern != null)
a.foldingStartMarker = pattern
}
if (a.foldingStopMarker) {
const pattern = callback(a.foldingStopMarker)
if (pattern != null)
a.foldingStopMarker = pattern
}
if (a.firstLineMatch) {
const pattern = callback(a.firstLineMatch)
if (pattern != null)
a.firstLineMatch = pattern
}
if (a.match) {
const pattern = callback(a.match)
if (pattern != null)
a.match = pattern
}
if (a.begin) {
const pattern = callback(a.begin)
if (pattern != null)
a.begin = pattern
}
if (a.end) {
const pattern = callback(a.end)
if (pattern != null)
a.end = pattern
}
if (a.while) {
const pattern = callback(a.while)
if (pattern != null)
a.while = pattern
}
if (a.patterns) {
traverseGrammarPatterns(a.patterns, callback)
}
if (a.captures) {
traverseGrammarPatterns(Object.values(a.captures), callback)
}
if (a.beginCaptures) {
traverseGrammarPatterns(Object.values(a.beginCaptures), callback)
}
if (a.endCaptures) {
traverseGrammarPatterns(Object.values(a.endCaptures), callback)
}
Object.values(a.repository || {}).forEach((j: any) => {
traverseGrammarPatterns(j, callback)
})
}