@wener/common 1.0.2 → 1.0.3
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/lib/cn/DivisionCode.js +311 -0
- package/lib/cn/DivisionCode.js.map +1 -0
- package/lib/cn/Mod11Checksum.js +42 -0
- package/lib/cn/Mod11Checksum.js.map +1 -0
- package/lib/cn/Mod31Checksum.js +48 -0
- package/lib/cn/Mod31Checksum.js.map +1 -0
- package/lib/cn/ResidentIdentityCardNumber.js +50 -0
- package/lib/cn/ResidentIdentityCardNumber.js.map +1 -0
- package/lib/cn/UnifiedSocialCreditCode.js +118 -0
- package/lib/cn/UnifiedSocialCreditCode.js.map +1 -0
- package/lib/cn/formatDate.js +15 -0
- package/lib/cn/formatDate.js.map +1 -0
- package/lib/cn/index.js +4 -0
- package/lib/cn/index.js.map +1 -0
- package/lib/cn/parseSex.js +22 -0
- package/lib/cn/parseSex.js.map +1 -0
- package/lib/cn/types.d.js +8 -0
- package/lib/cn/types.d.js.map +1 -0
- package/lib/meta/defineFileType.js +44 -0
- package/lib/meta/defineFileType.js.map +1 -0
- package/lib/meta/defineMetadata.js +14 -3
- package/lib/meta/defineMetadata.js.map +1 -1
- package/lib/meta/index.js +1 -0
- package/lib/meta/index.js.map +1 -1
- package/lib/parseSort.js +15 -0
- package/lib/parseSort.js.map +1 -1
- package/lib/search/formatAdvanceSearch.js +1 -1
- package/lib/search/formatAdvanceSearch.js.map +1 -1
- package/lib/search/parser.js +380 -76
- package/lib/search/parser.js.map +1 -1
- package/lib/search/types.d.js.map +1 -1
- package/package.json +8 -4
- package/src/cn/DivisionCode.test.ts +50 -0
- package/src/cn/DivisionCode.ts +253 -0
- package/src/cn/Mod11Checksum.ts +24 -0
- package/src/cn/Mod31Checksum.ts +36 -0
- package/src/cn/ResidentIdentityCardNumber.test.ts +21 -0
- package/src/cn/ResidentIdentityCardNumber.ts +96 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +16 -0
- package/src/cn/UnifiedSocialCreditCode.ts +148 -0
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +15 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +41 -0
- package/src/cn/formatDate.ts +12 -0
- package/src/cn/index.ts +3 -0
- package/src/cn/parseSex.ts +27 -0
- package/src/cn/types.d.ts +51 -0
- package/src/meta/defineFileType.tsx +68 -0
- package/src/meta/defineMetadata.ts +16 -3
- package/src/meta/index.ts +2 -0
- package/src/parseSort.ts +18 -0
- package/src/search/AdvanceSearch.test.ts +2 -2
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +3 -3
- package/src/search/formatAdvanceSearch.ts +1 -1
- package/src/search/parser.js +325 -73
- package/src/search/parser.peggy +42 -9
- package/src/search/types.d.ts +1 -1
package/src/search/parser.js
CHANGED
|
@@ -196,12 +196,23 @@ function peg$parse(input, options) {
|
|
|
196
196
|
var peg$c18 = "T";
|
|
197
197
|
var peg$c19 = "Z";
|
|
198
198
|
var peg$c20 = "\"";
|
|
199
|
-
var peg$c21 = "
|
|
200
|
-
var peg$c22 = "
|
|
201
|
-
var peg$c23 = "
|
|
202
|
-
var peg$c24 = "
|
|
203
|
-
var peg$c25 = "
|
|
204
|
-
var peg$c26 = "
|
|
199
|
+
var peg$c21 = "\\'";
|
|
200
|
+
var peg$c22 = "\\\"";
|
|
201
|
+
var peg$c23 = "\\\\";
|
|
202
|
+
var peg$c24 = "\\/";
|
|
203
|
+
var peg$c25 = "\\b";
|
|
204
|
+
var peg$c26 = "\\f";
|
|
205
|
+
var peg$c27 = "\\n";
|
|
206
|
+
var peg$c28 = "\\r";
|
|
207
|
+
var peg$c29 = "\\t";
|
|
208
|
+
var peg$c30 = "''";
|
|
209
|
+
var peg$c31 = "\\u";
|
|
210
|
+
var peg$c32 = "true";
|
|
211
|
+
var peg$c33 = "false";
|
|
212
|
+
var peg$c34 = "null";
|
|
213
|
+
var peg$c35 = "OR";
|
|
214
|
+
var peg$c36 = "AND";
|
|
215
|
+
var peg$c37 = "NOT";
|
|
205
216
|
|
|
206
217
|
var peg$r0 = /^[^*]/;
|
|
207
218
|
var peg$r1 = /^[^\-+,'" \r\n\t()]/;
|
|
@@ -212,9 +223,10 @@ function peg$parse(input, options) {
|
|
|
212
223
|
var peg$r6 = /^[0-9]/;
|
|
213
224
|
var peg$r7 = /^[a-zA-Z]/;
|
|
214
225
|
var peg$r8 = /^[_a-zA-Z0-9]/;
|
|
215
|
-
var peg$r9 = /^[^"]/;
|
|
216
|
-
var peg$r10 = /^[
|
|
217
|
-
var peg$r11 = /^[
|
|
226
|
+
var peg$r9 = /^[^"\\\0-\x1F\x7F]/;
|
|
227
|
+
var peg$r10 = /^[0-9a-fA-F]/;
|
|
228
|
+
var peg$r11 = /^[A-Za-z_]/;
|
|
229
|
+
var peg$r12 = /^[ \t\n\r]/;
|
|
218
230
|
|
|
219
231
|
var peg$e0 = peg$literalExpectation("/*", false);
|
|
220
232
|
var peg$e1 = peg$classExpectation(["*"], true, false);
|
|
@@ -246,17 +258,29 @@ function peg$parse(input, options) {
|
|
|
246
258
|
var peg$e27 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false);
|
|
247
259
|
var peg$e28 = peg$classExpectation(["_", ["a", "z"], ["A", "Z"], ["0", "9"]], false, false);
|
|
248
260
|
var peg$e29 = peg$literalExpectation("\"", false);
|
|
249
|
-
var peg$e30 = peg$classExpectation(["\""], true, false);
|
|
250
|
-
var peg$e31 = peg$literalExpectation("
|
|
251
|
-
var peg$e32 = peg$literalExpectation("
|
|
252
|
-
var peg$e33 = peg$literalExpectation("
|
|
253
|
-
var peg$e34 = peg$
|
|
254
|
-
var peg$e35 = peg$literalExpectation("
|
|
255
|
-
var peg$e36 = peg$literalExpectation("
|
|
256
|
-
var peg$e37 = peg$literalExpectation("
|
|
257
|
-
var peg$e38 = peg$
|
|
258
|
-
var peg$e39 = peg$
|
|
259
|
-
var peg$e40 = peg$
|
|
261
|
+
var peg$e30 = peg$classExpectation(["\"", "\\", ["\0", "\x1F"], "\x7F"], true, false);
|
|
262
|
+
var peg$e31 = peg$literalExpectation("\\'", false);
|
|
263
|
+
var peg$e32 = peg$literalExpectation("\\\"", false);
|
|
264
|
+
var peg$e33 = peg$literalExpectation("\\\\", false);
|
|
265
|
+
var peg$e34 = peg$literalExpectation("\\/", false);
|
|
266
|
+
var peg$e35 = peg$literalExpectation("\\b", false);
|
|
267
|
+
var peg$e36 = peg$literalExpectation("\\f", false);
|
|
268
|
+
var peg$e37 = peg$literalExpectation("\\n", false);
|
|
269
|
+
var peg$e38 = peg$literalExpectation("\\r", false);
|
|
270
|
+
var peg$e39 = peg$literalExpectation("\\t", false);
|
|
271
|
+
var peg$e40 = peg$literalExpectation("''", false);
|
|
272
|
+
var peg$e41 = peg$literalExpectation("\\u", false);
|
|
273
|
+
var peg$e42 = peg$classExpectation([["0", "9"], ["a", "f"], ["A", "F"]], false, false);
|
|
274
|
+
var peg$e43 = peg$literalExpectation("true", false);
|
|
275
|
+
var peg$e44 = peg$literalExpectation("false", false);
|
|
276
|
+
var peg$e45 = peg$literalExpectation("null", false);
|
|
277
|
+
var peg$e46 = peg$classExpectation([["A", "Z"], ["a", "z"], "_"], false, false);
|
|
278
|
+
var peg$e47 = peg$literalExpectation("OR", false);
|
|
279
|
+
var peg$e48 = peg$literalExpectation("AND", false);
|
|
280
|
+
var peg$e49 = peg$literalExpectation("NOT", false);
|
|
281
|
+
var peg$e50 = peg$otherExpectation("whitespace");
|
|
282
|
+
var peg$e51 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false);
|
|
283
|
+
var peg$e52 = peg$anyExpectation();
|
|
260
284
|
|
|
261
285
|
var peg$f0 = function(value) { return { type: "comment", value: value.trim() }; };
|
|
262
286
|
var peg$f1 = function(head, tail) {
|
|
@@ -297,7 +321,7 @@ function peg$parse(input, options) {
|
|
|
297
321
|
return {
|
|
298
322
|
type: "compare",
|
|
299
323
|
field,
|
|
300
|
-
operator: "
|
|
324
|
+
operator: "match",
|
|
301
325
|
value: { value },
|
|
302
326
|
mention: true,
|
|
303
327
|
};
|
|
@@ -336,12 +360,25 @@ function peg$parse(input, options) {
|
|
|
336
360
|
var peg$f20 = function() { return text(); };
|
|
337
361
|
var peg$f21 = function() { return parseFloat(text()); };
|
|
338
362
|
var peg$f22 = function(v) { return v.join(""); };
|
|
339
|
-
var peg$f23 = function() { return
|
|
340
|
-
var peg$f24 = function() { return
|
|
341
|
-
var peg$f25 = function() { return
|
|
342
|
-
var peg$f26 = function() { return
|
|
343
|
-
var peg$f27 = function() { return ""; };
|
|
344
|
-
var peg$f28 = function() { return "
|
|
363
|
+
var peg$f23 = function() { return "'"; };
|
|
364
|
+
var peg$f24 = function() { return '"'; };
|
|
365
|
+
var peg$f25 = function() { return "\\"; };
|
|
366
|
+
var peg$f26 = function() { return "/"; };
|
|
367
|
+
var peg$f27 = function() { return "\b"; };
|
|
368
|
+
var peg$f28 = function() { return "\f"; };
|
|
369
|
+
var peg$f29 = function() { return "\n"; };
|
|
370
|
+
var peg$f30 = function() { return "\r"; };
|
|
371
|
+
var peg$f31 = function() { return "\t"; };
|
|
372
|
+
var peg$f32 = function() { return "'"; };
|
|
373
|
+
var peg$f33 = function(h1, h2, h3, h4) {
|
|
374
|
+
return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
|
|
375
|
+
};
|
|
376
|
+
var peg$f34 = function() { return text().toLowerCase() === "true"; };
|
|
377
|
+
var peg$f35 = function() { return parseInt(text()); };
|
|
378
|
+
var peg$f36 = function() { return parseFloat(text()); };
|
|
379
|
+
var peg$f37 = function() { return null; };
|
|
380
|
+
var peg$f38 = function() { return ""; };
|
|
381
|
+
var peg$f39 = function() { return " "; };
|
|
345
382
|
var peg$currPos = options.peg$currPos | 0;
|
|
346
383
|
var peg$savedPos = peg$currPos;
|
|
347
384
|
var peg$posDetailsCache = [{ line: 1, column: 1 }];
|
|
@@ -2081,22 +2118,10 @@ function peg$parse(input, options) {
|
|
|
2081
2118
|
}
|
|
2082
2119
|
if (s1 !== peg$FAILED) {
|
|
2083
2120
|
s2 = [];
|
|
2084
|
-
s3 =
|
|
2085
|
-
if (peg$r9.test(s3)) {
|
|
2086
|
-
peg$currPos++;
|
|
2087
|
-
} else {
|
|
2088
|
-
s3 = peg$FAILED;
|
|
2089
|
-
if (peg$silentFails === 0) { peg$fail(peg$e30); }
|
|
2090
|
-
}
|
|
2121
|
+
s3 = peg$parsesingle_char();
|
|
2091
2122
|
while (s3 !== peg$FAILED) {
|
|
2092
2123
|
s2.push(s3);
|
|
2093
|
-
s3 =
|
|
2094
|
-
if (peg$r9.test(s3)) {
|
|
2095
|
-
peg$currPos++;
|
|
2096
|
-
} else {
|
|
2097
|
-
s3 = peg$FAILED;
|
|
2098
|
-
if (peg$silentFails === 0) { peg$fail(peg$e30); }
|
|
2099
|
-
}
|
|
2124
|
+
s3 = peg$parsesingle_char();
|
|
2100
2125
|
}
|
|
2101
2126
|
if (input.charCodeAt(peg$currPos) === 34) {
|
|
2102
2127
|
s3 = peg$c20;
|
|
@@ -2120,29 +2145,256 @@ function peg$parse(input, options) {
|
|
|
2120
2145
|
return s0;
|
|
2121
2146
|
}
|
|
2122
2147
|
|
|
2148
|
+
function peg$parsesingle_char() {
|
|
2149
|
+
var s0;
|
|
2150
|
+
|
|
2151
|
+
s0 = input.charAt(peg$currPos);
|
|
2152
|
+
if (peg$r9.test(s0)) {
|
|
2153
|
+
peg$currPos++;
|
|
2154
|
+
} else {
|
|
2155
|
+
s0 = peg$FAILED;
|
|
2156
|
+
if (peg$silentFails === 0) { peg$fail(peg$e30); }
|
|
2157
|
+
}
|
|
2158
|
+
if (s0 === peg$FAILED) {
|
|
2159
|
+
s0 = peg$parseescape_char();
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
return s0;
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
function peg$parseescape_char() {
|
|
2166
|
+
var s0, s1, s2, s3, s4, s5;
|
|
2167
|
+
|
|
2168
|
+
s0 = peg$currPos;
|
|
2169
|
+
if (input.substr(peg$currPos, 2) === peg$c21) {
|
|
2170
|
+
s1 = peg$c21;
|
|
2171
|
+
peg$currPos += 2;
|
|
2172
|
+
} else {
|
|
2173
|
+
s1 = peg$FAILED;
|
|
2174
|
+
if (peg$silentFails === 0) { peg$fail(peg$e31); }
|
|
2175
|
+
}
|
|
2176
|
+
if (s1 !== peg$FAILED) {
|
|
2177
|
+
peg$savedPos = s0;
|
|
2178
|
+
s1 = peg$f23();
|
|
2179
|
+
}
|
|
2180
|
+
s0 = s1;
|
|
2181
|
+
if (s0 === peg$FAILED) {
|
|
2182
|
+
s0 = peg$currPos;
|
|
2183
|
+
if (input.substr(peg$currPos, 2) === peg$c22) {
|
|
2184
|
+
s1 = peg$c22;
|
|
2185
|
+
peg$currPos += 2;
|
|
2186
|
+
} else {
|
|
2187
|
+
s1 = peg$FAILED;
|
|
2188
|
+
if (peg$silentFails === 0) { peg$fail(peg$e32); }
|
|
2189
|
+
}
|
|
2190
|
+
if (s1 !== peg$FAILED) {
|
|
2191
|
+
peg$savedPos = s0;
|
|
2192
|
+
s1 = peg$f24();
|
|
2193
|
+
}
|
|
2194
|
+
s0 = s1;
|
|
2195
|
+
if (s0 === peg$FAILED) {
|
|
2196
|
+
s0 = peg$currPos;
|
|
2197
|
+
if (input.substr(peg$currPos, 2) === peg$c23) {
|
|
2198
|
+
s1 = peg$c23;
|
|
2199
|
+
peg$currPos += 2;
|
|
2200
|
+
} else {
|
|
2201
|
+
s1 = peg$FAILED;
|
|
2202
|
+
if (peg$silentFails === 0) { peg$fail(peg$e33); }
|
|
2203
|
+
}
|
|
2204
|
+
if (s1 !== peg$FAILED) {
|
|
2205
|
+
peg$savedPos = s0;
|
|
2206
|
+
s1 = peg$f25();
|
|
2207
|
+
}
|
|
2208
|
+
s0 = s1;
|
|
2209
|
+
if (s0 === peg$FAILED) {
|
|
2210
|
+
s0 = peg$currPos;
|
|
2211
|
+
if (input.substr(peg$currPos, 2) === peg$c24) {
|
|
2212
|
+
s1 = peg$c24;
|
|
2213
|
+
peg$currPos += 2;
|
|
2214
|
+
} else {
|
|
2215
|
+
s1 = peg$FAILED;
|
|
2216
|
+
if (peg$silentFails === 0) { peg$fail(peg$e34); }
|
|
2217
|
+
}
|
|
2218
|
+
if (s1 !== peg$FAILED) {
|
|
2219
|
+
peg$savedPos = s0;
|
|
2220
|
+
s1 = peg$f26();
|
|
2221
|
+
}
|
|
2222
|
+
s0 = s1;
|
|
2223
|
+
if (s0 === peg$FAILED) {
|
|
2224
|
+
s0 = peg$currPos;
|
|
2225
|
+
if (input.substr(peg$currPos, 2) === peg$c25) {
|
|
2226
|
+
s1 = peg$c25;
|
|
2227
|
+
peg$currPos += 2;
|
|
2228
|
+
} else {
|
|
2229
|
+
s1 = peg$FAILED;
|
|
2230
|
+
if (peg$silentFails === 0) { peg$fail(peg$e35); }
|
|
2231
|
+
}
|
|
2232
|
+
if (s1 !== peg$FAILED) {
|
|
2233
|
+
peg$savedPos = s0;
|
|
2234
|
+
s1 = peg$f27();
|
|
2235
|
+
}
|
|
2236
|
+
s0 = s1;
|
|
2237
|
+
if (s0 === peg$FAILED) {
|
|
2238
|
+
s0 = peg$currPos;
|
|
2239
|
+
if (input.substr(peg$currPos, 2) === peg$c26) {
|
|
2240
|
+
s1 = peg$c26;
|
|
2241
|
+
peg$currPos += 2;
|
|
2242
|
+
} else {
|
|
2243
|
+
s1 = peg$FAILED;
|
|
2244
|
+
if (peg$silentFails === 0) { peg$fail(peg$e36); }
|
|
2245
|
+
}
|
|
2246
|
+
if (s1 !== peg$FAILED) {
|
|
2247
|
+
peg$savedPos = s0;
|
|
2248
|
+
s1 = peg$f28();
|
|
2249
|
+
}
|
|
2250
|
+
s0 = s1;
|
|
2251
|
+
if (s0 === peg$FAILED) {
|
|
2252
|
+
s0 = peg$currPos;
|
|
2253
|
+
if (input.substr(peg$currPos, 2) === peg$c27) {
|
|
2254
|
+
s1 = peg$c27;
|
|
2255
|
+
peg$currPos += 2;
|
|
2256
|
+
} else {
|
|
2257
|
+
s1 = peg$FAILED;
|
|
2258
|
+
if (peg$silentFails === 0) { peg$fail(peg$e37); }
|
|
2259
|
+
}
|
|
2260
|
+
if (s1 !== peg$FAILED) {
|
|
2261
|
+
peg$savedPos = s0;
|
|
2262
|
+
s1 = peg$f29();
|
|
2263
|
+
}
|
|
2264
|
+
s0 = s1;
|
|
2265
|
+
if (s0 === peg$FAILED) {
|
|
2266
|
+
s0 = peg$currPos;
|
|
2267
|
+
if (input.substr(peg$currPos, 2) === peg$c28) {
|
|
2268
|
+
s1 = peg$c28;
|
|
2269
|
+
peg$currPos += 2;
|
|
2270
|
+
} else {
|
|
2271
|
+
s1 = peg$FAILED;
|
|
2272
|
+
if (peg$silentFails === 0) { peg$fail(peg$e38); }
|
|
2273
|
+
}
|
|
2274
|
+
if (s1 !== peg$FAILED) {
|
|
2275
|
+
peg$savedPos = s0;
|
|
2276
|
+
s1 = peg$f30();
|
|
2277
|
+
}
|
|
2278
|
+
s0 = s1;
|
|
2279
|
+
if (s0 === peg$FAILED) {
|
|
2280
|
+
s0 = peg$currPos;
|
|
2281
|
+
if (input.substr(peg$currPos, 2) === peg$c29) {
|
|
2282
|
+
s1 = peg$c29;
|
|
2283
|
+
peg$currPos += 2;
|
|
2284
|
+
} else {
|
|
2285
|
+
s1 = peg$FAILED;
|
|
2286
|
+
if (peg$silentFails === 0) { peg$fail(peg$e39); }
|
|
2287
|
+
}
|
|
2288
|
+
if (s1 !== peg$FAILED) {
|
|
2289
|
+
peg$savedPos = s0;
|
|
2290
|
+
s1 = peg$f31();
|
|
2291
|
+
}
|
|
2292
|
+
s0 = s1;
|
|
2293
|
+
if (s0 === peg$FAILED) {
|
|
2294
|
+
s0 = peg$currPos;
|
|
2295
|
+
if (input.substr(peg$currPos, 2) === peg$c30) {
|
|
2296
|
+
s1 = peg$c30;
|
|
2297
|
+
peg$currPos += 2;
|
|
2298
|
+
} else {
|
|
2299
|
+
s1 = peg$FAILED;
|
|
2300
|
+
if (peg$silentFails === 0) { peg$fail(peg$e40); }
|
|
2301
|
+
}
|
|
2302
|
+
if (s1 !== peg$FAILED) {
|
|
2303
|
+
peg$savedPos = s0;
|
|
2304
|
+
s1 = peg$f32();
|
|
2305
|
+
}
|
|
2306
|
+
s0 = s1;
|
|
2307
|
+
if (s0 === peg$FAILED) {
|
|
2308
|
+
s0 = peg$currPos;
|
|
2309
|
+
if (input.substr(peg$currPos, 2) === peg$c31) {
|
|
2310
|
+
s1 = peg$c31;
|
|
2311
|
+
peg$currPos += 2;
|
|
2312
|
+
} else {
|
|
2313
|
+
s1 = peg$FAILED;
|
|
2314
|
+
if (peg$silentFails === 0) { peg$fail(peg$e41); }
|
|
2315
|
+
}
|
|
2316
|
+
if (s1 !== peg$FAILED) {
|
|
2317
|
+
s2 = peg$parsehex_digit();
|
|
2318
|
+
if (s2 !== peg$FAILED) {
|
|
2319
|
+
s3 = peg$parsehex_digit();
|
|
2320
|
+
if (s3 !== peg$FAILED) {
|
|
2321
|
+
s4 = peg$parsehex_digit();
|
|
2322
|
+
if (s4 !== peg$FAILED) {
|
|
2323
|
+
s5 = peg$parsehex_digit();
|
|
2324
|
+
if (s5 !== peg$FAILED) {
|
|
2325
|
+
peg$savedPos = s0;
|
|
2326
|
+
s0 = peg$f33(s2, s3, s4, s5);
|
|
2327
|
+
} else {
|
|
2328
|
+
peg$currPos = s0;
|
|
2329
|
+
s0 = peg$FAILED;
|
|
2330
|
+
}
|
|
2331
|
+
} else {
|
|
2332
|
+
peg$currPos = s0;
|
|
2333
|
+
s0 = peg$FAILED;
|
|
2334
|
+
}
|
|
2335
|
+
} else {
|
|
2336
|
+
peg$currPos = s0;
|
|
2337
|
+
s0 = peg$FAILED;
|
|
2338
|
+
}
|
|
2339
|
+
} else {
|
|
2340
|
+
peg$currPos = s0;
|
|
2341
|
+
s0 = peg$FAILED;
|
|
2342
|
+
}
|
|
2343
|
+
} else {
|
|
2344
|
+
peg$currPos = s0;
|
|
2345
|
+
s0 = peg$FAILED;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
return s0;
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
function peg$parsehex_digit() {
|
|
2362
|
+
var s0;
|
|
2363
|
+
|
|
2364
|
+
s0 = input.charAt(peg$currPos);
|
|
2365
|
+
if (peg$r10.test(s0)) {
|
|
2366
|
+
peg$currPos++;
|
|
2367
|
+
} else {
|
|
2368
|
+
s0 = peg$FAILED;
|
|
2369
|
+
if (peg$silentFails === 0) { peg$fail(peg$e42); }
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
return s0;
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2123
2375
|
function peg$parsebool() {
|
|
2124
2376
|
var s0, s1;
|
|
2125
2377
|
|
|
2126
2378
|
s0 = peg$currPos;
|
|
2127
|
-
if (input.substr(peg$currPos, 4) === peg$
|
|
2128
|
-
s1 = peg$
|
|
2379
|
+
if (input.substr(peg$currPos, 4) === peg$c32) {
|
|
2380
|
+
s1 = peg$c32;
|
|
2129
2381
|
peg$currPos += 4;
|
|
2130
2382
|
} else {
|
|
2131
2383
|
s1 = peg$FAILED;
|
|
2132
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2384
|
+
if (peg$silentFails === 0) { peg$fail(peg$e43); }
|
|
2133
2385
|
}
|
|
2134
2386
|
if (s1 === peg$FAILED) {
|
|
2135
|
-
if (input.substr(peg$currPos, 5) === peg$
|
|
2136
|
-
s1 = peg$
|
|
2387
|
+
if (input.substr(peg$currPos, 5) === peg$c33) {
|
|
2388
|
+
s1 = peg$c33;
|
|
2137
2389
|
peg$currPos += 5;
|
|
2138
2390
|
} else {
|
|
2139
2391
|
s1 = peg$FAILED;
|
|
2140
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2392
|
+
if (peg$silentFails === 0) { peg$fail(peg$e44); }
|
|
2141
2393
|
}
|
|
2142
2394
|
}
|
|
2143
2395
|
if (s1 !== peg$FAILED) {
|
|
2144
2396
|
peg$savedPos = s0;
|
|
2145
|
-
s1 = peg$
|
|
2397
|
+
s1 = peg$f34();
|
|
2146
2398
|
}
|
|
2147
2399
|
s0 = s1;
|
|
2148
2400
|
|
|
@@ -2177,7 +2429,7 @@ function peg$parse(input, options) {
|
|
|
2177
2429
|
}
|
|
2178
2430
|
if (s1 !== peg$FAILED) {
|
|
2179
2431
|
peg$savedPos = s0;
|
|
2180
|
-
s1 = peg$
|
|
2432
|
+
s1 = peg$f35();
|
|
2181
2433
|
}
|
|
2182
2434
|
s0 = s1;
|
|
2183
2435
|
|
|
@@ -2243,7 +2495,7 @@ function peg$parse(input, options) {
|
|
|
2243
2495
|
}
|
|
2244
2496
|
if (s3 !== peg$FAILED) {
|
|
2245
2497
|
peg$savedPos = s0;
|
|
2246
|
-
s0 = peg$
|
|
2498
|
+
s0 = peg$f36();
|
|
2247
2499
|
} else {
|
|
2248
2500
|
peg$currPos = s0;
|
|
2249
2501
|
s0 = peg$FAILED;
|
|
@@ -2264,16 +2516,16 @@ function peg$parse(input, options) {
|
|
|
2264
2516
|
var s0, s1;
|
|
2265
2517
|
|
|
2266
2518
|
s0 = peg$currPos;
|
|
2267
|
-
if (input.substr(peg$currPos, 4) === peg$
|
|
2268
|
-
s1 = peg$
|
|
2519
|
+
if (input.substr(peg$currPos, 4) === peg$c34) {
|
|
2520
|
+
s1 = peg$c34;
|
|
2269
2521
|
peg$currPos += 4;
|
|
2270
2522
|
} else {
|
|
2271
2523
|
s1 = peg$FAILED;
|
|
2272
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2524
|
+
if (peg$silentFails === 0) { peg$fail(peg$e45); }
|
|
2273
2525
|
}
|
|
2274
2526
|
if (s1 !== peg$FAILED) {
|
|
2275
2527
|
peg$savedPos = s0;
|
|
2276
|
-
s1 = peg$
|
|
2528
|
+
s1 = peg$f37();
|
|
2277
2529
|
}
|
|
2278
2530
|
s0 = s1;
|
|
2279
2531
|
|
|
@@ -2284,11 +2536,11 @@ function peg$parse(input, options) {
|
|
|
2284
2536
|
var s0;
|
|
2285
2537
|
|
|
2286
2538
|
s0 = input.charAt(peg$currPos);
|
|
2287
|
-
if (peg$
|
|
2539
|
+
if (peg$r11.test(s0)) {
|
|
2288
2540
|
peg$currPos++;
|
|
2289
2541
|
} else {
|
|
2290
2542
|
s0 = peg$FAILED;
|
|
2291
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2543
|
+
if (peg$silentFails === 0) { peg$fail(peg$e46); }
|
|
2292
2544
|
}
|
|
2293
2545
|
|
|
2294
2546
|
return s0;
|
|
@@ -2298,12 +2550,12 @@ function peg$parse(input, options) {
|
|
|
2298
2550
|
var s0, s1, s2, s3;
|
|
2299
2551
|
|
|
2300
2552
|
s0 = peg$currPos;
|
|
2301
|
-
if (input.substr(peg$currPos, 2) === peg$
|
|
2302
|
-
s1 = peg$
|
|
2553
|
+
if (input.substr(peg$currPos, 2) === peg$c35) {
|
|
2554
|
+
s1 = peg$c35;
|
|
2303
2555
|
peg$currPos += 2;
|
|
2304
2556
|
} else {
|
|
2305
2557
|
s1 = peg$FAILED;
|
|
2306
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2558
|
+
if (peg$silentFails === 0) { peg$fail(peg$e47); }
|
|
2307
2559
|
}
|
|
2308
2560
|
if (s1 !== peg$FAILED) {
|
|
2309
2561
|
s2 = peg$currPos;
|
|
@@ -2335,12 +2587,12 @@ function peg$parse(input, options) {
|
|
|
2335
2587
|
var s0, s1, s2, s3;
|
|
2336
2588
|
|
|
2337
2589
|
s0 = peg$currPos;
|
|
2338
|
-
if (input.substr(peg$currPos, 3) === peg$
|
|
2339
|
-
s1 = peg$
|
|
2590
|
+
if (input.substr(peg$currPos, 3) === peg$c36) {
|
|
2591
|
+
s1 = peg$c36;
|
|
2340
2592
|
peg$currPos += 3;
|
|
2341
2593
|
} else {
|
|
2342
2594
|
s1 = peg$FAILED;
|
|
2343
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2595
|
+
if (peg$silentFails === 0) { peg$fail(peg$e48); }
|
|
2344
2596
|
}
|
|
2345
2597
|
if (s1 !== peg$FAILED) {
|
|
2346
2598
|
s2 = peg$currPos;
|
|
@@ -2372,12 +2624,12 @@ function peg$parse(input, options) {
|
|
|
2372
2624
|
var s0, s1, s2, s3;
|
|
2373
2625
|
|
|
2374
2626
|
s0 = peg$currPos;
|
|
2375
|
-
if (input.substr(peg$currPos, 3) === peg$
|
|
2376
|
-
s1 = peg$
|
|
2627
|
+
if (input.substr(peg$currPos, 3) === peg$c37) {
|
|
2628
|
+
s1 = peg$c37;
|
|
2377
2629
|
peg$currPos += 3;
|
|
2378
2630
|
} else {
|
|
2379
2631
|
s1 = peg$FAILED;
|
|
2380
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2632
|
+
if (peg$silentFails === 0) { peg$fail(peg$e49); }
|
|
2381
2633
|
}
|
|
2382
2634
|
if (s1 !== peg$FAILED) {
|
|
2383
2635
|
s2 = peg$currPos;
|
|
@@ -2417,11 +2669,11 @@ function peg$parse(input, options) {
|
|
|
2417
2669
|
s2 = peg$parsewhite();
|
|
2418
2670
|
}
|
|
2419
2671
|
peg$savedPos = s0;
|
|
2420
|
-
s1 = peg$
|
|
2672
|
+
s1 = peg$f38();
|
|
2421
2673
|
s0 = s1;
|
|
2422
2674
|
peg$silentFails--;
|
|
2423
2675
|
s1 = peg$FAILED;
|
|
2424
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2676
|
+
if (peg$silentFails === 0) { peg$fail(peg$e50); }
|
|
2425
2677
|
|
|
2426
2678
|
return s0;
|
|
2427
2679
|
}
|
|
@@ -2443,13 +2695,13 @@ function peg$parse(input, options) {
|
|
|
2443
2695
|
}
|
|
2444
2696
|
if (s1 !== peg$FAILED) {
|
|
2445
2697
|
peg$savedPos = s0;
|
|
2446
|
-
s1 = peg$
|
|
2698
|
+
s1 = peg$f39();
|
|
2447
2699
|
}
|
|
2448
2700
|
s0 = s1;
|
|
2449
2701
|
peg$silentFails--;
|
|
2450
2702
|
if (s0 === peg$FAILED) {
|
|
2451
2703
|
s1 = peg$FAILED;
|
|
2452
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2704
|
+
if (peg$silentFails === 0) { peg$fail(peg$e50); }
|
|
2453
2705
|
}
|
|
2454
2706
|
|
|
2455
2707
|
return s0;
|
|
@@ -2459,11 +2711,11 @@ function peg$parse(input, options) {
|
|
|
2459
2711
|
var s0;
|
|
2460
2712
|
|
|
2461
2713
|
s0 = input.charAt(peg$currPos);
|
|
2462
|
-
if (peg$
|
|
2714
|
+
if (peg$r12.test(s0)) {
|
|
2463
2715
|
peg$currPos++;
|
|
2464
2716
|
} else {
|
|
2465
2717
|
s0 = peg$FAILED;
|
|
2466
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2718
|
+
if (peg$silentFails === 0) { peg$fail(peg$e51); }
|
|
2467
2719
|
}
|
|
2468
2720
|
|
|
2469
2721
|
return s0;
|
|
@@ -2479,7 +2731,7 @@ function peg$parse(input, options) {
|
|
|
2479
2731
|
peg$currPos++;
|
|
2480
2732
|
} else {
|
|
2481
2733
|
s1 = peg$FAILED;
|
|
2482
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
2734
|
+
if (peg$silentFails === 0) { peg$fail(peg$e52); }
|
|
2483
2735
|
}
|
|
2484
2736
|
peg$silentFails--;
|
|
2485
2737
|
if (s1 === peg$FAILED) {
|
|
@@ -2494,7 +2746,7 @@ function peg$parse(input, options) {
|
|
|
2494
2746
|
|
|
2495
2747
|
|
|
2496
2748
|
const OPERATORS = {
|
|
2497
|
-
":": "
|
|
2749
|
+
":": "match",
|
|
2498
2750
|
":=": "eq",
|
|
2499
2751
|
":!=": "ne",
|
|
2500
2752
|
":>": "gt",
|
package/src/search/parser.peggy
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
/*
|
|
2
2
|
Grammar for advance search query
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
grammar: https://github.com/wenerme/wener/blob/master/notes/languages/parser/peg/advance-search.peggy
|
|
5
|
+
js: https://github.com/wenerme/wode/tree/main/packages/wener-common
|
|
6
|
+
playground: https://peggyjs.org/online
|
|
5
7
|
================================
|
|
6
8
|
|
|
9
|
+
- Github search
|
|
10
|
+
- Google search like
|
|
11
|
+
|
|
12
|
+
MAYBE date(createdAt):>2024-01-01
|
|
13
|
+
BUT createdAt:2024-01-01..*
|
|
14
|
+
|
|
15
|
+
MAYBE createdAt:now-7d..now
|
|
16
|
+
|
|
17
|
+
single quote string
|
|
18
|
+
MAYBE @HELLO:'HI'
|
|
19
|
+
|
|
20
|
+
MAYBE field.*, field.0
|
|
21
|
+
|
|
22
|
+
Examples
|
|
23
|
+
==========
|
|
7
24
|
ok OR yes AND NO AND NO
|
|
8
25
|
QUALIFIER.a:@me is:yes AND yes HELLO WORLD
|
|
9
26
|
start:>2019-09-12T12:20:30.123+08:00
|
|
@@ -21,7 +38,7 @@ owner:!=@me
|
|
|
21
38
|
|
|
22
39
|
{
|
|
23
40
|
const OPERATORS = {
|
|
24
|
-
":": "
|
|
41
|
+
":": "match",
|
|
25
42
|
":=": "eq",
|
|
26
43
|
":!=": "ne",
|
|
27
44
|
":>": "gt",
|
|
@@ -94,7 +111,7 @@ ComparisonExpr
|
|
|
94
111
|
return {
|
|
95
112
|
type: "compare",
|
|
96
113
|
field,
|
|
97
|
-
operator: "
|
|
114
|
+
operator: "match",
|
|
98
115
|
value: { value },
|
|
99
116
|
mention: true,
|
|
100
117
|
};
|
|
@@ -116,10 +133,6 @@ KeywordExpr
|
|
|
116
133
|
|
|
117
134
|
keyword = [^-+,'" \r\n\t()] [^ \r\n\t)]* { return text(); }
|
|
118
135
|
|
|
119
|
-
// support field,
|
|
120
|
-
// support field.key
|
|
121
|
-
// MAYBE field.*, field.0
|
|
122
|
-
// MAYBE date(field)
|
|
123
136
|
field = $ident|1.., "."|
|
|
124
137
|
|
|
125
138
|
range
|
|
@@ -176,8 +189,28 @@ literal
|
|
|
176
189
|
|
|
177
190
|
number = ([0-9]+ ("." [0-9]+)? / "." [0-9]+) { return parseFloat(text()); }
|
|
178
191
|
|
|
179
|
-
|
|
180
|
-
|
|
192
|
+
string = "\"" v:single_char* "\"" { return v.join(""); }
|
|
193
|
+
|
|
194
|
+
single_char
|
|
195
|
+
= [^"\\\0-\x1F\x7f]
|
|
196
|
+
/ escape_char
|
|
197
|
+
|
|
198
|
+
escape_char
|
|
199
|
+
= "\\'" { return "'"; }
|
|
200
|
+
/ "\\\"" { return '"'; }
|
|
201
|
+
/ "\\\\" { return "\\"; }
|
|
202
|
+
/ "\\/" { return "/"; }
|
|
203
|
+
/ "\\b" { return "\b"; }
|
|
204
|
+
/ "\\f" { return "\f"; }
|
|
205
|
+
/ "\\n" { return "\n"; }
|
|
206
|
+
/ "\\r" { return "\r"; }
|
|
207
|
+
/ "\\t" { return "\t"; }
|
|
208
|
+
/ "''" { return "'"; }
|
|
209
|
+
/ "\\u" h1:hex_digit h2:hex_digit h3:hex_digit h4:hex_digit {
|
|
210
|
+
return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
hex_digit = [0-9a-fA-F]
|
|
181
214
|
|
|
182
215
|
bool = ("true" / "false") { return text().toLowerCase() === "true"; }
|
|
183
216
|
|
package/src/search/types.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export type CompareCondition = {
|
|
|
42
42
|
* mention value for eq, ne only
|
|
43
43
|
* range require range value
|
|
44
44
|
*/
|
|
45
|
-
operator: 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'range' | '
|
|
45
|
+
operator: 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'range' | 'match';
|
|
46
46
|
negative?: boolean;
|
|
47
47
|
mention?: boolean;
|
|
48
48
|
value: Value;
|