@gmb/bitmark-parser-generator 3.38.0 → 4.0.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/dist/browser/bitmark-parser-generator.min.js +1 -1
- package/dist/browser/bundle-report.html +2 -2
- package/dist/browser/cjs/index.cjs +61 -56
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +24 -8
- package/dist/browser/esm/index.d.ts +24 -8
- package/dist/browser/esm/index.js +61 -56
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/index.cjs +245 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -8
- package/dist/index.d.ts +24 -8
- package/dist/index.js +243 -118
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1522,12 +1522,12 @@ var StringUtils = class {
|
|
|
1522
1522
|
subLength = width;
|
|
1523
1523
|
rangeStartNext = rangeStart + width;
|
|
1524
1524
|
}
|
|
1525
|
-
subString = str.
|
|
1525
|
+
subString = str.slice(rangeStart, rangeStart + subLength);
|
|
1526
1526
|
rangeStart = rangeStartNext;
|
|
1527
1527
|
result.push(subString.trim());
|
|
1528
1528
|
}
|
|
1529
1529
|
if (rangeStart < len) {
|
|
1530
|
-
subString = str.
|
|
1530
|
+
subString = str.slice(rangeStart);
|
|
1531
1531
|
result.push(subString);
|
|
1532
1532
|
}
|
|
1533
1533
|
return result;
|
|
@@ -1539,6 +1539,7 @@ var StringUtils = class {
|
|
|
1539
1539
|
* @returns the camelCase version of the string
|
|
1540
1540
|
*/
|
|
1541
1541
|
kebabToCamel(str) {
|
|
1542
|
+
if (!str) return str;
|
|
1542
1543
|
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
1543
1544
|
}
|
|
1544
1545
|
};
|
|
@@ -1694,13 +1695,13 @@ var ObjectUtils = class {
|
|
|
1694
1695
|
* @param path the path to the property to set as a dotted string or array or a mix of both
|
|
1695
1696
|
* @returns the value of the property, or undefined if the property does not exist
|
|
1696
1697
|
*/
|
|
1697
|
-
getViaPath(obj,
|
|
1698
|
+
getViaPath(obj, path5) {
|
|
1698
1699
|
if (!obj) return void 0;
|
|
1699
|
-
if (!
|
|
1700
|
-
if (!Array.isArray(
|
|
1701
|
-
|
|
1700
|
+
if (!path5) return void 0;
|
|
1701
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1702
|
+
path5 = path5.flatMap((p) => p.split("."));
|
|
1702
1703
|
let node = obj;
|
|
1703
|
-
for (const key of
|
|
1704
|
+
for (const key of path5) {
|
|
1704
1705
|
if (node == null) return void 0;
|
|
1705
1706
|
node = node[key];
|
|
1706
1707
|
}
|
|
@@ -1716,14 +1717,14 @@ var ObjectUtils = class {
|
|
|
1716
1717
|
* @param create - if true, create plain objects in the path if they do not exist
|
|
1717
1718
|
* @returns true if the value was set, false if the value was not set
|
|
1718
1719
|
*/
|
|
1719
|
-
setViaPath(obj,
|
|
1720
|
+
setViaPath(obj, path5, value, create) {
|
|
1720
1721
|
if (!obj) return false;
|
|
1721
|
-
if (!
|
|
1722
|
-
if (!Array.isArray(
|
|
1723
|
-
|
|
1722
|
+
if (!path5) return false;
|
|
1723
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1724
|
+
path5 = path5.flatMap((p) => p.split("."));
|
|
1724
1725
|
let node = obj;
|
|
1725
|
-
for (let i = 0; i <
|
|
1726
|
-
const key =
|
|
1726
|
+
for (let i = 0; i < path5.length - 1; i++) {
|
|
1727
|
+
const key = path5[i];
|
|
1727
1728
|
if (node[key] == void 0) {
|
|
1728
1729
|
if (create) {
|
|
1729
1730
|
node[key] = {};
|
|
@@ -1733,7 +1734,7 @@ var ObjectUtils = class {
|
|
|
1733
1734
|
}
|
|
1734
1735
|
node = node[key];
|
|
1735
1736
|
}
|
|
1736
|
-
node[
|
|
1737
|
+
node[path5[path5.length - 1]] = value;
|
|
1737
1738
|
return true;
|
|
1738
1739
|
}
|
|
1739
1740
|
/**
|
|
@@ -1780,19 +1781,19 @@ var ObjectUtils = class {
|
|
|
1780
1781
|
* @param path
|
|
1781
1782
|
* @returns
|
|
1782
1783
|
*/
|
|
1783
|
-
flatMapPath(obj,
|
|
1784
|
+
flatMapPath(obj, path5) {
|
|
1784
1785
|
if (!obj) return [];
|
|
1785
|
-
if (!
|
|
1786
|
-
if (!Array.isArray(
|
|
1786
|
+
if (!path5) return [];
|
|
1787
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1787
1788
|
const node = obj;
|
|
1788
|
-
const key =
|
|
1789
|
+
const key = path5.shift();
|
|
1789
1790
|
if (key == null) return node;
|
|
1790
1791
|
const data = node[key];
|
|
1791
1792
|
if (!data) return [];
|
|
1792
1793
|
if (Array.isArray(data)) {
|
|
1793
|
-
return data.flatMap((d) => this.flatMapPath(d,
|
|
1794
|
+
return data.flatMap((d) => this.flatMapPath(d, path5.slice()));
|
|
1794
1795
|
} else {
|
|
1795
|
-
return [this.flatMapPath(data,
|
|
1796
|
+
return [this.flatMapPath(data, path5)].flat();
|
|
1796
1797
|
}
|
|
1797
1798
|
}
|
|
1798
1799
|
// testFlatMapPath() {
|
|
@@ -8938,7 +8939,7 @@ var instance2 = new Config();
|
|
|
8938
8939
|
// src/generated/package_info.ts
|
|
8939
8940
|
var PACKAGE_INFO = {
|
|
8940
8941
|
"name": "@gmb/bitmark-parser-generator",
|
|
8941
|
-
"version": "
|
|
8942
|
+
"version": "4.0.1",
|
|
8942
8943
|
"author": "Get More Brain Ltd",
|
|
8943
8944
|
"license": "ISC",
|
|
8944
8945
|
"description": "A bitmark parser and generator using Peggy.js"
|
|
@@ -20704,8 +20705,10 @@ var NodeValidator = class {
|
|
|
20704
20705
|
if (!valid) {
|
|
20705
20706
|
if (resource.type) {
|
|
20706
20707
|
ret = {
|
|
20707
|
-
type: resource.type
|
|
20708
|
-
|
|
20708
|
+
type: resource.type,
|
|
20709
|
+
__typeAlias: resource.type,
|
|
20710
|
+
__configKey: resource.__configKey,
|
|
20711
|
+
__invalid: true
|
|
20709
20712
|
};
|
|
20710
20713
|
}
|
|
20711
20714
|
}
|
|
@@ -24183,14 +24186,14 @@ var Builder = class extends BaseBuilder {
|
|
|
24183
24186
|
* @param path path for the value
|
|
24184
24187
|
* @param value the value to push down
|
|
24185
24188
|
*/
|
|
24186
|
-
pushDownTree(_context, body, bodyBitTypes, cardNode, cardNodePath,
|
|
24189
|
+
pushDownTree(_context, body, bodyBitTypes, cardNode, cardNodePath, path5, value) {
|
|
24187
24190
|
if (value === void 0) return;
|
|
24188
24191
|
if (cardNode && cardNodePath) {
|
|
24189
24192
|
if (!Array.isArray(cardNodePath)) cardNodePath = [cardNodePath];
|
|
24190
24193
|
const data = objectUtils.flatMapPath(cardNode, cardNodePath);
|
|
24191
24194
|
for (const d of data) {
|
|
24192
|
-
if (d[
|
|
24193
|
-
d[
|
|
24195
|
+
if (d[path5] == null) {
|
|
24196
|
+
d[path5] = value;
|
|
24194
24197
|
}
|
|
24195
24198
|
}
|
|
24196
24199
|
}
|
|
@@ -24204,8 +24207,8 @@ var Builder = class extends BaseBuilder {
|
|
|
24204
24207
|
if (part) {
|
|
24205
24208
|
if (bodyBitTypes.indexOf(part.type) !== -1) {
|
|
24206
24209
|
const data = part;
|
|
24207
|
-
if (data[
|
|
24208
|
-
data[
|
|
24210
|
+
if (data[path5] == null) {
|
|
24211
|
+
data[path5] = value;
|
|
24209
24212
|
}
|
|
24210
24213
|
}
|
|
24211
24214
|
}
|
|
@@ -24398,13 +24401,14 @@ var StringWriter = class {
|
|
|
24398
24401
|
}
|
|
24399
24402
|
writeLine(value) {
|
|
24400
24403
|
if (!this._buffer) return this;
|
|
24404
|
+
let line;
|
|
24401
24405
|
if (value != null) {
|
|
24402
|
-
|
|
24403
|
-
this.lastWrite = value + this.endOfLineString;
|
|
24406
|
+
line = value + this.endOfLineString;
|
|
24404
24407
|
} else {
|
|
24405
|
-
this.
|
|
24406
|
-
this.lastWrite = this.endOfLineString;
|
|
24408
|
+
line = this.endOfLineString;
|
|
24407
24409
|
}
|
|
24410
|
+
this._buffer.push(line);
|
|
24411
|
+
this.lastWrite = line;
|
|
24408
24412
|
return this;
|
|
24409
24413
|
}
|
|
24410
24414
|
writeLines(values, delimiter) {
|
|
@@ -26692,6 +26696,7 @@ var JsonGenerator = class extends AstWalkerGenerator {
|
|
|
26692
26696
|
this.resetState();
|
|
26693
26697
|
this.writer.openSync();
|
|
26694
26698
|
this.walkAndWrite(ast);
|
|
26699
|
+
this.write(JSON.stringify(this.json, null, this.jsonPrettifySpace));
|
|
26695
26700
|
this.writer.closeSync();
|
|
26696
26701
|
}
|
|
26697
26702
|
resetState() {
|
|
@@ -31246,7 +31251,8 @@ function buildResources(context, resourceTypeAttachment, resources) {
|
|
|
31246
31251
|
const countsMax = resourcesConfig.getCountsMax();
|
|
31247
31252
|
if (resources) {
|
|
31248
31253
|
for (const r of resources.reverse()) {
|
|
31249
|
-
|
|
31254
|
+
if (r.__invalid) continue;
|
|
31255
|
+
const configKey = r.__configKey;
|
|
31250
31256
|
let countMin = countsMin.get(configKey) ?? 0;
|
|
31251
31257
|
let countMax = countsMax.get(configKey) ?? 0;
|
|
31252
31258
|
countMin = Math.max(0, countMin - 1);
|
|
@@ -31267,7 +31273,7 @@ function buildResources(context, resourceTypeAttachment, resources) {
|
|
|
31267
31273
|
context.addWarning(warningMsg);
|
|
31268
31274
|
} else if (filteredResources.length === 0 && resourceTypeAttachment) {
|
|
31269
31275
|
context.addWarning(
|
|
31270
|
-
`Resource type [&${resourceTypeAttachment}] is specified in the bit header, but no such
|
|
31276
|
+
`Resource type [&${resourceTypeAttachment}] is specified in the bit header, but no such resource is present`
|
|
31271
31277
|
);
|
|
31272
31278
|
}
|
|
31273
31279
|
if (excessResources.length > 0) {
|
|
@@ -35118,8 +35124,8 @@ var BitmarkParser = class {
|
|
|
35118
35124
|
};
|
|
35119
35125
|
|
|
35120
35126
|
// src/BitmarkParserGenerator.ts
|
|
35121
|
-
var
|
|
35122
|
-
var
|
|
35127
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
35128
|
+
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
35123
35129
|
|
|
35124
35130
|
// src/ast/writer/FileWriter.ts
|
|
35125
35131
|
var import_node_path = __toESM(require("path"), 1);
|
|
@@ -35207,13 +35213,13 @@ var FileWriter = class extends StreamWriter {
|
|
|
35207
35213
|
* @param path - path of file to write
|
|
35208
35214
|
* @param options - options for file writing
|
|
35209
35215
|
*/
|
|
35210
|
-
constructor(
|
|
35216
|
+
constructor(path5, options) {
|
|
35211
35217
|
super();
|
|
35212
35218
|
__publicField(this, "_path");
|
|
35213
35219
|
__publicField(this, "_append");
|
|
35214
35220
|
__publicField(this, "_encoding");
|
|
35215
35221
|
const opts = Object.assign({}, options);
|
|
35216
|
-
this._path =
|
|
35222
|
+
this._path = path5;
|
|
35217
35223
|
this._append = !!opts.append;
|
|
35218
35224
|
this._encoding = opts.encoding ?? "utf8";
|
|
35219
35225
|
}
|
|
@@ -35260,7 +35266,119 @@ var FileWriter = class extends StreamWriter {
|
|
|
35260
35266
|
};
|
|
35261
35267
|
|
|
35262
35268
|
// src/generator/bitmark/BitmarkFileGenerator.ts
|
|
35263
|
-
var
|
|
35269
|
+
var import_fs_extra3 = require("fs-extra");
|
|
35270
|
+
|
|
35271
|
+
// src/ast/writer/SyncFileWriter.ts
|
|
35272
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
35273
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
35274
|
+
var import_os2 = __toESM(require("os"), 1);
|
|
35275
|
+
var SyncFileWriter = class {
|
|
35276
|
+
/**
|
|
35277
|
+
* Create a writer to write to a file.
|
|
35278
|
+
*
|
|
35279
|
+
* @param path - path of file to write
|
|
35280
|
+
* @param options - options for file writing
|
|
35281
|
+
*/
|
|
35282
|
+
constructor(path5, options) {
|
|
35283
|
+
__publicField(this, "_path");
|
|
35284
|
+
__publicField(this, "_append");
|
|
35285
|
+
__publicField(this, "_encoding");
|
|
35286
|
+
__publicField(this, "_open");
|
|
35287
|
+
__publicField(this, "endOfLineString", import_os2.default.EOL);
|
|
35288
|
+
__publicField(this, "lastWrite", "");
|
|
35289
|
+
const opts = Object.assign({}, options);
|
|
35290
|
+
this._path = path5;
|
|
35291
|
+
this._append = !!opts.append;
|
|
35292
|
+
this._encoding = opts.encoding ?? "utf8";
|
|
35293
|
+
this._open = false;
|
|
35294
|
+
}
|
|
35295
|
+
get isSync() {
|
|
35296
|
+
return true;
|
|
35297
|
+
}
|
|
35298
|
+
get path() {
|
|
35299
|
+
return this._path;
|
|
35300
|
+
}
|
|
35301
|
+
get append() {
|
|
35302
|
+
return this._append;
|
|
35303
|
+
}
|
|
35304
|
+
get encoding() {
|
|
35305
|
+
return this._encoding;
|
|
35306
|
+
}
|
|
35307
|
+
async open() {
|
|
35308
|
+
this.openSync();
|
|
35309
|
+
return Promise.resolve();
|
|
35310
|
+
}
|
|
35311
|
+
async close() {
|
|
35312
|
+
try {
|
|
35313
|
+
this.closeSync();
|
|
35314
|
+
} catch (e) {
|
|
35315
|
+
return Promise.reject(e);
|
|
35316
|
+
}
|
|
35317
|
+
return Promise.resolve();
|
|
35318
|
+
}
|
|
35319
|
+
openSync() {
|
|
35320
|
+
const flag = this._append ? "a" : "w";
|
|
35321
|
+
import_fs_extra2.default.ensureDirSync(import_node_path2.default.dirname(this._path.toString()));
|
|
35322
|
+
import_fs_extra2.default.writeFileSync(this._path, "", {
|
|
35323
|
+
flag,
|
|
35324
|
+
encoding: this._encoding
|
|
35325
|
+
});
|
|
35326
|
+
this._open = true;
|
|
35327
|
+
}
|
|
35328
|
+
closeSync() {
|
|
35329
|
+
this._open = false;
|
|
35330
|
+
}
|
|
35331
|
+
writeLine(value) {
|
|
35332
|
+
if (!this._open) return this;
|
|
35333
|
+
let line;
|
|
35334
|
+
if (value != null) {
|
|
35335
|
+
line = value + this.endOfLineString;
|
|
35336
|
+
} else {
|
|
35337
|
+
line = this.endOfLineString;
|
|
35338
|
+
}
|
|
35339
|
+
import_fs_extra2.default.appendFileSync(this._path, line, {
|
|
35340
|
+
encoding: this._encoding
|
|
35341
|
+
});
|
|
35342
|
+
this.lastWrite = line;
|
|
35343
|
+
return this;
|
|
35344
|
+
}
|
|
35345
|
+
writeLines(values, delimiter) {
|
|
35346
|
+
if (!this._open) return this;
|
|
35347
|
+
if (!values) return this;
|
|
35348
|
+
let str = "";
|
|
35349
|
+
for (let i = 0, len = values.length; i < len; i++) {
|
|
35350
|
+
const value = values[i];
|
|
35351
|
+
str += value;
|
|
35352
|
+
if (delimiter && i < len - 1) {
|
|
35353
|
+
str += delimiter;
|
|
35354
|
+
}
|
|
35355
|
+
str += this.endOfLineString;
|
|
35356
|
+
}
|
|
35357
|
+
import_fs_extra2.default.appendFileSync(this._path, str, {
|
|
35358
|
+
encoding: this._encoding
|
|
35359
|
+
});
|
|
35360
|
+
this.lastWrite = str;
|
|
35361
|
+
return this;
|
|
35362
|
+
}
|
|
35363
|
+
write(value) {
|
|
35364
|
+
if (!this._open) return this;
|
|
35365
|
+
if (value == null) return this;
|
|
35366
|
+
if (value) this.lastWrite = value;
|
|
35367
|
+
import_fs_extra2.default.appendFileSync(this._path, value, {
|
|
35368
|
+
encoding: this._encoding
|
|
35369
|
+
});
|
|
35370
|
+
return this;
|
|
35371
|
+
}
|
|
35372
|
+
writeWhiteSpace() {
|
|
35373
|
+
this.write(" ");
|
|
35374
|
+
return this;
|
|
35375
|
+
}
|
|
35376
|
+
getLastWrite() {
|
|
35377
|
+
return this.lastWrite;
|
|
35378
|
+
}
|
|
35379
|
+
};
|
|
35380
|
+
|
|
35381
|
+
// src/generator/bitmark/BitmarkFileGenerator.ts
|
|
35264
35382
|
var BitmarkFileGenerator = class {
|
|
35265
35383
|
/**
|
|
35266
35384
|
* Generate bitmark markup from a bitmark AST as a file
|
|
@@ -35268,9 +35386,11 @@ var BitmarkFileGenerator = class {
|
|
|
35268
35386
|
* @param path - path of file to generate
|
|
35269
35387
|
* @param options - bitmark generation options
|
|
35270
35388
|
*/
|
|
35271
|
-
constructor(
|
|
35389
|
+
constructor(path5, options) {
|
|
35272
35390
|
__publicField(this, "generator");
|
|
35273
|
-
|
|
35391
|
+
__publicField(this, "async");
|
|
35392
|
+
this.async = options?.async ?? false;
|
|
35393
|
+
const writer = this.async ? new FileWriter(path5, options?.fileOptions) : new SyncFileWriter(path5, options?.fileOptions);
|
|
35274
35394
|
this.generator = new BitmarkGenerator(writer, options);
|
|
35275
35395
|
}
|
|
35276
35396
|
/**
|
|
@@ -35287,12 +35407,15 @@ var BitmarkFileGenerator = class {
|
|
|
35287
35407
|
* @param ast bitmark AST
|
|
35288
35408
|
*/
|
|
35289
35409
|
generateSync(_ast) {
|
|
35290
|
-
|
|
35410
|
+
if (this.async) {
|
|
35411
|
+
throw new Error("Sync operation not supported");
|
|
35412
|
+
}
|
|
35413
|
+
this.generator.generateSync(_ast);
|
|
35291
35414
|
}
|
|
35292
35415
|
};
|
|
35293
35416
|
|
|
35294
35417
|
// src/generator/json/JsonFileGenerator.ts
|
|
35295
|
-
var
|
|
35418
|
+
var import_fs_extra4 = require("fs-extra");
|
|
35296
35419
|
var JsonFileGenerator = class {
|
|
35297
35420
|
/**
|
|
35298
35421
|
* Generate bitmark JSON from a bitmark AST as a file
|
|
@@ -35302,9 +35425,11 @@ var JsonFileGenerator = class {
|
|
|
35302
35425
|
* @param fileOptions - file options
|
|
35303
35426
|
* @param bitmarkOptions - bitmark generation options
|
|
35304
35427
|
*/
|
|
35305
|
-
constructor(
|
|
35428
|
+
constructor(path5, options) {
|
|
35306
35429
|
__publicField(this, "generator");
|
|
35307
|
-
|
|
35430
|
+
__publicField(this, "async");
|
|
35431
|
+
this.async = options?.async ?? false;
|
|
35432
|
+
const writer = this.async ? new FileWriter(path5, options?.fileOptions) : new SyncFileWriter(path5, options?.fileOptions);
|
|
35308
35433
|
this.generator = new JsonGenerator(writer, options);
|
|
35309
35434
|
}
|
|
35310
35435
|
/**
|
|
@@ -35321,19 +35446,22 @@ var JsonFileGenerator = class {
|
|
|
35321
35446
|
* @param ast bitmark AST
|
|
35322
35447
|
*/
|
|
35323
35448
|
generateSync(_ast) {
|
|
35324
|
-
|
|
35449
|
+
if (this.async) {
|
|
35450
|
+
throw new Error("Sync operation not supported");
|
|
35451
|
+
}
|
|
35452
|
+
this.generator.generateSync(_ast);
|
|
35325
35453
|
}
|
|
35326
35454
|
};
|
|
35327
35455
|
|
|
35328
35456
|
// src/info/ConfigBuilder.ts
|
|
35329
|
-
var
|
|
35330
|
-
var
|
|
35457
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
35458
|
+
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
35331
35459
|
var ConfigBuilder = class {
|
|
35332
|
-
|
|
35460
|
+
build(options) {
|
|
35333
35461
|
const opts = Object.assign({}, options);
|
|
35334
|
-
|
|
35462
|
+
this.buildFlat(opts);
|
|
35335
35463
|
}
|
|
35336
|
-
|
|
35464
|
+
buildFlat(options) {
|
|
35337
35465
|
const opts = Object.assign({}, options);
|
|
35338
35466
|
const bitConfigs = [];
|
|
35339
35467
|
for (const bt of BitType.values()) {
|
|
@@ -35342,9 +35470,8 @@ var ConfigBuilder = class {
|
|
|
35342
35470
|
if (bitConfig) bitConfigs.push(bitConfig);
|
|
35343
35471
|
}
|
|
35344
35472
|
const outputFolder = opts.outputDir ?? "assets/config";
|
|
35345
|
-
const outputFolderBits =
|
|
35346
|
-
|
|
35347
|
-
const fileWrites = [];
|
|
35473
|
+
const outputFolderBits = import_node_path3.default.join(outputFolder, "bits_flat");
|
|
35474
|
+
import_fs_extra5.default.ensureDirSync(outputFolderBits);
|
|
35348
35475
|
for (const b of bitConfigs) {
|
|
35349
35476
|
const inherits = [];
|
|
35350
35477
|
const tags2 = [];
|
|
@@ -35477,11 +35604,10 @@ var ConfigBuilder = class {
|
|
|
35477
35604
|
resourceAttachmentAllowed: b.resourceAttachmentAllowed ?? true,
|
|
35478
35605
|
tags: tags2
|
|
35479
35606
|
};
|
|
35480
|
-
const output =
|
|
35607
|
+
const output = import_node_path3.default.join(outputFolderBits, `${b.bitType}.jsonc`);
|
|
35481
35608
|
const str = JSON.stringify(bitJson, null, 2);
|
|
35482
|
-
|
|
35609
|
+
import_fs_extra5.default.writeFileSync(output, str);
|
|
35483
35610
|
}
|
|
35484
|
-
await Promise.all(fileWrites);
|
|
35485
35611
|
}
|
|
35486
35612
|
};
|
|
35487
35613
|
|
|
@@ -35593,11 +35719,10 @@ var BitmarkParserGenerator = class {
|
|
|
35593
35719
|
/**
|
|
35594
35720
|
* Generate the new configuration for the bitmark parser.
|
|
35595
35721
|
*/
|
|
35596
|
-
|
|
35722
|
+
generateConfig(options) {
|
|
35597
35723
|
const opts = Object.assign({}, options);
|
|
35598
35724
|
const builder3 = new ConfigBuilder();
|
|
35599
|
-
|
|
35600
|
-
return void 0;
|
|
35725
|
+
builder3.build(opts);
|
|
35601
35726
|
}
|
|
35602
35727
|
/**
|
|
35603
35728
|
* Convert bitmark from bitmark to JSON, or JSON to bitmark.
|
|
@@ -35621,11 +35746,11 @@ var BitmarkParserGenerator = class {
|
|
|
35621
35746
|
* @param input - bitmark or JSON or AST as a string, JSON or AST as plain JS object, or path to a file containing
|
|
35622
35747
|
* bitmark, JSON, or AST.
|
|
35623
35748
|
* @param options - the conversion options
|
|
35624
|
-
* @returns
|
|
35749
|
+
* @returns A string if converting to bitmark, a plain JS object if converting to JSON, or
|
|
35625
35750
|
* void if writing to a file
|
|
35626
35751
|
* @throws Error if any error occurs
|
|
35627
35752
|
*/
|
|
35628
|
-
|
|
35753
|
+
convert(input, options) {
|
|
35629
35754
|
let res;
|
|
35630
35755
|
const opts = Object.assign({}, options);
|
|
35631
35756
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
@@ -35640,8 +35765,8 @@ var BitmarkParserGenerator = class {
|
|
|
35640
35765
|
}
|
|
35641
35766
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35642
35767
|
if (env.isNode) {
|
|
35643
|
-
if (
|
|
35644
|
-
inStr =
|
|
35768
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
35769
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35645
35770
|
encoding: "utf8"
|
|
35646
35771
|
});
|
|
35647
35772
|
}
|
|
@@ -35654,92 +35779,92 @@ var BitmarkParserGenerator = class {
|
|
|
35654
35779
|
}
|
|
35655
35780
|
const isJson = !!ast?.bits;
|
|
35656
35781
|
const isBitmark = !isJson && !isAst;
|
|
35657
|
-
const bitmarkToBitmark =
|
|
35658
|
-
|
|
35659
|
-
|
|
35782
|
+
const bitmarkToBitmark = (bitmarkStr) => {
|
|
35783
|
+
bitmarkToAst(bitmarkStr);
|
|
35784
|
+
astToBitmark(res);
|
|
35660
35785
|
};
|
|
35661
|
-
const bitmarkToAst =
|
|
35786
|
+
const bitmarkToAst = (bitmarkStr) => {
|
|
35662
35787
|
res = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35663
35788
|
parserType: bitmarkParserType
|
|
35664
35789
|
});
|
|
35665
35790
|
};
|
|
35666
|
-
const bitmarkToJson =
|
|
35791
|
+
const bitmarkToJson = (bitmarkStr) => {
|
|
35667
35792
|
if (bitmarkParserType === BitmarkParserType.peggy) {
|
|
35668
35793
|
ast = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35669
35794
|
parserType: bitmarkParserType
|
|
35670
35795
|
});
|
|
35671
35796
|
if (opts.outputFile) {
|
|
35672
35797
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35673
|
-
|
|
35798
|
+
generator.generateSync(ast);
|
|
35674
35799
|
} else {
|
|
35675
35800
|
const generator = new JsonObjectGenerator(opts);
|
|
35676
|
-
const json =
|
|
35801
|
+
const json = generator.generateSync(ast);
|
|
35677
35802
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35678
35803
|
}
|
|
35679
35804
|
}
|
|
35680
35805
|
};
|
|
35681
|
-
const astToBitmark =
|
|
35806
|
+
const astToBitmark = (astJson) => {
|
|
35682
35807
|
if (opts.outputFile) {
|
|
35683
35808
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35684
|
-
|
|
35809
|
+
generator.generateSync(astJson);
|
|
35685
35810
|
} else {
|
|
35686
35811
|
const generator = new BitmarkStringGenerator(opts);
|
|
35687
|
-
res =
|
|
35812
|
+
res = generator.generateSync(astJson);
|
|
35688
35813
|
}
|
|
35689
35814
|
};
|
|
35690
|
-
const astToAst =
|
|
35815
|
+
const astToAst = (astJson) => {
|
|
35691
35816
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
35692
35817
|
};
|
|
35693
|
-
const astToJson =
|
|
35818
|
+
const astToJson = (astJson) => {
|
|
35694
35819
|
if (opts.outputFile) {
|
|
35695
35820
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35696
|
-
|
|
35821
|
+
generator.generateSync(astJson);
|
|
35697
35822
|
} else {
|
|
35698
35823
|
const generator = new JsonObjectGenerator(opts);
|
|
35699
|
-
const json =
|
|
35824
|
+
const json = generator.generateSync(astJson);
|
|
35700
35825
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35701
35826
|
}
|
|
35702
35827
|
};
|
|
35703
|
-
const jsonToBitmark =
|
|
35828
|
+
const jsonToBitmark = (astJson) => {
|
|
35704
35829
|
if (opts.outputFile) {
|
|
35705
35830
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35706
|
-
|
|
35831
|
+
generator.generateSync(astJson);
|
|
35707
35832
|
} else {
|
|
35708
35833
|
const generator = new BitmarkStringGenerator(opts);
|
|
35709
|
-
res =
|
|
35834
|
+
res = generator.generateSync(astJson);
|
|
35710
35835
|
}
|
|
35711
35836
|
};
|
|
35712
|
-
const jsonToAst =
|
|
35837
|
+
const jsonToAst = (astJson) => {
|
|
35713
35838
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
35714
35839
|
};
|
|
35715
|
-
const jsonToJson =
|
|
35716
|
-
|
|
35840
|
+
const jsonToJson = (astJson) => {
|
|
35841
|
+
astToJson(astJson);
|
|
35717
35842
|
};
|
|
35718
35843
|
if (isBitmark) {
|
|
35719
35844
|
if (outputBitmark) {
|
|
35720
|
-
|
|
35845
|
+
bitmarkToBitmark(inStr);
|
|
35721
35846
|
} else if (outputAst) {
|
|
35722
|
-
|
|
35847
|
+
bitmarkToAst(inStr);
|
|
35723
35848
|
} else {
|
|
35724
|
-
|
|
35849
|
+
bitmarkToJson(inStr);
|
|
35725
35850
|
}
|
|
35726
35851
|
} else if (isAst) {
|
|
35727
35852
|
ast = ast;
|
|
35728
35853
|
if (outputAst) {
|
|
35729
|
-
|
|
35854
|
+
astToAst(ast);
|
|
35730
35855
|
} else if (outputJson) {
|
|
35731
|
-
|
|
35856
|
+
astToJson(ast);
|
|
35732
35857
|
} else {
|
|
35733
|
-
|
|
35858
|
+
astToBitmark(ast);
|
|
35734
35859
|
}
|
|
35735
35860
|
} else {
|
|
35736
35861
|
ast = ast;
|
|
35737
35862
|
if (outputJson) {
|
|
35738
|
-
|
|
35863
|
+
jsonToJson(ast);
|
|
35739
35864
|
} else if (outputAst) {
|
|
35740
|
-
|
|
35865
|
+
jsonToAst(ast);
|
|
35741
35866
|
} else {
|
|
35742
|
-
|
|
35867
|
+
jsonToBitmark(ast);
|
|
35743
35868
|
}
|
|
35744
35869
|
}
|
|
35745
35870
|
return res;
|
|
@@ -35769,7 +35894,7 @@ var BitmarkParserGenerator = class {
|
|
|
35769
35894
|
* void if writing to a file
|
|
35770
35895
|
* @throws Error if any error occurs
|
|
35771
35896
|
*/
|
|
35772
|
-
|
|
35897
|
+
upgrade(input, options) {
|
|
35773
35898
|
let res;
|
|
35774
35899
|
const opts = Object.assign({}, options);
|
|
35775
35900
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
@@ -35780,8 +35905,8 @@ var BitmarkParserGenerator = class {
|
|
|
35780
35905
|
}
|
|
35781
35906
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35782
35907
|
if (env.isNode) {
|
|
35783
|
-
if (
|
|
35784
|
-
inStr =
|
|
35908
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
35909
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35785
35910
|
encoding: "utf8"
|
|
35786
35911
|
});
|
|
35787
35912
|
}
|
|
@@ -35790,33 +35915,33 @@ var BitmarkParserGenerator = class {
|
|
|
35790
35915
|
let ast = this.jsonParser.toAst(inStr);
|
|
35791
35916
|
const isJson = !!ast?.bits;
|
|
35792
35917
|
const isBitmark = !isJson;
|
|
35793
|
-
const bitmarkToBitmark =
|
|
35918
|
+
const bitmarkToBitmark = (bitmarkStr) => {
|
|
35794
35919
|
const astJson = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35795
35920
|
parserType: bitmarkParserType
|
|
35796
35921
|
});
|
|
35797
35922
|
if (opts.outputFile) {
|
|
35798
35923
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35799
|
-
|
|
35924
|
+
generator.generateSync(astJson);
|
|
35800
35925
|
} else {
|
|
35801
35926
|
const generator = new BitmarkStringGenerator(opts);
|
|
35802
|
-
res =
|
|
35927
|
+
res = generator.generateSync(astJson);
|
|
35803
35928
|
}
|
|
35804
35929
|
};
|
|
35805
|
-
const jsonToJson =
|
|
35930
|
+
const jsonToJson = (astJson) => {
|
|
35806
35931
|
if (opts.outputFile) {
|
|
35807
35932
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35808
|
-
|
|
35933
|
+
generator.generateSync(astJson);
|
|
35809
35934
|
} else {
|
|
35810
35935
|
const generator = new JsonObjectGenerator(opts);
|
|
35811
|
-
const json =
|
|
35936
|
+
const json = generator.generateSync(astJson);
|
|
35812
35937
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35813
35938
|
}
|
|
35814
35939
|
};
|
|
35815
35940
|
if (isBitmark) {
|
|
35816
|
-
|
|
35941
|
+
bitmarkToBitmark(inStr);
|
|
35817
35942
|
} else {
|
|
35818
35943
|
ast = ast;
|
|
35819
|
-
|
|
35944
|
+
jsonToJson(ast);
|
|
35820
35945
|
}
|
|
35821
35946
|
return res;
|
|
35822
35947
|
}
|
|
@@ -35836,8 +35961,8 @@ var BitmarkParserGenerator = class {
|
|
|
35836
35961
|
const opts = Object.assign({}, options);
|
|
35837
35962
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35838
35963
|
if (env.isNode) {
|
|
35839
|
-
if (
|
|
35840
|
-
inStr =
|
|
35964
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
35965
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35841
35966
|
encoding: "utf8"
|
|
35842
35967
|
});
|
|
35843
35968
|
}
|
|
@@ -35880,7 +36005,7 @@ var BitmarkParserGenerator = class {
|
|
|
35880
36005
|
* void if writing to a file
|
|
35881
36006
|
* @throws Error if any error occurs
|
|
35882
36007
|
*/
|
|
35883
|
-
|
|
36008
|
+
convertText(input, options) {
|
|
35884
36009
|
let res;
|
|
35885
36010
|
let preRes;
|
|
35886
36011
|
const opts = Object.assign({}, options);
|
|
@@ -35894,8 +36019,8 @@ var BitmarkParserGenerator = class {
|
|
|
35894
36019
|
}
|
|
35895
36020
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35896
36021
|
if (env.isNode) {
|
|
35897
|
-
if (
|
|
35898
|
-
inStr =
|
|
36022
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
36023
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35899
36024
|
encoding: "utf8"
|
|
35900
36025
|
});
|
|
35901
36026
|
}
|
|
@@ -35909,7 +36034,7 @@ var BitmarkParserGenerator = class {
|
|
|
35909
36034
|
location: TextLocation.body
|
|
35910
36035
|
});
|
|
35911
36036
|
} else {
|
|
35912
|
-
preRes =
|
|
36037
|
+
preRes = this.textGenerator.generateSync(ast, textFormat, textLocation);
|
|
35913
36038
|
}
|
|
35914
36039
|
if (opts.outputFile) {
|
|
35915
36040
|
const output = opts.outputFile.toString();
|
|
@@ -35918,8 +36043,8 @@ var BitmarkParserGenerator = class {
|
|
|
35918
36043
|
strRes = this.jsonStringifyPrettify(preRes, jsonOptions, true);
|
|
35919
36044
|
}
|
|
35920
36045
|
const flag = fileOptions.append ? "a" : "w";
|
|
35921
|
-
|
|
35922
|
-
|
|
36046
|
+
import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
|
|
36047
|
+
import_fs_extra6.default.writeFileSync(output, strRes, {
|
|
35923
36048
|
flag
|
|
35924
36049
|
});
|
|
35925
36050
|
} else {
|
|
@@ -35961,8 +36086,8 @@ var BitmarkParserGenerator = class {
|
|
|
35961
36086
|
}
|
|
35962
36087
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35963
36088
|
if (env.isNode) {
|
|
35964
|
-
if (
|
|
35965
|
-
inStr =
|
|
36089
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
36090
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35966
36091
|
encoding: "utf8"
|
|
35967
36092
|
});
|
|
35968
36093
|
}
|
|
@@ -35975,8 +36100,8 @@ var BitmarkParserGenerator = class {
|
|
|
35975
36100
|
if (opts.outputFile) {
|
|
35976
36101
|
const output = opts.outputFile.toString();
|
|
35977
36102
|
const flag = fileOptions.append ? "a" : "w";
|
|
35978
|
-
|
|
35979
|
-
|
|
36103
|
+
import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
|
|
36104
|
+
import_fs_extra6.default.writeFileSync(output, res, {
|
|
35980
36105
|
flag
|
|
35981
36106
|
});
|
|
35982
36107
|
} else {
|
|
@@ -36013,8 +36138,8 @@ var BitmarkParserGenerator = class {
|
|
|
36013
36138
|
}
|
|
36014
36139
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
36015
36140
|
if (env.isNode) {
|
|
36016
|
-
if (
|
|
36017
|
-
inStr =
|
|
36141
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
36142
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
36018
36143
|
encoding: "utf8"
|
|
36019
36144
|
});
|
|
36020
36145
|
}
|
|
@@ -36027,8 +36152,8 @@ var BitmarkParserGenerator = class {
|
|
|
36027
36152
|
if (opts.outputFile) {
|
|
36028
36153
|
const output = opts.outputFile.toString();
|
|
36029
36154
|
const flag = fileOptions.append ? "a" : "w";
|
|
36030
|
-
|
|
36031
|
-
|
|
36155
|
+
import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
|
|
36156
|
+
import_fs_extra6.default.writeFileSync(output, res, {
|
|
36032
36157
|
flag
|
|
36033
36158
|
});
|
|
36034
36159
|
} else {
|