@bablr/boot 0.6.1 → 0.6.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/dist/cjs.bundle.cjs +5141 -0
- package/dist/esm.bundle.mjs +5139 -0
- package/lib/esm-entry.mjs +3 -0
- package/lib/languages/cstml.js +93 -5
- package/lib/languages/instruction.js +19 -4
- package/lib/miniparser.js +14 -4
- package/lib/utils.js +1 -1
- package/package.json +16 -6
- package/lib/index.mjs +0 -17
package/lib/languages/cstml.js
CHANGED
|
@@ -7,6 +7,7 @@ const _ = /\s+/y;
|
|
|
7
7
|
const PN = 'Punctuator';
|
|
8
8
|
const ID = 'Identifier';
|
|
9
9
|
const KW = 'Keyword';
|
|
10
|
+
const LIT = 'Literal';
|
|
10
11
|
|
|
11
12
|
const name = 'CSTML';
|
|
12
13
|
|
|
@@ -79,10 +80,26 @@ const covers = buildCovers({
|
|
|
79
80
|
'Content',
|
|
80
81
|
'UnsignedInteger',
|
|
81
82
|
'Flags',
|
|
83
|
+
'Array',
|
|
84
|
+
'Object',
|
|
85
|
+
'Boolean',
|
|
86
|
+
'Null',
|
|
87
|
+
'Identifier',
|
|
88
|
+
'JSONProperty',
|
|
89
|
+
'JSONExpression',
|
|
82
90
|
],
|
|
83
91
|
[sym.fragment]: ['Attributes'],
|
|
84
92
|
Attribute: ['MappingAttribute', 'BooleanAttribute'],
|
|
85
|
-
|
|
93
|
+
JSONExpression: [
|
|
94
|
+
'Boolean',
|
|
95
|
+
'Null',
|
|
96
|
+
'Number',
|
|
97
|
+
'String',
|
|
98
|
+
'Array',
|
|
99
|
+
'Object',
|
|
100
|
+
'Identifier',
|
|
101
|
+
'Separator',
|
|
102
|
+
],
|
|
86
103
|
TagType: ['Identifier', 'GlobalIdentifier'],
|
|
87
104
|
Tag: ['LiteralTag', 'Trivia'],
|
|
88
105
|
PropertyValue: ['GapTag', 'Node', 'NullTag'],
|
|
@@ -318,15 +335,23 @@ const grammar = class CSTMLMiniparserGrammar {
|
|
|
318
335
|
p.eatMatchTrivia(_);
|
|
319
336
|
p.eat('=', PN, { path: 'mapToken' });
|
|
320
337
|
p.eatMatchTrivia(_);
|
|
321
|
-
p.eatProduction('
|
|
338
|
+
p.eatProduction('JSONExpression', { path: 'value' });
|
|
322
339
|
}
|
|
323
340
|
|
|
324
341
|
// @Cover
|
|
325
|
-
|
|
342
|
+
JSONExpression(p) {
|
|
326
343
|
if (p.match(/['"]/y)) {
|
|
327
344
|
p.eatProduction('String');
|
|
328
345
|
} else if (p.match(/[\d+-]/y)) {
|
|
329
346
|
p.eatProduction('Number');
|
|
347
|
+
} else if (p.match('[')) {
|
|
348
|
+
p.eatProduction('Array');
|
|
349
|
+
} else if (p.match('{')) {
|
|
350
|
+
p.eatProduction('Object');
|
|
351
|
+
} else if (p.match(/true|false/y)) {
|
|
352
|
+
p.eatProduction('Boolean');
|
|
353
|
+
} else if (p.match('null')) {
|
|
354
|
+
p.eatProduction('Null');
|
|
330
355
|
}
|
|
331
356
|
}
|
|
332
357
|
|
|
@@ -395,10 +420,73 @@ const grammar = class CSTMLMiniparserGrammar {
|
|
|
395
420
|
}
|
|
396
421
|
|
|
397
422
|
// @Node
|
|
398
|
-
|
|
399
|
-
p.
|
|
423
|
+
Array(p) {
|
|
424
|
+
p.eat('[', PN, { path: 'openToken', balanced: ']' });
|
|
425
|
+
|
|
426
|
+
p.eatMatchTrivia(_);
|
|
427
|
+
|
|
428
|
+
let first = true;
|
|
429
|
+
let sep;
|
|
430
|
+
while (first || (sep && (p.match(/./y) || p.atExpression))) {
|
|
431
|
+
p.eatProduction('JSONExpression', { path: 'elements[]' });
|
|
432
|
+
if (p.match(/\s*,?/y)) {
|
|
433
|
+
sep = p.eatProduction('Separator', { path: 'separators[]' });
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
first = false;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
p.eat(']', PN, { path: 'closeToken', balancer: true });
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// @Node
|
|
443
|
+
Object(p) {
|
|
444
|
+
p.eat('{', PN, { path: 'openToken', balanced: '}' });
|
|
445
|
+
|
|
446
|
+
p.eatMatchTrivia(_);
|
|
447
|
+
|
|
448
|
+
let first = true;
|
|
449
|
+
let sep;
|
|
450
|
+
while (first || (sep && (p.match(/./y) || p.atExpression))) {
|
|
451
|
+
p.eatProduction('JSONProperty', { path: 'properties[]' });
|
|
452
|
+
if (p.match(/\s*,?/y)) {
|
|
453
|
+
sep = p.eatProduction('Separator', { path: 'separators[]' });
|
|
454
|
+
}
|
|
455
|
+
first = false;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
p.eatMatchTrivia(_);
|
|
459
|
+
|
|
460
|
+
p.eat('}', PN, { path: 'closeToken', balancer: true });
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// @Node
|
|
464
|
+
JSONProperty(p) {
|
|
465
|
+
p.eat(/[a-zA-Z]+/y, LIT, { path: 'key' });
|
|
466
|
+
p.eatMatchTrivia(_);
|
|
467
|
+
p.eat(':', PN, { path: 'mapToken' });
|
|
468
|
+
p.eatMatchTrivia(_);
|
|
469
|
+
p.eatProduction('JSONExpression', { path: 'value' });
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// @Node
|
|
473
|
+
Boolean(p) {
|
|
474
|
+
p.eat(/true|false/y, KW, { path: 'sigilToken' });
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// @Node
|
|
478
|
+
Null(p) {
|
|
479
|
+
p.eat('null', KW, { path: 'sigilToken' });
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
//@Node
|
|
483
|
+
Separator(p) {
|
|
484
|
+
p.eatMatchTrivia(_);
|
|
485
|
+
p.eatMatch(/,/y, PN, { path: 'separators[]' });
|
|
486
|
+
p.eatMatchTrivia(_);
|
|
400
487
|
}
|
|
401
488
|
|
|
489
|
+
//@Node
|
|
402
490
|
Number(p) {
|
|
403
491
|
if (p.match(/-?\d/y)) {
|
|
404
492
|
p.eatProduction('Integer');
|
|
@@ -29,6 +29,7 @@ const covers = buildCovers({
|
|
|
29
29
|
'Boolean',
|
|
30
30
|
'Null',
|
|
31
31
|
'Spamex:Matcher',
|
|
32
|
+
'Separator',
|
|
32
33
|
],
|
|
33
34
|
});
|
|
34
35
|
|
|
@@ -75,7 +76,9 @@ const grammar = class InstructionMiniparserGrammar {
|
|
|
75
76
|
let sep;
|
|
76
77
|
while (first || (sep && (p.match(/./y) || p.atExpression))) {
|
|
77
78
|
p.eatProduction('Property', { path: 'properties[]' });
|
|
78
|
-
|
|
79
|
+
if (p.match(/\s*,?/y)) {
|
|
80
|
+
sep = p.eatProduction('Separator', { path: 'separators[]' });
|
|
81
|
+
}
|
|
79
82
|
first = false;
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -103,7 +106,10 @@ const grammar = class InstructionMiniparserGrammar {
|
|
|
103
106
|
let sep;
|
|
104
107
|
while (first || (sep && (p.match(/./y) || p.atExpression))) {
|
|
105
108
|
p.eatProduction('Expression', { path: 'elements[]' });
|
|
106
|
-
|
|
109
|
+
if (p.match(/\s*,?/y)) {
|
|
110
|
+
sep = p.eatProduction('Separator', { path: 'separators[]' });
|
|
111
|
+
}
|
|
112
|
+
|
|
107
113
|
first = false;
|
|
108
114
|
}
|
|
109
115
|
|
|
@@ -114,12 +120,14 @@ const grammar = class InstructionMiniparserGrammar {
|
|
|
114
120
|
Tuple(p) {
|
|
115
121
|
p.eat('(', PN, { path: 'openToken', balanced: ')' });
|
|
116
122
|
|
|
117
|
-
let sep
|
|
123
|
+
let sep;
|
|
118
124
|
|
|
119
125
|
let i = 0;
|
|
120
126
|
while (i === 0 || (sep && (p.match(/./y) || p.atExpression))) {
|
|
121
127
|
p.eatProduction('Expression', { path: 'values[]' });
|
|
122
|
-
|
|
128
|
+
if (p.match(/\s*,?/y)) {
|
|
129
|
+
sep = p.eatProduction('Separator', { path: 'separators[]' });
|
|
130
|
+
}
|
|
123
131
|
i++;
|
|
124
132
|
}
|
|
125
133
|
|
|
@@ -131,6 +139,13 @@ const grammar = class InstructionMiniparserGrammar {
|
|
|
131
139
|
p.eat(/true|false/y, KW, { path: 'sigilToken' });
|
|
132
140
|
}
|
|
133
141
|
|
|
142
|
+
//@Node
|
|
143
|
+
Separator(p) {
|
|
144
|
+
p.eatMatchTrivia(_);
|
|
145
|
+
p.eatMatch(/,/y, PN, { path: 'separators[]' });
|
|
146
|
+
p.eatMatchTrivia(_);
|
|
147
|
+
}
|
|
148
|
+
|
|
134
149
|
// @Node
|
|
135
150
|
Null(p) {
|
|
136
151
|
p.eat('null', KW, { path: 'sigilToken' });
|
package/lib/miniparser.js
CHANGED
|
@@ -9,6 +9,8 @@ const { parsePath } = require('./path.js');
|
|
|
9
9
|
const { set, isRegex, isArray, getPrototypeOf, buildNode } = require('./utils.js');
|
|
10
10
|
const { ReferenceTag, LiteralTag, Escape } = require('@bablr/boot-helpers/symbols');
|
|
11
11
|
|
|
12
|
+
const { hasOwn } = Object;
|
|
13
|
+
|
|
12
14
|
class TemplateParser {
|
|
13
15
|
constructor(rootLanguage, quasis, expressions) {
|
|
14
16
|
if (!quasis) throw new Error();
|
|
@@ -197,6 +199,10 @@ class TemplateParser {
|
|
|
197
199
|
this.spans.push({ type: 'Bare', guard: null });
|
|
198
200
|
}
|
|
199
201
|
|
|
202
|
+
if (!hasOwn(getPrototypeOf(grammar), type)) {
|
|
203
|
+
throw new Error(`Unknown production {type: ${type}}`);
|
|
204
|
+
}
|
|
205
|
+
|
|
200
206
|
const result = getPrototypeOf(grammar)[type].call(grammar, this, props);
|
|
201
207
|
|
|
202
208
|
if (isEmbedded) {
|
|
@@ -319,7 +325,7 @@ class TemplateParser {
|
|
|
319
325
|
|
|
320
326
|
const result = this.matchSticky(pattern, attrs, this);
|
|
321
327
|
|
|
322
|
-
if (!result)
|
|
328
|
+
if (!result) this.fail();
|
|
323
329
|
|
|
324
330
|
this.idx += result.length;
|
|
325
331
|
|
|
@@ -367,7 +373,7 @@ class TemplateParser {
|
|
|
367
373
|
eatTrivia(pattern) {
|
|
368
374
|
const result = this.matchSticky(pattern, {}, this);
|
|
369
375
|
|
|
370
|
-
if (!result)
|
|
376
|
+
if (!result) this.fail();
|
|
371
377
|
|
|
372
378
|
this.idx += result.length;
|
|
373
379
|
|
|
@@ -391,7 +397,7 @@ class TemplateParser {
|
|
|
391
397
|
eatEscape(pattern) {
|
|
392
398
|
const result = this.matchSticky(pattern, {}, this);
|
|
393
399
|
|
|
394
|
-
if (!result)
|
|
400
|
+
if (!result) this.fail();
|
|
395
401
|
|
|
396
402
|
this.idx += result.length;
|
|
397
403
|
|
|
@@ -415,7 +421,7 @@ class TemplateParser {
|
|
|
415
421
|
eatLiteral(pattern) {
|
|
416
422
|
const result = this.matchSticky(pattern, {}, this);
|
|
417
423
|
|
|
418
|
-
if (!result)
|
|
424
|
+
if (!result) this.fail();
|
|
419
425
|
|
|
420
426
|
this.idx += result.length;
|
|
421
427
|
|
|
@@ -451,6 +457,10 @@ class TemplateParser {
|
|
|
451
457
|
this.spans.pop();
|
|
452
458
|
this.spans.push(span);
|
|
453
459
|
}
|
|
460
|
+
|
|
461
|
+
fail() {
|
|
462
|
+
throw new Error(`miniparser: parsing \`${this.quasis}\` failed`);
|
|
463
|
+
}
|
|
454
464
|
}
|
|
455
465
|
|
|
456
466
|
module.exports = { TemplateParser };
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/boot",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Compile-time tools for bootstrapping BABLR VM",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12.0.0"
|
|
7
7
|
},
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"require": "./
|
|
11
|
-
"import": "./lib/
|
|
10
|
+
"require": "./dist/cjs.bundle.cjs",
|
|
11
|
+
"import": "./lib/esm-entry.mjs"
|
|
12
12
|
},
|
|
13
13
|
"./shorthand.macro": "./shorthand.macro.js"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
+
"dist/**/*.cjs",
|
|
17
|
+
"dist/**/*.mjs",
|
|
18
|
+
"lib/esm-entry.mjs",
|
|
16
19
|
"lib/**/*.js",
|
|
17
|
-
"lib/**/*.mjs",
|
|
18
20
|
"shorthand.macro.js"
|
|
19
21
|
],
|
|
20
22
|
"sideEffects": false,
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "rollup -c"
|
|
25
|
+
},
|
|
21
26
|
"dependencies": {
|
|
22
27
|
"@babel/helper-module-imports": "^7.22.15",
|
|
23
28
|
"@babel/template": "^7.22.15",
|
|
24
29
|
"@babel/types": "7.23.0",
|
|
25
|
-
"@bablr/boot-helpers": "0.3.
|
|
30
|
+
"@bablr/boot-helpers": "0.3.2",
|
|
26
31
|
"@iter-tools/imm-stack": "1.1.0",
|
|
27
32
|
"escape-string-regexp": "4.0.0",
|
|
28
33
|
"iter-tools": "^7.5.3",
|
|
29
|
-
"jest-diff": "29.7.0"
|
|
34
|
+
"jest-diff": "29.7.0",
|
|
35
|
+
"rollup": "^4.27.3"
|
|
30
36
|
},
|
|
31
37
|
"devDependencies": {
|
|
32
38
|
"@babel/cli": "^7.23.0",
|
|
@@ -34,12 +40,16 @@
|
|
|
34
40
|
"@babel/plugin-proposal-decorators": "^7.23.2",
|
|
35
41
|
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
36
42
|
"@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",
|
|
37
45
|
"babel-plugin-macros": "^3.1.0",
|
|
38
46
|
"enhanced-resolve": "^5.12.0",
|
|
39
47
|
"eslint": "^8.47.0",
|
|
40
48
|
"eslint-import-resolver-enhanced-resolve": "^1.0.5",
|
|
41
49
|
"eslint-plugin-import": "^2.27.5",
|
|
42
50
|
"expect": "^29.6.2",
|
|
51
|
+
"install": "^0.13.0",
|
|
52
|
+
"npm": "^10.9.0",
|
|
43
53
|
"prettier": "^2.0.5"
|
|
44
54
|
},
|
|
45
55
|
"repository": "git@github.com:bablr-lang/boot.git",
|