@chaoswise/intl 1.0.0 → 1.2.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/bin/chaoswise-intl.js +5 -1
- package/bin/scripts/collect.js +38 -18
- package/bin/scripts/conf/default.js +40 -2
- package/bin/scripts/conf/getCustomConfig.js +8 -0
- package/bin/scripts/conf/index.js +2 -25
- package/bin/scripts/conf/initConfig.js +37 -0
- package/bin/scripts/initConfig.js +3 -0
- package/bin/scripts/service/index.js +2 -2
- package/bin/scripts/update.js +5 -5
- package/bin/scripts/util/FormPath/contexts.d.ts +10 -0
- package/bin/scripts/util/FormPath/contexts.js +23 -0
- package/bin/scripts/util/FormPath/destructor.d.ts +15 -0
- package/bin/scripts/util/FormPath/destructor.js +124 -0
- package/bin/scripts/util/FormPath/index.d.ts +49 -0
- package/bin/scripts/util/FormPath/index.js +536 -0
- package/bin/scripts/util/FormPath/lru.d.ts +1 -0
- package/bin/scripts/util/FormPath/lru.js +246 -0
- package/bin/scripts/util/FormPath/matcher.d.ts +33 -0
- package/bin/scripts/util/FormPath/matcher.js +216 -0
- package/bin/scripts/util/FormPath/parser.d.ts +28 -0
- package/bin/scripts/util/FormPath/parser.js +302 -0
- package/bin/scripts/util/FormPath/tokenizer.d.ts +26 -0
- package/bin/scripts/util/FormPath/tokenizer.js +280 -0
- package/bin/scripts/util/FormPath/tokens.d.ts +26 -0
- package/bin/scripts/util/FormPath/tokens.js +212 -0
- package/bin/scripts/util/FormPath/types.d.ts +76 -0
- package/bin/scripts/util/FormPath/types.js +17 -0
- package/bin/scripts/util/FormPath/utils.d.ts +10 -0
- package/bin/scripts/util/FormPath/utils.js +63 -0
- package/bin/scripts/util/downloadJson.js +10 -1
- package/bin/scripts/util/file.js +31 -0
- package/bin/scripts/util/getGroupName.js +15 -0
- package/bin/scripts/util/getWord.js +13 -0
- package/bin/scripts/util/log.js +25 -4
- package/bin/scripts/util/makeVisitorCollect.js +351 -46
- package/bin/scripts/util/makeVisitorUpdate.js +38 -1
- package/bin/scripts/util/specialMatch.js +14 -0
- package/bin/scripts/util/transformAst.js +30 -22
- package/bin/scripts/util/writeNewWordsFile.js +30 -0
- package/lib/index.js +2 -1
- package/package.json +7 -5
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LRUMap = void 0;
|
|
4
|
+
var NEWER = Symbol('newer');
|
|
5
|
+
var OLDER = Symbol('older');
|
|
6
|
+
function LRUMap(limit, entries) {
|
|
7
|
+
if (typeof limit !== 'number') {
|
|
8
|
+
entries = limit;
|
|
9
|
+
limit = 0;
|
|
10
|
+
}
|
|
11
|
+
this.size = 0;
|
|
12
|
+
this.limit = limit;
|
|
13
|
+
this.oldest = this.newest = undefined;
|
|
14
|
+
this._keymap = new Map();
|
|
15
|
+
if (entries) {
|
|
16
|
+
this.assign(entries);
|
|
17
|
+
if (limit < 1) {
|
|
18
|
+
this.limit = this.size;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.LRUMap = LRUMap;
|
|
23
|
+
function Entry(key, value) {
|
|
24
|
+
this.key = key;
|
|
25
|
+
this.value = value;
|
|
26
|
+
this[NEWER] = undefined;
|
|
27
|
+
this[OLDER] = undefined;
|
|
28
|
+
}
|
|
29
|
+
LRUMap.prototype._markEntryAsUsed = function (entry) {
|
|
30
|
+
if (entry === this.newest) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (entry[NEWER]) {
|
|
34
|
+
if (entry === this.oldest) {
|
|
35
|
+
this.oldest = entry[NEWER];
|
|
36
|
+
}
|
|
37
|
+
entry[NEWER][OLDER] = entry[OLDER];
|
|
38
|
+
}
|
|
39
|
+
if (entry[OLDER]) {
|
|
40
|
+
entry[OLDER][NEWER] = entry[NEWER];
|
|
41
|
+
}
|
|
42
|
+
entry[NEWER] = undefined;
|
|
43
|
+
entry[OLDER] = this.newest;
|
|
44
|
+
if (this.newest) {
|
|
45
|
+
this.newest[NEWER] = entry;
|
|
46
|
+
}
|
|
47
|
+
this.newest = entry;
|
|
48
|
+
};
|
|
49
|
+
LRUMap.prototype.assign = function (entries) {
|
|
50
|
+
var entry;
|
|
51
|
+
var limit = this.limit || Number.MAX_VALUE;
|
|
52
|
+
this._keymap.clear();
|
|
53
|
+
var it = entries[Symbol.iterator]();
|
|
54
|
+
for (var itv = it.next(); !itv.done; itv = it.next()) {
|
|
55
|
+
var e = new Entry(itv.value[0], itv.value[1]);
|
|
56
|
+
this._keymap.set(e.key, e);
|
|
57
|
+
if (!entry) {
|
|
58
|
+
this.oldest = e;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
entry[NEWER] = e;
|
|
62
|
+
e[OLDER] = entry;
|
|
63
|
+
}
|
|
64
|
+
entry = e;
|
|
65
|
+
if (limit-- === 0) {
|
|
66
|
+
throw new Error('overflow');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
this.newest = entry;
|
|
70
|
+
this.size = this._keymap.size;
|
|
71
|
+
};
|
|
72
|
+
LRUMap.prototype.get = function (key) {
|
|
73
|
+
var entry = this._keymap.get(key);
|
|
74
|
+
if (!entry) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this._markEntryAsUsed(entry);
|
|
78
|
+
return entry.value;
|
|
79
|
+
};
|
|
80
|
+
LRUMap.prototype.set = function (key, value) {
|
|
81
|
+
var entry = this._keymap.get(key);
|
|
82
|
+
if (entry) {
|
|
83
|
+
entry.value = value;
|
|
84
|
+
this._markEntryAsUsed(entry);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
this._keymap.set(key, (entry = new Entry(key, value)));
|
|
88
|
+
if (this.newest) {
|
|
89
|
+
this.newest[NEWER] = entry;
|
|
90
|
+
entry[OLDER] = this.newest;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.oldest = entry;
|
|
94
|
+
}
|
|
95
|
+
this.newest = entry;
|
|
96
|
+
++this.size;
|
|
97
|
+
if (this.size > this.limit) {
|
|
98
|
+
this.shift();
|
|
99
|
+
}
|
|
100
|
+
return this;
|
|
101
|
+
};
|
|
102
|
+
LRUMap.prototype.shift = function () {
|
|
103
|
+
var entry = this.oldest;
|
|
104
|
+
if (entry) {
|
|
105
|
+
if (this.oldest[NEWER]) {
|
|
106
|
+
this.oldest = this.oldest[NEWER];
|
|
107
|
+
this.oldest[OLDER] = undefined;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
this.oldest = undefined;
|
|
111
|
+
this.newest = undefined;
|
|
112
|
+
}
|
|
113
|
+
entry[NEWER] = entry[OLDER] = undefined;
|
|
114
|
+
this._keymap.delete(entry.key);
|
|
115
|
+
--this.size;
|
|
116
|
+
return [entry.key, entry.value];
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
LRUMap.prototype.find = function (key) {
|
|
120
|
+
var e = this._keymap.get(key);
|
|
121
|
+
return e ? e.value : undefined;
|
|
122
|
+
};
|
|
123
|
+
LRUMap.prototype.has = function (key) {
|
|
124
|
+
return this._keymap.has(key);
|
|
125
|
+
};
|
|
126
|
+
LRUMap.prototype.delete = function (key) {
|
|
127
|
+
var entry = this._keymap.get(key);
|
|
128
|
+
if (!entry) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this._keymap.delete(entry.key);
|
|
132
|
+
if (entry[NEWER] && entry[OLDER]) {
|
|
133
|
+
entry[OLDER][NEWER] = entry[NEWER];
|
|
134
|
+
entry[NEWER][OLDER] = entry[OLDER];
|
|
135
|
+
}
|
|
136
|
+
else if (entry[NEWER]) {
|
|
137
|
+
entry[NEWER][OLDER] = undefined;
|
|
138
|
+
this.oldest = entry[NEWER];
|
|
139
|
+
}
|
|
140
|
+
else if (entry[OLDER]) {
|
|
141
|
+
entry[OLDER][NEWER] = undefined;
|
|
142
|
+
this.newest = entry[OLDER];
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.oldest = this.newest = undefined;
|
|
146
|
+
}
|
|
147
|
+
this.size--;
|
|
148
|
+
return entry.value;
|
|
149
|
+
};
|
|
150
|
+
LRUMap.prototype.clear = function () {
|
|
151
|
+
this.oldest = this.newest = undefined;
|
|
152
|
+
this.size = 0;
|
|
153
|
+
this._keymap.clear();
|
|
154
|
+
};
|
|
155
|
+
function EntryIterator(oldestEntry) {
|
|
156
|
+
this.entry = oldestEntry;
|
|
157
|
+
}
|
|
158
|
+
EntryIterator.prototype[Symbol.iterator] = function () {
|
|
159
|
+
return this;
|
|
160
|
+
};
|
|
161
|
+
EntryIterator.prototype.next = function () {
|
|
162
|
+
var ent = this.entry;
|
|
163
|
+
if (ent) {
|
|
164
|
+
this.entry = ent[NEWER];
|
|
165
|
+
return { done: false, value: [ent.key, ent.value] };
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return { done: true, value: undefined };
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
function KeyIterator(oldestEntry) {
|
|
172
|
+
this.entry = oldestEntry;
|
|
173
|
+
}
|
|
174
|
+
KeyIterator.prototype[Symbol.iterator] = function () {
|
|
175
|
+
return this;
|
|
176
|
+
};
|
|
177
|
+
KeyIterator.prototype.next = function () {
|
|
178
|
+
var ent = this.entry;
|
|
179
|
+
if (ent) {
|
|
180
|
+
this.entry = ent[NEWER];
|
|
181
|
+
return { done: false, value: ent.key };
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
return { done: true, value: undefined };
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
function ValueIterator(oldestEntry) {
|
|
188
|
+
this.entry = oldestEntry;
|
|
189
|
+
}
|
|
190
|
+
ValueIterator.prototype[Symbol.iterator] = function () {
|
|
191
|
+
return this;
|
|
192
|
+
};
|
|
193
|
+
ValueIterator.prototype.next = function () {
|
|
194
|
+
var ent = this.entry;
|
|
195
|
+
if (ent) {
|
|
196
|
+
this.entry = ent[NEWER];
|
|
197
|
+
return { done: false, value: ent.value };
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return { done: true, value: undefined };
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
LRUMap.prototype.keys = function () {
|
|
204
|
+
return new KeyIterator(this.oldest);
|
|
205
|
+
};
|
|
206
|
+
LRUMap.prototype.values = function () {
|
|
207
|
+
return new ValueIterator(this.oldest);
|
|
208
|
+
};
|
|
209
|
+
LRUMap.prototype.entries = function () {
|
|
210
|
+
return this;
|
|
211
|
+
};
|
|
212
|
+
LRUMap.prototype[Symbol.iterator] = function () {
|
|
213
|
+
return new EntryIterator(this.oldest);
|
|
214
|
+
};
|
|
215
|
+
LRUMap.prototype.forEach = function (fun, thisObj) {
|
|
216
|
+
if (typeof thisObj !== 'object') {
|
|
217
|
+
thisObj = this;
|
|
218
|
+
}
|
|
219
|
+
var entry = this.oldest;
|
|
220
|
+
while (entry) {
|
|
221
|
+
fun.call(thisObj, entry.value, entry.key, this);
|
|
222
|
+
entry = entry[NEWER];
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
LRUMap.prototype.toJSON = function () {
|
|
226
|
+
var s = new Array(this.size);
|
|
227
|
+
var i = 0;
|
|
228
|
+
var entry = this.oldest;
|
|
229
|
+
while (entry) {
|
|
230
|
+
s[i++] = { key: entry.key, value: entry.value };
|
|
231
|
+
entry = entry[NEWER];
|
|
232
|
+
}
|
|
233
|
+
return s;
|
|
234
|
+
};
|
|
235
|
+
LRUMap.prototype.toString = function () {
|
|
236
|
+
var s = '';
|
|
237
|
+
var entry = this.oldest;
|
|
238
|
+
while (entry) {
|
|
239
|
+
s += String(entry.key) + ':' + entry.value;
|
|
240
|
+
entry = entry[NEWER];
|
|
241
|
+
if (entry) {
|
|
242
|
+
s += ' < ';
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return s;
|
|
246
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Segments, Node, IdentifierNode, IgnoreExpressionNode, DestructorExpressionNode, ExpandOperatorNode, WildcardOperatorNode, GroupExpressionNode, RangeExpressionNode, DotOperatorNode } from './types';
|
|
2
|
+
export declare class Matcher {
|
|
3
|
+
private tree;
|
|
4
|
+
private pos;
|
|
5
|
+
private tail;
|
|
6
|
+
private stack;
|
|
7
|
+
private excluding;
|
|
8
|
+
private record;
|
|
9
|
+
constructor(tree: Node, record?: any);
|
|
10
|
+
currentElement(path: Segments): string;
|
|
11
|
+
matchNext: (node: any, path: any) => any;
|
|
12
|
+
recordMatch(match: () => boolean): () => boolean;
|
|
13
|
+
matchIdentifier(path: Segments, node: IdentifierNode): any;
|
|
14
|
+
matchIgnoreExpression(path: Segments, node: IgnoreExpressionNode): any;
|
|
15
|
+
matchDestructorExpression(path: Segments, node: DestructorExpressionNode): any;
|
|
16
|
+
matchExpandOperator(path: Segments, node: ExpandOperatorNode): any;
|
|
17
|
+
matchWildcardOperator(path: Segments, node: WildcardOperatorNode): any;
|
|
18
|
+
matchGroupExpression(path: Segments, node: GroupExpressionNode): any;
|
|
19
|
+
matchRangeExpression(path: Segments, node: RangeExpressionNode): boolean;
|
|
20
|
+
matchDotOperator(path: Segments, node: DotOperatorNode): any;
|
|
21
|
+
matchAtom(path: Segments, node: Node): any;
|
|
22
|
+
match(path: Segments): {
|
|
23
|
+
matched: boolean;
|
|
24
|
+
record?: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
matched: any;
|
|
27
|
+
record: any;
|
|
28
|
+
};
|
|
29
|
+
static matchSegments(source: Segments, target: Segments, record?: any): false | {
|
|
30
|
+
matched: any;
|
|
31
|
+
record: any;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Matcher = void 0;
|
|
4
|
+
var types_1 = require("./types");
|
|
5
|
+
var utils_1 = require("./utils");
|
|
6
|
+
var isValid = function (val) { return val !== undefined && val !== null && val !== ''; };
|
|
7
|
+
var Matcher = (function () {
|
|
8
|
+
function Matcher(tree, record) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
this.matchNext = function (node, path) {
|
|
11
|
+
return node.after
|
|
12
|
+
? _this.matchAtom(path, node.after)
|
|
13
|
+
: isValid(path[_this.pos]);
|
|
14
|
+
};
|
|
15
|
+
this.tree = tree;
|
|
16
|
+
this.pos = 0;
|
|
17
|
+
this.excluding = false;
|
|
18
|
+
this.record = record;
|
|
19
|
+
this.stack = [];
|
|
20
|
+
}
|
|
21
|
+
Matcher.prototype.currentElement = function (path) {
|
|
22
|
+
return String(path[this.pos] || '').replace(/\s*/g, '');
|
|
23
|
+
};
|
|
24
|
+
Matcher.prototype.recordMatch = function (match) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
return function () {
|
|
27
|
+
var result = match();
|
|
28
|
+
if (result) {
|
|
29
|
+
if (_this.record && _this.record.score !== undefined) {
|
|
30
|
+
_this.record.score++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
Matcher.prototype.matchIdentifier = function (path, node) {
|
|
37
|
+
var _this = this;
|
|
38
|
+
this.tail = node;
|
|
39
|
+
if (isValid(path[this.pos + 1]) && !node.after) {
|
|
40
|
+
if (this.stack.length) {
|
|
41
|
+
for (var i = this.stack.length - 1; i >= 0; i--) {
|
|
42
|
+
if (!this.stack[i].after || !this.stack[i].filter) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
var current;
|
|
52
|
+
var next = function () {
|
|
53
|
+
return _this.matchNext(node, path);
|
|
54
|
+
};
|
|
55
|
+
if (types_1.isExpandOperator(node.after)) {
|
|
56
|
+
current = this.recordMatch(function () {
|
|
57
|
+
return node.value === String(path[_this.pos]).substring(0, node.value.length);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
current = this.recordMatch(function () {
|
|
62
|
+
return utils_1.isEqual(String(node.value), String(path[_this.pos]));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (this.excluding) {
|
|
66
|
+
if (node.after) {
|
|
67
|
+
if (this.pos < path.length) {
|
|
68
|
+
return current() && next();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (node.after && types_1.isWildcardOperator(node.after.after)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (this.pos >= path.length) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return current();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return current() && next();
|
|
85
|
+
};
|
|
86
|
+
Matcher.prototype.matchIgnoreExpression = function (path, node) {
|
|
87
|
+
return (utils_1.isEqual(node.value, this.currentElement(path)) &&
|
|
88
|
+
this.matchNext(node, path));
|
|
89
|
+
};
|
|
90
|
+
Matcher.prototype.matchDestructorExpression = function (path, node) {
|
|
91
|
+
return (utils_1.isEqual(node.source, this.currentElement(path)) &&
|
|
92
|
+
this.matchNext(node, path));
|
|
93
|
+
};
|
|
94
|
+
Matcher.prototype.matchExpandOperator = function (path, node) {
|
|
95
|
+
return this.matchAtom(path, node.after);
|
|
96
|
+
};
|
|
97
|
+
Matcher.prototype.matchWildcardOperator = function (path, node) {
|
|
98
|
+
this.tail = node;
|
|
99
|
+
this.stack.push(node);
|
|
100
|
+
var matched = false;
|
|
101
|
+
if (node.filter) {
|
|
102
|
+
if (node.after) {
|
|
103
|
+
matched =
|
|
104
|
+
this.matchAtom(path, node.filter) && this.matchAtom(path, node.after);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
matched = this.matchAtom(path, node.filter);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
matched = this.matchNext(node, path);
|
|
112
|
+
}
|
|
113
|
+
this.stack.pop();
|
|
114
|
+
return matched;
|
|
115
|
+
};
|
|
116
|
+
Matcher.prototype.matchGroupExpression = function (path, node) {
|
|
117
|
+
var _this = this;
|
|
118
|
+
var current = this.pos;
|
|
119
|
+
this.excluding = !!node.isExclude;
|
|
120
|
+
var method = this.excluding ? 'every' : 'some';
|
|
121
|
+
var result = utils_1.toArray(node.value)[method](function (_node) {
|
|
122
|
+
_this.pos = current;
|
|
123
|
+
return _this.excluding
|
|
124
|
+
? !_this.matchAtom(path, _node)
|
|
125
|
+
: _this.matchAtom(path, _node);
|
|
126
|
+
});
|
|
127
|
+
this.excluding = false;
|
|
128
|
+
return result;
|
|
129
|
+
};
|
|
130
|
+
Matcher.prototype.matchRangeExpression = function (path, node) {
|
|
131
|
+
if (node.start) {
|
|
132
|
+
if (node.end) {
|
|
133
|
+
return (path[this.pos] >= parseInt(node.start.value) &&
|
|
134
|
+
path[this.pos] <= parseInt(node.end.value));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return path[this.pos] >= parseInt(node.start.value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
if (node.end) {
|
|
142
|
+
return path[this.pos] <= parseInt(node.end.value);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
Matcher.prototype.matchDotOperator = function (path, node) {
|
|
150
|
+
this.pos++;
|
|
151
|
+
return this.matchNext(node, path);
|
|
152
|
+
};
|
|
153
|
+
Matcher.prototype.matchAtom = function (path, node) {
|
|
154
|
+
if (!node) {
|
|
155
|
+
if (this.stack.length > 0)
|
|
156
|
+
return true;
|
|
157
|
+
if (isValid(path[this.pos + 1]))
|
|
158
|
+
return false;
|
|
159
|
+
if (this.pos == path.length - 1)
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
if (types_1.isIdentifier(node)) {
|
|
163
|
+
return this.matchIdentifier(path, node);
|
|
164
|
+
}
|
|
165
|
+
else if (types_1.isIgnoreExpression(node)) {
|
|
166
|
+
return this.matchIgnoreExpression(path, node);
|
|
167
|
+
}
|
|
168
|
+
else if (types_1.isDestructorExpression(node)) {
|
|
169
|
+
return this.matchDestructorExpression(path, node);
|
|
170
|
+
}
|
|
171
|
+
else if (types_1.isExpandOperator(node)) {
|
|
172
|
+
return this.matchExpandOperator(path, node);
|
|
173
|
+
}
|
|
174
|
+
else if (types_1.isWildcardOperator(node)) {
|
|
175
|
+
return this.matchWildcardOperator(path, node);
|
|
176
|
+
}
|
|
177
|
+
else if (types_1.isGroupExpression(node)) {
|
|
178
|
+
return this.matchGroupExpression(path, node);
|
|
179
|
+
}
|
|
180
|
+
else if (types_1.isRangeExpression(node)) {
|
|
181
|
+
return this.matchRangeExpression(path, node);
|
|
182
|
+
}
|
|
183
|
+
else if (types_1.isDotOperator(node)) {
|
|
184
|
+
return this.matchDotOperator(path, node);
|
|
185
|
+
}
|
|
186
|
+
return true;
|
|
187
|
+
};
|
|
188
|
+
Matcher.prototype.match = function (path) {
|
|
189
|
+
var matched = this.matchAtom(path, this.tree);
|
|
190
|
+
if (!this.tail)
|
|
191
|
+
return { matched: false };
|
|
192
|
+
if (this.tail == this.tree && types_1.isWildcardOperator(this.tail)) {
|
|
193
|
+
return { matched: true };
|
|
194
|
+
}
|
|
195
|
+
return { matched: matched, record: this.record };
|
|
196
|
+
};
|
|
197
|
+
Matcher.matchSegments = function (source, target, record) {
|
|
198
|
+
var pos = 0;
|
|
199
|
+
if (source.length !== target.length)
|
|
200
|
+
return false;
|
|
201
|
+
var match = function (pos) {
|
|
202
|
+
var current = function () {
|
|
203
|
+
var res = utils_1.isEqual(source[pos], target[pos]);
|
|
204
|
+
if (record && record.score !== undefined) {
|
|
205
|
+
record.score++;
|
|
206
|
+
}
|
|
207
|
+
return res;
|
|
208
|
+
};
|
|
209
|
+
var next = function () { return (pos < source.length - 1 ? match(pos + 1) : true); };
|
|
210
|
+
return current() && next();
|
|
211
|
+
};
|
|
212
|
+
return { matched: match(pos), record: record };
|
|
213
|
+
};
|
|
214
|
+
return Matcher;
|
|
215
|
+
}());
|
|
216
|
+
exports.Matcher = Matcher;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Tokenizer } from './tokenizer';
|
|
2
|
+
import { Token } from './tokens';
|
|
3
|
+
import { IdentifierNode, ExpandOperatorNode, WildcardOperatorNode, RangeExpressionNode, GroupExpressionNode, IgnoreExpressionNode, DestructorExpressionNode, ObjectPatternNode, ObjectPatternPropertyNode, ArrayPatternNode, Node, Segments } from './types';
|
|
4
|
+
export declare class Parser extends Tokenizer {
|
|
5
|
+
isMatchPattern: boolean;
|
|
6
|
+
isWildMatchPattern: boolean;
|
|
7
|
+
haveExcludePattern: boolean;
|
|
8
|
+
data: {
|
|
9
|
+
segments: Segments;
|
|
10
|
+
tree?: Node;
|
|
11
|
+
};
|
|
12
|
+
parse(): Node;
|
|
13
|
+
append(parent: Node, node: Node): void;
|
|
14
|
+
parseAtom(type: Token): Node;
|
|
15
|
+
pushSegments(key: string | number): void;
|
|
16
|
+
parseIdentifier(): IdentifierNode;
|
|
17
|
+
parseExpandOperator(): ExpandOperatorNode;
|
|
18
|
+
parseWildcardOperator(): WildcardOperatorNode;
|
|
19
|
+
parseDestructorExpression(): DestructorExpressionNode;
|
|
20
|
+
parseArrayPattern(): ArrayPatternNode;
|
|
21
|
+
parseArrayPatternElements(): any[];
|
|
22
|
+
parseObjectPattern(): ObjectPatternNode;
|
|
23
|
+
parseObjectProperties(): ObjectPatternPropertyNode[];
|
|
24
|
+
parseDotOperator(): Node;
|
|
25
|
+
parseIgnoreExpression(): IgnoreExpressionNode;
|
|
26
|
+
parseGroupExpression(parent: Node): GroupExpressionNode;
|
|
27
|
+
parseRangeExpression(parent: Node): RangeExpressionNode;
|
|
28
|
+
}
|