tarsec 0.0.14 → 0.0.16
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/README.md +5 -1
- package/dist/combinators/seq.js +1 -12
- package/dist/combinators.d.ts +39 -5
- package/dist/combinators.js +640 -600
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -30
- package/dist/parsers/within.d.ts +1 -1
- package/dist/parsers/within.js +31 -45
- package/dist/parsers.d.ts +132 -2
- package/dist/parsers.js +329 -168
- package/dist/trace.d.ts +8 -1
- package/dist/trace.js +177 -180
- package/dist/types.d.ts +43 -15
- package/dist/types.js +57 -59
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +53 -66
- package/package.json +2 -1
package/dist/utils.js
CHANGED
|
@@ -1,70 +1,57 @@
|
|
|
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
|
-
|
|
1
|
+
export function escape(str) {
|
|
2
|
+
return JSON.stringify(str);
|
|
3
|
+
}
|
|
4
|
+
export function merge(a, b) {
|
|
5
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
6
|
+
return [...a, ...b];
|
|
7
|
+
}
|
|
8
|
+
else if (Array.isArray(a)) {
|
|
9
|
+
return [...a, b];
|
|
10
|
+
}
|
|
11
|
+
else if (Array.isArray(b)) {
|
|
12
|
+
return [a, ...b];
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return [a, b];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function mergeCaptures(a, b) {
|
|
19
|
+
const result = {};
|
|
20
|
+
Object.keys(a).forEach((key) => {
|
|
21
|
+
result[key] = a[key];
|
|
22
|
+
});
|
|
23
|
+
Object.keys(b).forEach((key) => {
|
|
24
|
+
if (result[key]) {
|
|
25
|
+
result[key] = merge(result[key], b[key]);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.merge = merge;
|
|
32
|
-
function mergeCaptures(a, b) {
|
|
33
|
-
const result = {};
|
|
34
|
-
Object.keys(a).forEach((key) => {
|
|
35
|
-
result[key] = a[key];
|
|
36
|
-
});
|
|
37
|
-
Object.keys(b).forEach((key) => {
|
|
38
|
-
if (result[key]) {
|
|
39
|
-
result[key] = merge(result[key], b[key]);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
result[key] = b[key];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
exports.mergeCaptures = mergeCaptures;
|
|
48
|
-
function findAncestorWithNextParser(node, count = 0) {
|
|
49
|
-
if (node === null)
|
|
50
|
-
return [null, count];
|
|
51
|
-
if (!node.closed) {
|
|
52
|
-
return [node, count];
|
|
53
|
-
}
|
|
54
|
-
if (node.parent) {
|
|
55
|
-
return findAncestorWithNextParser(node.parent, count + 1);
|
|
28
|
+
result[key] = b[key];
|
|
56
29
|
}
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
export function findAncestorWithNextParser(node, count = 0) {
|
|
34
|
+
if (node === null)
|
|
57
35
|
return [null, count];
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
36
|
+
if (!node.closed) {
|
|
37
|
+
return [node, count];
|
|
38
|
+
}
|
|
39
|
+
if (node.parent) {
|
|
40
|
+
return findAncestorWithNextParser(node.parent, count + 1);
|
|
41
|
+
}
|
|
42
|
+
return [null, count];
|
|
43
|
+
}
|
|
44
|
+
export function popMany(arr, count) {
|
|
45
|
+
for (let i = 0; i < count; i++) {
|
|
46
|
+
arr.pop();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function round(num, places = 2) {
|
|
50
|
+
return Math.round(num * 10 ** places) / 10 ** places;
|
|
51
|
+
}
|
|
52
|
+
export function shorten(str, length = 250) {
|
|
53
|
+
if (str.length > length) {
|
|
54
|
+
return str.substring(0, length) + "...";
|
|
55
|
+
}
|
|
56
|
+
return str;
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tarsec",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "A parser combinator library for TypeScript, inspired by Parsec.",
|
|
5
5
|
"homepage": "https://github.com/egonSchiele/tarsec",
|
|
6
6
|
"scripts": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"require": "./dist/index.js"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
+
"type": "module",
|
|
24
25
|
"types": "./dist/index.d.ts",
|
|
25
26
|
"keywords": ["parser", "parser combinator", "parsec"],
|
|
26
27
|
"author": "",
|