@gmb/bitmark-parser-generator 3.37.0 → 4.0.0
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 +35706 -0
- package/dist/browser/cjs/index.cjs.map +1 -0
- package/dist/browser/cjs/index.d.cts +7818 -0
- package/dist/browser/esm/index.d.ts +7818 -0
- package/dist/browser/esm/index.js +35660 -0
- package/dist/browser/esm/index.js.map +1 -0
- package/dist/index.cjs +244 -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 +242 -118
- package/dist/index.js.map +1 -1
- package/package.json +27 -5
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.0",
|
|
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) {
|
|
@@ -31246,7 +31250,8 @@ function buildResources(context, resourceTypeAttachment, resources) {
|
|
|
31246
31250
|
const countsMax = resourcesConfig.getCountsMax();
|
|
31247
31251
|
if (resources) {
|
|
31248
31252
|
for (const r of resources.reverse()) {
|
|
31249
|
-
|
|
31253
|
+
if (r.__invalid) continue;
|
|
31254
|
+
const configKey = r.__configKey;
|
|
31250
31255
|
let countMin = countsMin.get(configKey) ?? 0;
|
|
31251
31256
|
let countMax = countsMax.get(configKey) ?? 0;
|
|
31252
31257
|
countMin = Math.max(0, countMin - 1);
|
|
@@ -31267,7 +31272,7 @@ function buildResources(context, resourceTypeAttachment, resources) {
|
|
|
31267
31272
|
context.addWarning(warningMsg);
|
|
31268
31273
|
} else if (filteredResources.length === 0 && resourceTypeAttachment) {
|
|
31269
31274
|
context.addWarning(
|
|
31270
|
-
`Resource type [&${resourceTypeAttachment}] is specified in the bit header, but no such
|
|
31275
|
+
`Resource type [&${resourceTypeAttachment}] is specified in the bit header, but no such resource is present`
|
|
31271
31276
|
);
|
|
31272
31277
|
}
|
|
31273
31278
|
if (excessResources.length > 0) {
|
|
@@ -35118,8 +35123,8 @@ var BitmarkParser = class {
|
|
|
35118
35123
|
};
|
|
35119
35124
|
|
|
35120
35125
|
// src/BitmarkParserGenerator.ts
|
|
35121
|
-
var
|
|
35122
|
-
var
|
|
35126
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
35127
|
+
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
35123
35128
|
|
|
35124
35129
|
// src/ast/writer/FileWriter.ts
|
|
35125
35130
|
var import_node_path = __toESM(require("path"), 1);
|
|
@@ -35207,13 +35212,13 @@ var FileWriter = class extends StreamWriter {
|
|
|
35207
35212
|
* @param path - path of file to write
|
|
35208
35213
|
* @param options - options for file writing
|
|
35209
35214
|
*/
|
|
35210
|
-
constructor(
|
|
35215
|
+
constructor(path5, options) {
|
|
35211
35216
|
super();
|
|
35212
35217
|
__publicField(this, "_path");
|
|
35213
35218
|
__publicField(this, "_append");
|
|
35214
35219
|
__publicField(this, "_encoding");
|
|
35215
35220
|
const opts = Object.assign({}, options);
|
|
35216
|
-
this._path =
|
|
35221
|
+
this._path = path5;
|
|
35217
35222
|
this._append = !!opts.append;
|
|
35218
35223
|
this._encoding = opts.encoding ?? "utf8";
|
|
35219
35224
|
}
|
|
@@ -35260,7 +35265,119 @@ var FileWriter = class extends StreamWriter {
|
|
|
35260
35265
|
};
|
|
35261
35266
|
|
|
35262
35267
|
// src/generator/bitmark/BitmarkFileGenerator.ts
|
|
35263
|
-
var
|
|
35268
|
+
var import_fs_extra3 = require("fs-extra");
|
|
35269
|
+
|
|
35270
|
+
// src/ast/writer/SyncFileWriter.ts
|
|
35271
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
35272
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
35273
|
+
var import_os2 = __toESM(require("os"), 1);
|
|
35274
|
+
var SyncFileWriter = class {
|
|
35275
|
+
/**
|
|
35276
|
+
* Create a writer to write to a file.
|
|
35277
|
+
*
|
|
35278
|
+
* @param path - path of file to write
|
|
35279
|
+
* @param options - options for file writing
|
|
35280
|
+
*/
|
|
35281
|
+
constructor(path5, options) {
|
|
35282
|
+
__publicField(this, "_path");
|
|
35283
|
+
__publicField(this, "_append");
|
|
35284
|
+
__publicField(this, "_encoding");
|
|
35285
|
+
__publicField(this, "_open");
|
|
35286
|
+
__publicField(this, "endOfLineString", import_os2.default.EOL);
|
|
35287
|
+
__publicField(this, "lastWrite", "");
|
|
35288
|
+
const opts = Object.assign({}, options);
|
|
35289
|
+
this._path = path5;
|
|
35290
|
+
this._append = !!opts.append;
|
|
35291
|
+
this._encoding = opts.encoding ?? "utf8";
|
|
35292
|
+
this._open = false;
|
|
35293
|
+
}
|
|
35294
|
+
get isSync() {
|
|
35295
|
+
return true;
|
|
35296
|
+
}
|
|
35297
|
+
get path() {
|
|
35298
|
+
return this._path;
|
|
35299
|
+
}
|
|
35300
|
+
get append() {
|
|
35301
|
+
return this._append;
|
|
35302
|
+
}
|
|
35303
|
+
get encoding() {
|
|
35304
|
+
return this._encoding;
|
|
35305
|
+
}
|
|
35306
|
+
async open() {
|
|
35307
|
+
this.openSync();
|
|
35308
|
+
return Promise.resolve();
|
|
35309
|
+
}
|
|
35310
|
+
async close() {
|
|
35311
|
+
try {
|
|
35312
|
+
this.closeSync();
|
|
35313
|
+
} catch (e) {
|
|
35314
|
+
return Promise.reject(e);
|
|
35315
|
+
}
|
|
35316
|
+
return Promise.resolve();
|
|
35317
|
+
}
|
|
35318
|
+
openSync() {
|
|
35319
|
+
const flag = this._append ? "a" : "w";
|
|
35320
|
+
import_fs_extra2.default.ensureDirSync(import_node_path2.default.dirname(this._path.toString()));
|
|
35321
|
+
import_fs_extra2.default.writeFileSync(this._path, "", {
|
|
35322
|
+
flag,
|
|
35323
|
+
encoding: this._encoding
|
|
35324
|
+
});
|
|
35325
|
+
this._open = true;
|
|
35326
|
+
}
|
|
35327
|
+
closeSync() {
|
|
35328
|
+
this._open = false;
|
|
35329
|
+
}
|
|
35330
|
+
writeLine(value) {
|
|
35331
|
+
if (!this._open) return this;
|
|
35332
|
+
let line;
|
|
35333
|
+
if (value != null) {
|
|
35334
|
+
line = value + this.endOfLineString;
|
|
35335
|
+
} else {
|
|
35336
|
+
line = this.endOfLineString;
|
|
35337
|
+
}
|
|
35338
|
+
import_fs_extra2.default.appendFileSync(this._path, line, {
|
|
35339
|
+
encoding: this._encoding
|
|
35340
|
+
});
|
|
35341
|
+
this.lastWrite = line;
|
|
35342
|
+
return this;
|
|
35343
|
+
}
|
|
35344
|
+
writeLines(values, delimiter) {
|
|
35345
|
+
if (!this._open) return this;
|
|
35346
|
+
if (!values) return this;
|
|
35347
|
+
let str = "";
|
|
35348
|
+
for (let i = 0, len = values.length; i < len; i++) {
|
|
35349
|
+
const value = values[i];
|
|
35350
|
+
str += value;
|
|
35351
|
+
if (delimiter && i < len - 1) {
|
|
35352
|
+
str += delimiter;
|
|
35353
|
+
}
|
|
35354
|
+
str += this.endOfLineString;
|
|
35355
|
+
}
|
|
35356
|
+
import_fs_extra2.default.appendFileSync(this._path, str, {
|
|
35357
|
+
encoding: this._encoding
|
|
35358
|
+
});
|
|
35359
|
+
this.lastWrite = str;
|
|
35360
|
+
return this;
|
|
35361
|
+
}
|
|
35362
|
+
write(value) {
|
|
35363
|
+
if (!this._open) return this;
|
|
35364
|
+
if (value == null) return this;
|
|
35365
|
+
if (value) this.lastWrite = value;
|
|
35366
|
+
import_fs_extra2.default.appendFileSync(this._path, value, {
|
|
35367
|
+
encoding: this._encoding
|
|
35368
|
+
});
|
|
35369
|
+
return this;
|
|
35370
|
+
}
|
|
35371
|
+
writeWhiteSpace() {
|
|
35372
|
+
this.write(" ");
|
|
35373
|
+
return this;
|
|
35374
|
+
}
|
|
35375
|
+
getLastWrite() {
|
|
35376
|
+
return this.lastWrite;
|
|
35377
|
+
}
|
|
35378
|
+
};
|
|
35379
|
+
|
|
35380
|
+
// src/generator/bitmark/BitmarkFileGenerator.ts
|
|
35264
35381
|
var BitmarkFileGenerator = class {
|
|
35265
35382
|
/**
|
|
35266
35383
|
* Generate bitmark markup from a bitmark AST as a file
|
|
@@ -35268,9 +35385,11 @@ var BitmarkFileGenerator = class {
|
|
|
35268
35385
|
* @param path - path of file to generate
|
|
35269
35386
|
* @param options - bitmark generation options
|
|
35270
35387
|
*/
|
|
35271
|
-
constructor(
|
|
35388
|
+
constructor(path5, options) {
|
|
35272
35389
|
__publicField(this, "generator");
|
|
35273
|
-
|
|
35390
|
+
__publicField(this, "async");
|
|
35391
|
+
this.async = options?.async ?? false;
|
|
35392
|
+
const writer = this.async ? new FileWriter(path5, options?.fileOptions) : new SyncFileWriter(path5, options?.fileOptions);
|
|
35274
35393
|
this.generator = new BitmarkGenerator(writer, options);
|
|
35275
35394
|
}
|
|
35276
35395
|
/**
|
|
@@ -35287,12 +35406,15 @@ var BitmarkFileGenerator = class {
|
|
|
35287
35406
|
* @param ast bitmark AST
|
|
35288
35407
|
*/
|
|
35289
35408
|
generateSync(_ast) {
|
|
35290
|
-
|
|
35409
|
+
if (this.async) {
|
|
35410
|
+
throw new Error("Sync operation not supported");
|
|
35411
|
+
}
|
|
35412
|
+
this.generator.generateSync(_ast);
|
|
35291
35413
|
}
|
|
35292
35414
|
};
|
|
35293
35415
|
|
|
35294
35416
|
// src/generator/json/JsonFileGenerator.ts
|
|
35295
|
-
var
|
|
35417
|
+
var import_fs_extra4 = require("fs-extra");
|
|
35296
35418
|
var JsonFileGenerator = class {
|
|
35297
35419
|
/**
|
|
35298
35420
|
* Generate bitmark JSON from a bitmark AST as a file
|
|
@@ -35302,9 +35424,11 @@ var JsonFileGenerator = class {
|
|
|
35302
35424
|
* @param fileOptions - file options
|
|
35303
35425
|
* @param bitmarkOptions - bitmark generation options
|
|
35304
35426
|
*/
|
|
35305
|
-
constructor(
|
|
35427
|
+
constructor(path5, options) {
|
|
35306
35428
|
__publicField(this, "generator");
|
|
35307
|
-
|
|
35429
|
+
__publicField(this, "async");
|
|
35430
|
+
this.async = options?.async ?? false;
|
|
35431
|
+
const writer = this.async ? new FileWriter(path5, options?.fileOptions) : new SyncFileWriter(path5, options?.fileOptions);
|
|
35308
35432
|
this.generator = new JsonGenerator(writer, options);
|
|
35309
35433
|
}
|
|
35310
35434
|
/**
|
|
@@ -35321,19 +35445,22 @@ var JsonFileGenerator = class {
|
|
|
35321
35445
|
* @param ast bitmark AST
|
|
35322
35446
|
*/
|
|
35323
35447
|
generateSync(_ast) {
|
|
35324
|
-
|
|
35448
|
+
if (this.async) {
|
|
35449
|
+
throw new Error("Sync operation not supported");
|
|
35450
|
+
}
|
|
35451
|
+
this.generator.generateSync(_ast);
|
|
35325
35452
|
}
|
|
35326
35453
|
};
|
|
35327
35454
|
|
|
35328
35455
|
// src/info/ConfigBuilder.ts
|
|
35329
|
-
var
|
|
35330
|
-
var
|
|
35456
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
35457
|
+
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
35331
35458
|
var ConfigBuilder = class {
|
|
35332
|
-
|
|
35459
|
+
build(options) {
|
|
35333
35460
|
const opts = Object.assign({}, options);
|
|
35334
|
-
|
|
35461
|
+
this.buildFlat(opts);
|
|
35335
35462
|
}
|
|
35336
|
-
|
|
35463
|
+
buildFlat(options) {
|
|
35337
35464
|
const opts = Object.assign({}, options);
|
|
35338
35465
|
const bitConfigs = [];
|
|
35339
35466
|
for (const bt of BitType.values()) {
|
|
@@ -35342,9 +35469,8 @@ var ConfigBuilder = class {
|
|
|
35342
35469
|
if (bitConfig) bitConfigs.push(bitConfig);
|
|
35343
35470
|
}
|
|
35344
35471
|
const outputFolder = opts.outputDir ?? "assets/config";
|
|
35345
|
-
const outputFolderBits =
|
|
35346
|
-
|
|
35347
|
-
const fileWrites = [];
|
|
35472
|
+
const outputFolderBits = import_node_path3.default.join(outputFolder, "bits_flat");
|
|
35473
|
+
import_fs_extra5.default.ensureDirSync(outputFolderBits);
|
|
35348
35474
|
for (const b of bitConfigs) {
|
|
35349
35475
|
const inherits = [];
|
|
35350
35476
|
const tags2 = [];
|
|
@@ -35477,11 +35603,10 @@ var ConfigBuilder = class {
|
|
|
35477
35603
|
resourceAttachmentAllowed: b.resourceAttachmentAllowed ?? true,
|
|
35478
35604
|
tags: tags2
|
|
35479
35605
|
};
|
|
35480
|
-
const output =
|
|
35606
|
+
const output = import_node_path3.default.join(outputFolderBits, `${b.bitType}.jsonc`);
|
|
35481
35607
|
const str = JSON.stringify(bitJson, null, 2);
|
|
35482
|
-
|
|
35608
|
+
import_fs_extra5.default.writeFileSync(output, str);
|
|
35483
35609
|
}
|
|
35484
|
-
await Promise.all(fileWrites);
|
|
35485
35610
|
}
|
|
35486
35611
|
};
|
|
35487
35612
|
|
|
@@ -35593,11 +35718,10 @@ var BitmarkParserGenerator = class {
|
|
|
35593
35718
|
/**
|
|
35594
35719
|
* Generate the new configuration for the bitmark parser.
|
|
35595
35720
|
*/
|
|
35596
|
-
|
|
35721
|
+
generateConfig(options) {
|
|
35597
35722
|
const opts = Object.assign({}, options);
|
|
35598
35723
|
const builder3 = new ConfigBuilder();
|
|
35599
|
-
|
|
35600
|
-
return void 0;
|
|
35724
|
+
builder3.build(opts);
|
|
35601
35725
|
}
|
|
35602
35726
|
/**
|
|
35603
35727
|
* Convert bitmark from bitmark to JSON, or JSON to bitmark.
|
|
@@ -35621,11 +35745,11 @@ var BitmarkParserGenerator = class {
|
|
|
35621
35745
|
* @param input - bitmark or JSON or AST as a string, JSON or AST as plain JS object, or path to a file containing
|
|
35622
35746
|
* bitmark, JSON, or AST.
|
|
35623
35747
|
* @param options - the conversion options
|
|
35624
|
-
* @returns
|
|
35748
|
+
* @returns A string if converting to bitmark, a plain JS object if converting to JSON, or
|
|
35625
35749
|
* void if writing to a file
|
|
35626
35750
|
* @throws Error if any error occurs
|
|
35627
35751
|
*/
|
|
35628
|
-
|
|
35752
|
+
convert(input, options) {
|
|
35629
35753
|
let res;
|
|
35630
35754
|
const opts = Object.assign({}, options);
|
|
35631
35755
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
@@ -35640,8 +35764,8 @@ var BitmarkParserGenerator = class {
|
|
|
35640
35764
|
}
|
|
35641
35765
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35642
35766
|
if (env.isNode) {
|
|
35643
|
-
if (
|
|
35644
|
-
inStr =
|
|
35767
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
35768
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35645
35769
|
encoding: "utf8"
|
|
35646
35770
|
});
|
|
35647
35771
|
}
|
|
@@ -35654,92 +35778,92 @@ var BitmarkParserGenerator = class {
|
|
|
35654
35778
|
}
|
|
35655
35779
|
const isJson = !!ast?.bits;
|
|
35656
35780
|
const isBitmark = !isJson && !isAst;
|
|
35657
|
-
const bitmarkToBitmark =
|
|
35658
|
-
|
|
35659
|
-
|
|
35781
|
+
const bitmarkToBitmark = (bitmarkStr) => {
|
|
35782
|
+
bitmarkToAst(bitmarkStr);
|
|
35783
|
+
astToBitmark(res);
|
|
35660
35784
|
};
|
|
35661
|
-
const bitmarkToAst =
|
|
35785
|
+
const bitmarkToAst = (bitmarkStr) => {
|
|
35662
35786
|
res = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35663
35787
|
parserType: bitmarkParserType
|
|
35664
35788
|
});
|
|
35665
35789
|
};
|
|
35666
|
-
const bitmarkToJson =
|
|
35790
|
+
const bitmarkToJson = (bitmarkStr) => {
|
|
35667
35791
|
if (bitmarkParserType === BitmarkParserType.peggy) {
|
|
35668
35792
|
ast = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35669
35793
|
parserType: bitmarkParserType
|
|
35670
35794
|
});
|
|
35671
35795
|
if (opts.outputFile) {
|
|
35672
35796
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35673
|
-
|
|
35797
|
+
generator.generateSync(ast);
|
|
35674
35798
|
} else {
|
|
35675
35799
|
const generator = new JsonObjectGenerator(opts);
|
|
35676
|
-
const json =
|
|
35800
|
+
const json = generator.generateSync(ast);
|
|
35677
35801
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35678
35802
|
}
|
|
35679
35803
|
}
|
|
35680
35804
|
};
|
|
35681
|
-
const astToBitmark =
|
|
35805
|
+
const astToBitmark = (astJson) => {
|
|
35682
35806
|
if (opts.outputFile) {
|
|
35683
35807
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35684
|
-
|
|
35808
|
+
generator.generateSync(astJson);
|
|
35685
35809
|
} else {
|
|
35686
35810
|
const generator = new BitmarkStringGenerator(opts);
|
|
35687
|
-
res =
|
|
35811
|
+
res = generator.generateSync(astJson);
|
|
35688
35812
|
}
|
|
35689
35813
|
};
|
|
35690
|
-
const astToAst =
|
|
35814
|
+
const astToAst = (astJson) => {
|
|
35691
35815
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
35692
35816
|
};
|
|
35693
|
-
const astToJson =
|
|
35817
|
+
const astToJson = (astJson) => {
|
|
35694
35818
|
if (opts.outputFile) {
|
|
35695
35819
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35696
|
-
|
|
35820
|
+
generator.generateSync(astJson);
|
|
35697
35821
|
} else {
|
|
35698
35822
|
const generator = new JsonObjectGenerator(opts);
|
|
35699
|
-
const json =
|
|
35823
|
+
const json = generator.generateSync(astJson);
|
|
35700
35824
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35701
35825
|
}
|
|
35702
35826
|
};
|
|
35703
|
-
const jsonToBitmark =
|
|
35827
|
+
const jsonToBitmark = (astJson) => {
|
|
35704
35828
|
if (opts.outputFile) {
|
|
35705
35829
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35706
|
-
|
|
35830
|
+
generator.generateSync(astJson);
|
|
35707
35831
|
} else {
|
|
35708
35832
|
const generator = new BitmarkStringGenerator(opts);
|
|
35709
|
-
res =
|
|
35833
|
+
res = generator.generateSync(astJson);
|
|
35710
35834
|
}
|
|
35711
35835
|
};
|
|
35712
|
-
const jsonToAst =
|
|
35836
|
+
const jsonToAst = (astJson) => {
|
|
35713
35837
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
35714
35838
|
};
|
|
35715
|
-
const jsonToJson =
|
|
35716
|
-
|
|
35839
|
+
const jsonToJson = (astJson) => {
|
|
35840
|
+
astToJson(astJson);
|
|
35717
35841
|
};
|
|
35718
35842
|
if (isBitmark) {
|
|
35719
35843
|
if (outputBitmark) {
|
|
35720
|
-
|
|
35844
|
+
bitmarkToBitmark(inStr);
|
|
35721
35845
|
} else if (outputAst) {
|
|
35722
|
-
|
|
35846
|
+
bitmarkToAst(inStr);
|
|
35723
35847
|
} else {
|
|
35724
|
-
|
|
35848
|
+
bitmarkToJson(inStr);
|
|
35725
35849
|
}
|
|
35726
35850
|
} else if (isAst) {
|
|
35727
35851
|
ast = ast;
|
|
35728
35852
|
if (outputAst) {
|
|
35729
|
-
|
|
35853
|
+
astToAst(ast);
|
|
35730
35854
|
} else if (outputJson) {
|
|
35731
|
-
|
|
35855
|
+
astToJson(ast);
|
|
35732
35856
|
} else {
|
|
35733
|
-
|
|
35857
|
+
astToBitmark(ast);
|
|
35734
35858
|
}
|
|
35735
35859
|
} else {
|
|
35736
35860
|
ast = ast;
|
|
35737
35861
|
if (outputJson) {
|
|
35738
|
-
|
|
35862
|
+
jsonToJson(ast);
|
|
35739
35863
|
} else if (outputAst) {
|
|
35740
|
-
|
|
35864
|
+
jsonToAst(ast);
|
|
35741
35865
|
} else {
|
|
35742
|
-
|
|
35866
|
+
jsonToBitmark(ast);
|
|
35743
35867
|
}
|
|
35744
35868
|
}
|
|
35745
35869
|
return res;
|
|
@@ -35769,7 +35893,7 @@ var BitmarkParserGenerator = class {
|
|
|
35769
35893
|
* void if writing to a file
|
|
35770
35894
|
* @throws Error if any error occurs
|
|
35771
35895
|
*/
|
|
35772
|
-
|
|
35896
|
+
upgrade(input, options) {
|
|
35773
35897
|
let res;
|
|
35774
35898
|
const opts = Object.assign({}, options);
|
|
35775
35899
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
@@ -35780,8 +35904,8 @@ var BitmarkParserGenerator = class {
|
|
|
35780
35904
|
}
|
|
35781
35905
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35782
35906
|
if (env.isNode) {
|
|
35783
|
-
if (
|
|
35784
|
-
inStr =
|
|
35907
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
35908
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35785
35909
|
encoding: "utf8"
|
|
35786
35910
|
});
|
|
35787
35911
|
}
|
|
@@ -35790,33 +35914,33 @@ var BitmarkParserGenerator = class {
|
|
|
35790
35914
|
let ast = this.jsonParser.toAst(inStr);
|
|
35791
35915
|
const isJson = !!ast?.bits;
|
|
35792
35916
|
const isBitmark = !isJson;
|
|
35793
|
-
const bitmarkToBitmark =
|
|
35917
|
+
const bitmarkToBitmark = (bitmarkStr) => {
|
|
35794
35918
|
const astJson = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35795
35919
|
parserType: bitmarkParserType
|
|
35796
35920
|
});
|
|
35797
35921
|
if (opts.outputFile) {
|
|
35798
35922
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35799
|
-
|
|
35923
|
+
generator.generateSync(astJson);
|
|
35800
35924
|
} else {
|
|
35801
35925
|
const generator = new BitmarkStringGenerator(opts);
|
|
35802
|
-
res =
|
|
35926
|
+
res = generator.generateSync(astJson);
|
|
35803
35927
|
}
|
|
35804
35928
|
};
|
|
35805
|
-
const jsonToJson =
|
|
35929
|
+
const jsonToJson = (astJson) => {
|
|
35806
35930
|
if (opts.outputFile) {
|
|
35807
35931
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35808
|
-
|
|
35932
|
+
generator.generateSync(astJson);
|
|
35809
35933
|
} else {
|
|
35810
35934
|
const generator = new JsonObjectGenerator(opts);
|
|
35811
|
-
const json =
|
|
35935
|
+
const json = generator.generateSync(astJson);
|
|
35812
35936
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35813
35937
|
}
|
|
35814
35938
|
};
|
|
35815
35939
|
if (isBitmark) {
|
|
35816
|
-
|
|
35940
|
+
bitmarkToBitmark(inStr);
|
|
35817
35941
|
} else {
|
|
35818
35942
|
ast = ast;
|
|
35819
|
-
|
|
35943
|
+
jsonToJson(ast);
|
|
35820
35944
|
}
|
|
35821
35945
|
return res;
|
|
35822
35946
|
}
|
|
@@ -35836,8 +35960,8 @@ var BitmarkParserGenerator = class {
|
|
|
35836
35960
|
const opts = Object.assign({}, options);
|
|
35837
35961
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35838
35962
|
if (env.isNode) {
|
|
35839
|
-
if (
|
|
35840
|
-
inStr =
|
|
35963
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
35964
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35841
35965
|
encoding: "utf8"
|
|
35842
35966
|
});
|
|
35843
35967
|
}
|
|
@@ -35880,7 +36004,7 @@ var BitmarkParserGenerator = class {
|
|
|
35880
36004
|
* void if writing to a file
|
|
35881
36005
|
* @throws Error if any error occurs
|
|
35882
36006
|
*/
|
|
35883
|
-
|
|
36007
|
+
convertText(input, options) {
|
|
35884
36008
|
let res;
|
|
35885
36009
|
let preRes;
|
|
35886
36010
|
const opts = Object.assign({}, options);
|
|
@@ -35894,8 +36018,8 @@ var BitmarkParserGenerator = class {
|
|
|
35894
36018
|
}
|
|
35895
36019
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35896
36020
|
if (env.isNode) {
|
|
35897
|
-
if (
|
|
35898
|
-
inStr =
|
|
36021
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
36022
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35899
36023
|
encoding: "utf8"
|
|
35900
36024
|
});
|
|
35901
36025
|
}
|
|
@@ -35909,7 +36033,7 @@ var BitmarkParserGenerator = class {
|
|
|
35909
36033
|
location: TextLocation.body
|
|
35910
36034
|
});
|
|
35911
36035
|
} else {
|
|
35912
|
-
preRes =
|
|
36036
|
+
preRes = this.textGenerator.generateSync(ast, textFormat, textLocation);
|
|
35913
36037
|
}
|
|
35914
36038
|
if (opts.outputFile) {
|
|
35915
36039
|
const output = opts.outputFile.toString();
|
|
@@ -35918,8 +36042,8 @@ var BitmarkParserGenerator = class {
|
|
|
35918
36042
|
strRes = this.jsonStringifyPrettify(preRes, jsonOptions, true);
|
|
35919
36043
|
}
|
|
35920
36044
|
const flag = fileOptions.append ? "a" : "w";
|
|
35921
|
-
|
|
35922
|
-
|
|
36045
|
+
import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
|
|
36046
|
+
import_fs_extra6.default.writeFileSync(output, strRes, {
|
|
35923
36047
|
flag
|
|
35924
36048
|
});
|
|
35925
36049
|
} else {
|
|
@@ -35961,8 +36085,8 @@ var BitmarkParserGenerator = class {
|
|
|
35961
36085
|
}
|
|
35962
36086
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35963
36087
|
if (env.isNode) {
|
|
35964
|
-
if (
|
|
35965
|
-
inStr =
|
|
36088
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
36089
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
35966
36090
|
encoding: "utf8"
|
|
35967
36091
|
});
|
|
35968
36092
|
}
|
|
@@ -35975,8 +36099,8 @@ var BitmarkParserGenerator = class {
|
|
|
35975
36099
|
if (opts.outputFile) {
|
|
35976
36100
|
const output = opts.outputFile.toString();
|
|
35977
36101
|
const flag = fileOptions.append ? "a" : "w";
|
|
35978
|
-
|
|
35979
|
-
|
|
36102
|
+
import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
|
|
36103
|
+
import_fs_extra6.default.writeFileSync(output, res, {
|
|
35980
36104
|
flag
|
|
35981
36105
|
});
|
|
35982
36106
|
} else {
|
|
@@ -36013,8 +36137,8 @@ var BitmarkParserGenerator = class {
|
|
|
36013
36137
|
}
|
|
36014
36138
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
36015
36139
|
if (env.isNode) {
|
|
36016
|
-
if (
|
|
36017
|
-
inStr =
|
|
36140
|
+
if (import_fs_extra6.default.existsSync(inStr)) {
|
|
36141
|
+
inStr = import_fs_extra6.default.readFileSync(inStr, {
|
|
36018
36142
|
encoding: "utf8"
|
|
36019
36143
|
});
|
|
36020
36144
|
}
|
|
@@ -36027,8 +36151,8 @@ var BitmarkParserGenerator = class {
|
|
|
36027
36151
|
if (opts.outputFile) {
|
|
36028
36152
|
const output = opts.outputFile.toString();
|
|
36029
36153
|
const flag = fileOptions.append ? "a" : "w";
|
|
36030
|
-
|
|
36031
|
-
|
|
36154
|
+
import_fs_extra6.default.ensureDirSync(import_node_path4.default.dirname(output));
|
|
36155
|
+
import_fs_extra6.default.writeFileSync(output, res, {
|
|
36032
36156
|
flag
|
|
36033
36157
|
});
|
|
36034
36158
|
} else {
|