@bablr/boot 0.6.3 → 0.7.1
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/index.js +37 -218
- package/lib/languages/cstml.js +86 -375
- package/lib/languages/instruction.js +84 -119
- package/lib/languages/json.js +243 -0
- package/lib/languages/regex.js +76 -52
- package/lib/languages/spamex.js +119 -82
- package/lib/match.js +13 -11
- package/lib/miniparser.js +101 -80
- package/lib/path.js +42 -18
- package/lib/utils.js +14 -100
- package/package.json +7 -24
- package/dist/cjs.bundle.cjs +0 -5141
- package/dist/esm.bundle.mjs +0 -5139
- package/lib/builders.js +0 -475
- package/lib/esm-entry.mjs +0 -3
- package/lib/print.js +0 -401
- package/shorthand.macro.js +0 -380
package/lib/path.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
language,
|
|
6
|
-
type,
|
|
7
|
-
attributes: {},
|
|
8
|
-
children: [],
|
|
9
|
-
properties: {},
|
|
10
|
-
};
|
|
11
|
-
};
|
|
1
|
+
import { buildReferenceTag } from '@bablr/agast-helpers/tree';
|
|
2
|
+
|
|
3
|
+
const { hasOwn, freeze } = Object;
|
|
4
|
+
const { isArray } = Array;
|
|
12
5
|
|
|
13
|
-
const
|
|
6
|
+
export const parsePath = (str) => {
|
|
7
|
+
const match = /^([a-zA-Z]+)(\[\])?(\+)?(\$)?$/.exec(str);
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
const name = stripPathBraces(str);
|
|
9
|
+
if (!match) throw new Error();
|
|
17
10
|
|
|
18
|
-
|
|
11
|
+
let flags = freeze({ expression: !!match[3], hasGap: !!match[4] });
|
|
19
12
|
|
|
20
|
-
return
|
|
13
|
+
return buildReferenceTag(match[1], !!match[2], flags);
|
|
21
14
|
};
|
|
22
15
|
|
|
23
|
-
class Path {
|
|
16
|
+
export class Path {
|
|
24
17
|
constructor(id, attributes, parent = null) {
|
|
25
18
|
this.id = id;
|
|
26
19
|
this.attributes = attributes;
|
|
@@ -54,4 +47,35 @@ class Path {
|
|
|
54
47
|
}
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
|
|
50
|
+
export class PathResolver {
|
|
51
|
+
constructor(node) {
|
|
52
|
+
this.node = node;
|
|
53
|
+
this.counters = {};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get(path) {
|
|
57
|
+
const { node, counters } = this;
|
|
58
|
+
|
|
59
|
+
const { isArray: pathIsArray, name } = path;
|
|
60
|
+
|
|
61
|
+
if (!hasOwn(node.properties, name)) {
|
|
62
|
+
throw new Error(`cannot resolve {path: ${name}}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let value = node.properties[name];
|
|
66
|
+
|
|
67
|
+
if (pathIsArray) {
|
|
68
|
+
if (!isArray(value)) {
|
|
69
|
+
throw new Error(`cannot resolve {path: ${name}}: not an array`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const counter = counters[name] ?? 0;
|
|
73
|
+
|
|
74
|
+
counters[name] = counter + 1;
|
|
75
|
+
|
|
76
|
+
value = value[counter];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
}
|
package/lib/utils.js
CHANGED
|
@@ -1,82 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const isString = require('iter-tools/methods/is-string');
|
|
1
|
+
import isArray from 'iter-tools/methods/is-array';
|
|
2
|
+
import isString from 'iter-tools/methods/is-string';
|
|
4
3
|
|
|
5
|
-
const {
|
|
6
|
-
const isSymbol = (value) => typeof value === 'symbol';
|
|
7
|
-
const isType = (value) => isString(value) || isSymbol(value);
|
|
8
|
-
const isRegex = (val) => val instanceof RegExp;
|
|
9
|
-
|
|
10
|
-
const objectEntries = (obj) => {
|
|
11
|
-
return {
|
|
12
|
-
*[Symbol.iterator]() {
|
|
13
|
-
for (let key in obj) if (hasOwn(obj, key)) yield [key, obj[key]];
|
|
14
|
-
const symTypes = getOwnPropertySymbols(obj);
|
|
15
|
-
for (const type of symTypes) {
|
|
16
|
-
yield [type, obj[type]];
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const explodeSubtypes = (aliases, exploded, types) => {
|
|
23
|
-
for (const type of types) {
|
|
24
|
-
const explodedTypes = aliases.get(type);
|
|
25
|
-
if (explodedTypes) {
|
|
26
|
-
for (const explodedType of explodedTypes) {
|
|
27
|
-
exploded.add(explodedType);
|
|
28
|
-
const subtypes = aliases.get(explodedType);
|
|
29
|
-
if (subtypes) {
|
|
30
|
-
explodeSubtypes(aliases, exploded, subtypes);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const buildCovers = (rawAliases) => {
|
|
38
|
-
const aliases = new Map();
|
|
39
|
-
|
|
40
|
-
for (const alias of objectEntries(rawAliases)) {
|
|
41
|
-
if (!isType(alias[0])) throw new Error('alias[0] key must be a string or symbol');
|
|
42
|
-
if (!isArray(alias[1])) throw new Error('alias[1] must be an array');
|
|
43
|
-
if (!every(isType, alias[1])) throw new Error('alias[1] values must be strings or symbols');
|
|
4
|
+
const { getPrototypeOf } = Object;
|
|
44
5
|
|
|
45
|
-
|
|
46
|
-
}
|
|
6
|
+
const isRegex = (val) => val instanceof RegExp;
|
|
47
7
|
|
|
48
|
-
|
|
49
|
-
|
|
8
|
+
export const buildId = (value) => {
|
|
9
|
+
if (isString(value)) {
|
|
10
|
+
const { 0: language, 1: type } = value.split(':');
|
|
11
|
+
return type ? { language, type } : { language: undefined, type: language };
|
|
12
|
+
} else {
|
|
13
|
+
return value;
|
|
50
14
|
}
|
|
51
|
-
|
|
52
|
-
return new Map(aliases);
|
|
53
15
|
};
|
|
54
16
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (!name) {
|
|
59
|
-
throw new Error();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (pathIsArray) {
|
|
63
|
-
if (!obj[name]) {
|
|
64
|
-
obj[name] = [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!isArray(obj[name])) throw new Error('bad array value');
|
|
68
|
-
|
|
69
|
-
obj[name].push(value);
|
|
70
|
-
} else {
|
|
71
|
-
if (hasOwn(obj, name)) {
|
|
72
|
-
throw new Error(`duplicate child name \`${name}\``);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
obj[name] = value;
|
|
76
|
-
}
|
|
17
|
+
export const id = (...args) => {
|
|
18
|
+
return buildId(String.raw(...args));
|
|
77
19
|
};
|
|
78
20
|
|
|
79
|
-
const resolveDependentLanguage = (language, name) => {
|
|
21
|
+
export const resolveDependentLanguage = (language, name) => {
|
|
80
22
|
if (name === undefined) {
|
|
81
23
|
return language;
|
|
82
24
|
}
|
|
@@ -90,32 +32,4 @@ const resolveDependentLanguage = (language, name) => {
|
|
|
90
32
|
return resolved;
|
|
91
33
|
};
|
|
92
34
|
|
|
93
|
-
|
|
94
|
-
const { language, type } = id;
|
|
95
|
-
return { language, type, children, properties, attributes, gap: undefined };
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const buildId = (value) => {
|
|
99
|
-
if (isString(value)) {
|
|
100
|
-
const { 0: language, 1: type } = value.split(':');
|
|
101
|
-
return type ? { language, type } : { language: undefined, type: language };
|
|
102
|
-
} else {
|
|
103
|
-
return value;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const id = (...args) => {
|
|
108
|
-
return buildId(String.raw(...args));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
module.exports = {
|
|
112
|
-
buildCovers,
|
|
113
|
-
set,
|
|
114
|
-
resolveDependentLanguage,
|
|
115
|
-
isArray,
|
|
116
|
-
isRegex,
|
|
117
|
-
getPrototypeOf,
|
|
118
|
-
buildNode,
|
|
119
|
-
buildId,
|
|
120
|
-
id,
|
|
121
|
-
};
|
|
35
|
+
export { isArray, isRegex, getPrototypeOf };
|
package/package.json
CHANGED
|
@@ -1,38 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/boot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Compile-time tools for bootstrapping BABLR VM",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12.0.0"
|
|
7
7
|
},
|
|
8
|
+
"type": "module",
|
|
8
9
|
"exports": {
|
|
9
|
-
".":
|
|
10
|
-
"require": "./dist/cjs.bundle.cjs",
|
|
11
|
-
"import": "./lib/esm-entry.mjs"
|
|
12
|
-
},
|
|
13
|
-
"./shorthand.macro": "./shorthand.macro.js"
|
|
10
|
+
".": "./lib/index.js"
|
|
14
11
|
},
|
|
15
12
|
"files": [
|
|
16
|
-
"dist/**/*.cjs",
|
|
17
|
-
"dist/**/*.mjs",
|
|
18
|
-
"lib/esm-entry.mjs",
|
|
19
13
|
"lib/**/*.js",
|
|
20
14
|
"shorthand.macro.js"
|
|
21
15
|
],
|
|
22
16
|
"sideEffects": false,
|
|
23
|
-
"scripts": {
|
|
24
|
-
"build": "rollup -c"
|
|
25
|
-
},
|
|
26
17
|
"dependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@babel/types": "7.23.0",
|
|
30
|
-
"@bablr/boot-helpers": "0.3.2",
|
|
18
|
+
"@bablr/agast-helpers": "0.6.1",
|
|
19
|
+
"@bablr/agast-vm-helpers": "0.6.0",
|
|
31
20
|
"@iter-tools/imm-stack": "1.1.0",
|
|
32
|
-
"escape-string-regexp": "
|
|
33
|
-
"iter-tools": "^7.5.3"
|
|
34
|
-
"jest-diff": "29.7.0",
|
|
35
|
-
"rollup": "^4.27.3"
|
|
21
|
+
"escape-string-regexp": "5.0.0",
|
|
22
|
+
"iter-tools": "^7.5.3"
|
|
36
23
|
},
|
|
37
24
|
"devDependencies": {
|
|
38
25
|
"@babel/cli": "^7.23.0",
|
|
@@ -40,16 +27,12 @@
|
|
|
40
27
|
"@babel/plugin-proposal-decorators": "^7.23.2",
|
|
41
28
|
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
42
29
|
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#a49dbe6861a82d96864ee89fbf0ec1844a8a5e8e",
|
|
43
|
-
"@rollup/plugin-commonjs": "^28.0.1",
|
|
44
|
-
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
45
30
|
"babel-plugin-macros": "^3.1.0",
|
|
46
31
|
"enhanced-resolve": "^5.12.0",
|
|
47
32
|
"eslint": "^8.47.0",
|
|
48
33
|
"eslint-import-resolver-enhanced-resolve": "^1.0.5",
|
|
49
34
|
"eslint-plugin-import": "^2.27.5",
|
|
50
35
|
"expect": "^29.6.2",
|
|
51
|
-
"install": "^0.13.0",
|
|
52
|
-
"npm": "^10.9.0",
|
|
53
36
|
"prettier": "^2.0.5"
|
|
54
37
|
},
|
|
55
38
|
"repository": "git@github.com:bablr-lang/boot.git",
|