@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.js
CHANGED
|
@@ -1463,12 +1463,12 @@ var StringUtils = class {
|
|
|
1463
1463
|
subLength = width;
|
|
1464
1464
|
rangeStartNext = rangeStart + width;
|
|
1465
1465
|
}
|
|
1466
|
-
subString = str.
|
|
1466
|
+
subString = str.slice(rangeStart, rangeStart + subLength);
|
|
1467
1467
|
rangeStart = rangeStartNext;
|
|
1468
1468
|
result.push(subString.trim());
|
|
1469
1469
|
}
|
|
1470
1470
|
if (rangeStart < len) {
|
|
1471
|
-
subString = str.
|
|
1471
|
+
subString = str.slice(rangeStart);
|
|
1472
1472
|
result.push(subString);
|
|
1473
1473
|
}
|
|
1474
1474
|
return result;
|
|
@@ -1480,6 +1480,7 @@ var StringUtils = class {
|
|
|
1480
1480
|
* @returns the camelCase version of the string
|
|
1481
1481
|
*/
|
|
1482
1482
|
kebabToCamel(str) {
|
|
1483
|
+
if (!str) return str;
|
|
1483
1484
|
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
1484
1485
|
}
|
|
1485
1486
|
};
|
|
@@ -1635,13 +1636,13 @@ var ObjectUtils = class {
|
|
|
1635
1636
|
* @param path the path to the property to set as a dotted string or array or a mix of both
|
|
1636
1637
|
* @returns the value of the property, or undefined if the property does not exist
|
|
1637
1638
|
*/
|
|
1638
|
-
getViaPath(obj,
|
|
1639
|
+
getViaPath(obj, path5) {
|
|
1639
1640
|
if (!obj) return void 0;
|
|
1640
|
-
if (!
|
|
1641
|
-
if (!Array.isArray(
|
|
1642
|
-
|
|
1641
|
+
if (!path5) return void 0;
|
|
1642
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1643
|
+
path5 = path5.flatMap((p) => p.split("."));
|
|
1643
1644
|
let node = obj;
|
|
1644
|
-
for (const key of
|
|
1645
|
+
for (const key of path5) {
|
|
1645
1646
|
if (node == null) return void 0;
|
|
1646
1647
|
node = node[key];
|
|
1647
1648
|
}
|
|
@@ -1657,14 +1658,14 @@ var ObjectUtils = class {
|
|
|
1657
1658
|
* @param create - if true, create plain objects in the path if they do not exist
|
|
1658
1659
|
* @returns true if the value was set, false if the value was not set
|
|
1659
1660
|
*/
|
|
1660
|
-
setViaPath(obj,
|
|
1661
|
+
setViaPath(obj, path5, value, create) {
|
|
1661
1662
|
if (!obj) return false;
|
|
1662
|
-
if (!
|
|
1663
|
-
if (!Array.isArray(
|
|
1664
|
-
|
|
1663
|
+
if (!path5) return false;
|
|
1664
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1665
|
+
path5 = path5.flatMap((p) => p.split("."));
|
|
1665
1666
|
let node = obj;
|
|
1666
|
-
for (let i = 0; i <
|
|
1667
|
-
const key =
|
|
1667
|
+
for (let i = 0; i < path5.length - 1; i++) {
|
|
1668
|
+
const key = path5[i];
|
|
1668
1669
|
if (node[key] == void 0) {
|
|
1669
1670
|
if (create) {
|
|
1670
1671
|
node[key] = {};
|
|
@@ -1674,7 +1675,7 @@ var ObjectUtils = class {
|
|
|
1674
1675
|
}
|
|
1675
1676
|
node = node[key];
|
|
1676
1677
|
}
|
|
1677
|
-
node[
|
|
1678
|
+
node[path5[path5.length - 1]] = value;
|
|
1678
1679
|
return true;
|
|
1679
1680
|
}
|
|
1680
1681
|
/**
|
|
@@ -1721,19 +1722,19 @@ var ObjectUtils = class {
|
|
|
1721
1722
|
* @param path
|
|
1722
1723
|
* @returns
|
|
1723
1724
|
*/
|
|
1724
|
-
flatMapPath(obj,
|
|
1725
|
+
flatMapPath(obj, path5) {
|
|
1725
1726
|
if (!obj) return [];
|
|
1726
|
-
if (!
|
|
1727
|
-
if (!Array.isArray(
|
|
1727
|
+
if (!path5) return [];
|
|
1728
|
+
if (!Array.isArray(path5)) path5 = [path5];
|
|
1728
1729
|
const node = obj;
|
|
1729
|
-
const key =
|
|
1730
|
+
const key = path5.shift();
|
|
1730
1731
|
if (key == null) return node;
|
|
1731
1732
|
const data = node[key];
|
|
1732
1733
|
if (!data) return [];
|
|
1733
1734
|
if (Array.isArray(data)) {
|
|
1734
|
-
return data.flatMap((d) => this.flatMapPath(d,
|
|
1735
|
+
return data.flatMap((d) => this.flatMapPath(d, path5.slice()));
|
|
1735
1736
|
} else {
|
|
1736
|
-
return [this.flatMapPath(data,
|
|
1737
|
+
return [this.flatMapPath(data, path5)].flat();
|
|
1737
1738
|
}
|
|
1738
1739
|
}
|
|
1739
1740
|
// testFlatMapPath() {
|
|
@@ -8879,7 +8880,7 @@ var instance2 = new Config();
|
|
|
8879
8880
|
// src/generated/package_info.ts
|
|
8880
8881
|
var PACKAGE_INFO = {
|
|
8881
8882
|
"name": "@gmb/bitmark-parser-generator",
|
|
8882
|
-
"version": "
|
|
8883
|
+
"version": "4.0.0",
|
|
8883
8884
|
"author": "Get More Brain Ltd",
|
|
8884
8885
|
"license": "ISC",
|
|
8885
8886
|
"description": "A bitmark parser and generator using Peggy.js"
|
|
@@ -20645,8 +20646,10 @@ var NodeValidator = class {
|
|
|
20645
20646
|
if (!valid) {
|
|
20646
20647
|
if (resource.type) {
|
|
20647
20648
|
ret = {
|
|
20648
|
-
type: resource.type
|
|
20649
|
-
|
|
20649
|
+
type: resource.type,
|
|
20650
|
+
__typeAlias: resource.type,
|
|
20651
|
+
__configKey: resource.__configKey,
|
|
20652
|
+
__invalid: true
|
|
20650
20653
|
};
|
|
20651
20654
|
}
|
|
20652
20655
|
}
|
|
@@ -24124,14 +24127,14 @@ var Builder = class extends BaseBuilder {
|
|
|
24124
24127
|
* @param path path for the value
|
|
24125
24128
|
* @param value the value to push down
|
|
24126
24129
|
*/
|
|
24127
|
-
pushDownTree(_context, body, bodyBitTypes, cardNode, cardNodePath,
|
|
24130
|
+
pushDownTree(_context, body, bodyBitTypes, cardNode, cardNodePath, path5, value) {
|
|
24128
24131
|
if (value === void 0) return;
|
|
24129
24132
|
if (cardNode && cardNodePath) {
|
|
24130
24133
|
if (!Array.isArray(cardNodePath)) cardNodePath = [cardNodePath];
|
|
24131
24134
|
const data = objectUtils.flatMapPath(cardNode, cardNodePath);
|
|
24132
24135
|
for (const d of data) {
|
|
24133
|
-
if (d[
|
|
24134
|
-
d[
|
|
24136
|
+
if (d[path5] == null) {
|
|
24137
|
+
d[path5] = value;
|
|
24135
24138
|
}
|
|
24136
24139
|
}
|
|
24137
24140
|
}
|
|
@@ -24145,8 +24148,8 @@ var Builder = class extends BaseBuilder {
|
|
|
24145
24148
|
if (part) {
|
|
24146
24149
|
if (bodyBitTypes.indexOf(part.type) !== -1) {
|
|
24147
24150
|
const data = part;
|
|
24148
|
-
if (data[
|
|
24149
|
-
data[
|
|
24151
|
+
if (data[path5] == null) {
|
|
24152
|
+
data[path5] = value;
|
|
24150
24153
|
}
|
|
24151
24154
|
}
|
|
24152
24155
|
}
|
|
@@ -24339,13 +24342,14 @@ var StringWriter = class {
|
|
|
24339
24342
|
}
|
|
24340
24343
|
writeLine(value) {
|
|
24341
24344
|
if (!this._buffer) return this;
|
|
24345
|
+
let line;
|
|
24342
24346
|
if (value != null) {
|
|
24343
|
-
|
|
24344
|
-
this.lastWrite = value + this.endOfLineString;
|
|
24347
|
+
line = value + this.endOfLineString;
|
|
24345
24348
|
} else {
|
|
24346
|
-
this.
|
|
24347
|
-
this.lastWrite = this.endOfLineString;
|
|
24349
|
+
line = this.endOfLineString;
|
|
24348
24350
|
}
|
|
24351
|
+
this._buffer.push(line);
|
|
24352
|
+
this.lastWrite = line;
|
|
24349
24353
|
return this;
|
|
24350
24354
|
}
|
|
24351
24355
|
writeLines(values, delimiter) {
|
|
@@ -31187,7 +31191,8 @@ function buildResources(context, resourceTypeAttachment, resources) {
|
|
|
31187
31191
|
const countsMax = resourcesConfig.getCountsMax();
|
|
31188
31192
|
if (resources) {
|
|
31189
31193
|
for (const r of resources.reverse()) {
|
|
31190
|
-
|
|
31194
|
+
if (r.__invalid) continue;
|
|
31195
|
+
const configKey = r.__configKey;
|
|
31191
31196
|
let countMin = countsMin.get(configKey) ?? 0;
|
|
31192
31197
|
let countMax = countsMax.get(configKey) ?? 0;
|
|
31193
31198
|
countMin = Math.max(0, countMin - 1);
|
|
@@ -31208,7 +31213,7 @@ function buildResources(context, resourceTypeAttachment, resources) {
|
|
|
31208
31213
|
context.addWarning(warningMsg);
|
|
31209
31214
|
} else if (filteredResources.length === 0 && resourceTypeAttachment) {
|
|
31210
31215
|
context.addWarning(
|
|
31211
|
-
`Resource type [&${resourceTypeAttachment}] is specified in the bit header, but no such
|
|
31216
|
+
`Resource type [&${resourceTypeAttachment}] is specified in the bit header, but no such resource is present`
|
|
31212
31217
|
);
|
|
31213
31218
|
}
|
|
31214
31219
|
if (excessResources.length > 0) {
|
|
@@ -35059,8 +35064,8 @@ var BitmarkParser = class {
|
|
|
35059
35064
|
};
|
|
35060
35065
|
|
|
35061
35066
|
// src/BitmarkParserGenerator.ts
|
|
35062
|
-
import
|
|
35063
|
-
import
|
|
35067
|
+
import path4 from "path";
|
|
35068
|
+
import fs6 from "fs-extra";
|
|
35064
35069
|
|
|
35065
35070
|
// src/ast/writer/FileWriter.ts
|
|
35066
35071
|
import path from "path";
|
|
@@ -35148,13 +35153,13 @@ var FileWriter = class extends StreamWriter {
|
|
|
35148
35153
|
* @param path - path of file to write
|
|
35149
35154
|
* @param options - options for file writing
|
|
35150
35155
|
*/
|
|
35151
|
-
constructor(
|
|
35156
|
+
constructor(path5, options) {
|
|
35152
35157
|
super();
|
|
35153
35158
|
__publicField(this, "_path");
|
|
35154
35159
|
__publicField(this, "_append");
|
|
35155
35160
|
__publicField(this, "_encoding");
|
|
35156
35161
|
const opts = Object.assign({}, options);
|
|
35157
|
-
this._path =
|
|
35162
|
+
this._path = path5;
|
|
35158
35163
|
this._append = !!opts.append;
|
|
35159
35164
|
this._encoding = opts.encoding ?? "utf8";
|
|
35160
35165
|
}
|
|
@@ -35202,6 +35207,118 @@ var FileWriter = class extends StreamWriter {
|
|
|
35202
35207
|
|
|
35203
35208
|
// src/generator/bitmark/BitmarkFileGenerator.ts
|
|
35204
35209
|
import "fs-extra";
|
|
35210
|
+
|
|
35211
|
+
// src/ast/writer/SyncFileWriter.ts
|
|
35212
|
+
import path2 from "path";
|
|
35213
|
+
import fs2 from "fs-extra";
|
|
35214
|
+
import os2 from "os";
|
|
35215
|
+
var SyncFileWriter = class {
|
|
35216
|
+
/**
|
|
35217
|
+
* Create a writer to write to a file.
|
|
35218
|
+
*
|
|
35219
|
+
* @param path - path of file to write
|
|
35220
|
+
* @param options - options for file writing
|
|
35221
|
+
*/
|
|
35222
|
+
constructor(path5, options) {
|
|
35223
|
+
__publicField(this, "_path");
|
|
35224
|
+
__publicField(this, "_append");
|
|
35225
|
+
__publicField(this, "_encoding");
|
|
35226
|
+
__publicField(this, "_open");
|
|
35227
|
+
__publicField(this, "endOfLineString", os2.EOL);
|
|
35228
|
+
__publicField(this, "lastWrite", "");
|
|
35229
|
+
const opts = Object.assign({}, options);
|
|
35230
|
+
this._path = path5;
|
|
35231
|
+
this._append = !!opts.append;
|
|
35232
|
+
this._encoding = opts.encoding ?? "utf8";
|
|
35233
|
+
this._open = false;
|
|
35234
|
+
}
|
|
35235
|
+
get isSync() {
|
|
35236
|
+
return true;
|
|
35237
|
+
}
|
|
35238
|
+
get path() {
|
|
35239
|
+
return this._path;
|
|
35240
|
+
}
|
|
35241
|
+
get append() {
|
|
35242
|
+
return this._append;
|
|
35243
|
+
}
|
|
35244
|
+
get encoding() {
|
|
35245
|
+
return this._encoding;
|
|
35246
|
+
}
|
|
35247
|
+
async open() {
|
|
35248
|
+
this.openSync();
|
|
35249
|
+
return Promise.resolve();
|
|
35250
|
+
}
|
|
35251
|
+
async close() {
|
|
35252
|
+
try {
|
|
35253
|
+
this.closeSync();
|
|
35254
|
+
} catch (e) {
|
|
35255
|
+
return Promise.reject(e);
|
|
35256
|
+
}
|
|
35257
|
+
return Promise.resolve();
|
|
35258
|
+
}
|
|
35259
|
+
openSync() {
|
|
35260
|
+
const flag = this._append ? "a" : "w";
|
|
35261
|
+
fs2.ensureDirSync(path2.dirname(this._path.toString()));
|
|
35262
|
+
fs2.writeFileSync(this._path, "", {
|
|
35263
|
+
flag,
|
|
35264
|
+
encoding: this._encoding
|
|
35265
|
+
});
|
|
35266
|
+
this._open = true;
|
|
35267
|
+
}
|
|
35268
|
+
closeSync() {
|
|
35269
|
+
this._open = false;
|
|
35270
|
+
}
|
|
35271
|
+
writeLine(value) {
|
|
35272
|
+
if (!this._open) return this;
|
|
35273
|
+
let line;
|
|
35274
|
+
if (value != null) {
|
|
35275
|
+
line = value + this.endOfLineString;
|
|
35276
|
+
} else {
|
|
35277
|
+
line = this.endOfLineString;
|
|
35278
|
+
}
|
|
35279
|
+
fs2.appendFileSync(this._path, line, {
|
|
35280
|
+
encoding: this._encoding
|
|
35281
|
+
});
|
|
35282
|
+
this.lastWrite = line;
|
|
35283
|
+
return this;
|
|
35284
|
+
}
|
|
35285
|
+
writeLines(values, delimiter) {
|
|
35286
|
+
if (!this._open) return this;
|
|
35287
|
+
if (!values) return this;
|
|
35288
|
+
let str = "";
|
|
35289
|
+
for (let i = 0, len = values.length; i < len; i++) {
|
|
35290
|
+
const value = values[i];
|
|
35291
|
+
str += value;
|
|
35292
|
+
if (delimiter && i < len - 1) {
|
|
35293
|
+
str += delimiter;
|
|
35294
|
+
}
|
|
35295
|
+
str += this.endOfLineString;
|
|
35296
|
+
}
|
|
35297
|
+
fs2.appendFileSync(this._path, str, {
|
|
35298
|
+
encoding: this._encoding
|
|
35299
|
+
});
|
|
35300
|
+
this.lastWrite = str;
|
|
35301
|
+
return this;
|
|
35302
|
+
}
|
|
35303
|
+
write(value) {
|
|
35304
|
+
if (!this._open) return this;
|
|
35305
|
+
if (value == null) return this;
|
|
35306
|
+
if (value) this.lastWrite = value;
|
|
35307
|
+
fs2.appendFileSync(this._path, value, {
|
|
35308
|
+
encoding: this._encoding
|
|
35309
|
+
});
|
|
35310
|
+
return this;
|
|
35311
|
+
}
|
|
35312
|
+
writeWhiteSpace() {
|
|
35313
|
+
this.write(" ");
|
|
35314
|
+
return this;
|
|
35315
|
+
}
|
|
35316
|
+
getLastWrite() {
|
|
35317
|
+
return this.lastWrite;
|
|
35318
|
+
}
|
|
35319
|
+
};
|
|
35320
|
+
|
|
35321
|
+
// src/generator/bitmark/BitmarkFileGenerator.ts
|
|
35205
35322
|
var BitmarkFileGenerator = class {
|
|
35206
35323
|
/**
|
|
35207
35324
|
* Generate bitmark markup from a bitmark AST as a file
|
|
@@ -35209,9 +35326,11 @@ var BitmarkFileGenerator = class {
|
|
|
35209
35326
|
* @param path - path of file to generate
|
|
35210
35327
|
* @param options - bitmark generation options
|
|
35211
35328
|
*/
|
|
35212
|
-
constructor(
|
|
35329
|
+
constructor(path5, options) {
|
|
35213
35330
|
__publicField(this, "generator");
|
|
35214
|
-
|
|
35331
|
+
__publicField(this, "async");
|
|
35332
|
+
this.async = options?.async ?? false;
|
|
35333
|
+
const writer = this.async ? new FileWriter(path5, options?.fileOptions) : new SyncFileWriter(path5, options?.fileOptions);
|
|
35215
35334
|
this.generator = new BitmarkGenerator(writer, options);
|
|
35216
35335
|
}
|
|
35217
35336
|
/**
|
|
@@ -35228,7 +35347,10 @@ var BitmarkFileGenerator = class {
|
|
|
35228
35347
|
* @param ast bitmark AST
|
|
35229
35348
|
*/
|
|
35230
35349
|
generateSync(_ast) {
|
|
35231
|
-
|
|
35350
|
+
if (this.async) {
|
|
35351
|
+
throw new Error("Sync operation not supported");
|
|
35352
|
+
}
|
|
35353
|
+
this.generator.generateSync(_ast);
|
|
35232
35354
|
}
|
|
35233
35355
|
};
|
|
35234
35356
|
|
|
@@ -35243,9 +35365,11 @@ var JsonFileGenerator = class {
|
|
|
35243
35365
|
* @param fileOptions - file options
|
|
35244
35366
|
* @param bitmarkOptions - bitmark generation options
|
|
35245
35367
|
*/
|
|
35246
|
-
constructor(
|
|
35368
|
+
constructor(path5, options) {
|
|
35247
35369
|
__publicField(this, "generator");
|
|
35248
|
-
|
|
35370
|
+
__publicField(this, "async");
|
|
35371
|
+
this.async = options?.async ?? false;
|
|
35372
|
+
const writer = this.async ? new FileWriter(path5, options?.fileOptions) : new SyncFileWriter(path5, options?.fileOptions);
|
|
35249
35373
|
this.generator = new JsonGenerator(writer, options);
|
|
35250
35374
|
}
|
|
35251
35375
|
/**
|
|
@@ -35262,19 +35386,22 @@ var JsonFileGenerator = class {
|
|
|
35262
35386
|
* @param ast bitmark AST
|
|
35263
35387
|
*/
|
|
35264
35388
|
generateSync(_ast) {
|
|
35265
|
-
|
|
35389
|
+
if (this.async) {
|
|
35390
|
+
throw new Error("Sync operation not supported");
|
|
35391
|
+
}
|
|
35392
|
+
this.generator.generateSync(_ast);
|
|
35266
35393
|
}
|
|
35267
35394
|
};
|
|
35268
35395
|
|
|
35269
35396
|
// src/info/ConfigBuilder.ts
|
|
35270
|
-
import
|
|
35271
|
-
import
|
|
35397
|
+
import path3 from "path";
|
|
35398
|
+
import fs5 from "fs-extra";
|
|
35272
35399
|
var ConfigBuilder = class {
|
|
35273
|
-
|
|
35400
|
+
build(options) {
|
|
35274
35401
|
const opts = Object.assign({}, options);
|
|
35275
|
-
|
|
35402
|
+
this.buildFlat(opts);
|
|
35276
35403
|
}
|
|
35277
|
-
|
|
35404
|
+
buildFlat(options) {
|
|
35278
35405
|
const opts = Object.assign({}, options);
|
|
35279
35406
|
const bitConfigs = [];
|
|
35280
35407
|
for (const bt of BitType.values()) {
|
|
@@ -35283,9 +35410,8 @@ var ConfigBuilder = class {
|
|
|
35283
35410
|
if (bitConfig) bitConfigs.push(bitConfig);
|
|
35284
35411
|
}
|
|
35285
35412
|
const outputFolder = opts.outputDir ?? "assets/config";
|
|
35286
|
-
const outputFolderBits =
|
|
35287
|
-
|
|
35288
|
-
const fileWrites = [];
|
|
35413
|
+
const outputFolderBits = path3.join(outputFolder, "bits_flat");
|
|
35414
|
+
fs5.ensureDirSync(outputFolderBits);
|
|
35289
35415
|
for (const b of bitConfigs) {
|
|
35290
35416
|
const inherits = [];
|
|
35291
35417
|
const tags2 = [];
|
|
@@ -35418,11 +35544,10 @@ var ConfigBuilder = class {
|
|
|
35418
35544
|
resourceAttachmentAllowed: b.resourceAttachmentAllowed ?? true,
|
|
35419
35545
|
tags: tags2
|
|
35420
35546
|
};
|
|
35421
|
-
const output =
|
|
35547
|
+
const output = path3.join(outputFolderBits, `${b.bitType}.jsonc`);
|
|
35422
35548
|
const str = JSON.stringify(bitJson, null, 2);
|
|
35423
|
-
|
|
35549
|
+
fs5.writeFileSync(output, str);
|
|
35424
35550
|
}
|
|
35425
|
-
await Promise.all(fileWrites);
|
|
35426
35551
|
}
|
|
35427
35552
|
};
|
|
35428
35553
|
|
|
@@ -35534,11 +35659,10 @@ var BitmarkParserGenerator = class {
|
|
|
35534
35659
|
/**
|
|
35535
35660
|
* Generate the new configuration for the bitmark parser.
|
|
35536
35661
|
*/
|
|
35537
|
-
|
|
35662
|
+
generateConfig(options) {
|
|
35538
35663
|
const opts = Object.assign({}, options);
|
|
35539
35664
|
const builder3 = new ConfigBuilder();
|
|
35540
|
-
|
|
35541
|
-
return void 0;
|
|
35665
|
+
builder3.build(opts);
|
|
35542
35666
|
}
|
|
35543
35667
|
/**
|
|
35544
35668
|
* Convert bitmark from bitmark to JSON, or JSON to bitmark.
|
|
@@ -35562,11 +35686,11 @@ var BitmarkParserGenerator = class {
|
|
|
35562
35686
|
* @param input - bitmark or JSON or AST as a string, JSON or AST as plain JS object, or path to a file containing
|
|
35563
35687
|
* bitmark, JSON, or AST.
|
|
35564
35688
|
* @param options - the conversion options
|
|
35565
|
-
* @returns
|
|
35689
|
+
* @returns A string if converting to bitmark, a plain JS object if converting to JSON, or
|
|
35566
35690
|
* void if writing to a file
|
|
35567
35691
|
* @throws Error if any error occurs
|
|
35568
35692
|
*/
|
|
35569
|
-
|
|
35693
|
+
convert(input, options) {
|
|
35570
35694
|
let res;
|
|
35571
35695
|
const opts = Object.assign({}, options);
|
|
35572
35696
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
@@ -35581,8 +35705,8 @@ var BitmarkParserGenerator = class {
|
|
|
35581
35705
|
}
|
|
35582
35706
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35583
35707
|
if (env.isNode) {
|
|
35584
|
-
if (
|
|
35585
|
-
inStr =
|
|
35708
|
+
if (fs6.existsSync(inStr)) {
|
|
35709
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35586
35710
|
encoding: "utf8"
|
|
35587
35711
|
});
|
|
35588
35712
|
}
|
|
@@ -35595,92 +35719,92 @@ var BitmarkParserGenerator = class {
|
|
|
35595
35719
|
}
|
|
35596
35720
|
const isJson = !!ast?.bits;
|
|
35597
35721
|
const isBitmark = !isJson && !isAst;
|
|
35598
|
-
const bitmarkToBitmark =
|
|
35599
|
-
|
|
35600
|
-
|
|
35722
|
+
const bitmarkToBitmark = (bitmarkStr) => {
|
|
35723
|
+
bitmarkToAst(bitmarkStr);
|
|
35724
|
+
astToBitmark(res);
|
|
35601
35725
|
};
|
|
35602
|
-
const bitmarkToAst =
|
|
35726
|
+
const bitmarkToAst = (bitmarkStr) => {
|
|
35603
35727
|
res = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35604
35728
|
parserType: bitmarkParserType
|
|
35605
35729
|
});
|
|
35606
35730
|
};
|
|
35607
|
-
const bitmarkToJson =
|
|
35731
|
+
const bitmarkToJson = (bitmarkStr) => {
|
|
35608
35732
|
if (bitmarkParserType === BitmarkParserType.peggy) {
|
|
35609
35733
|
ast = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35610
35734
|
parserType: bitmarkParserType
|
|
35611
35735
|
});
|
|
35612
35736
|
if (opts.outputFile) {
|
|
35613
35737
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35614
|
-
|
|
35738
|
+
generator.generateSync(ast);
|
|
35615
35739
|
} else {
|
|
35616
35740
|
const generator = new JsonObjectGenerator(opts);
|
|
35617
|
-
const json =
|
|
35741
|
+
const json = generator.generateSync(ast);
|
|
35618
35742
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35619
35743
|
}
|
|
35620
35744
|
}
|
|
35621
35745
|
};
|
|
35622
|
-
const astToBitmark =
|
|
35746
|
+
const astToBitmark = (astJson) => {
|
|
35623
35747
|
if (opts.outputFile) {
|
|
35624
35748
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35625
|
-
|
|
35749
|
+
generator.generateSync(astJson);
|
|
35626
35750
|
} else {
|
|
35627
35751
|
const generator = new BitmarkStringGenerator(opts);
|
|
35628
|
-
res =
|
|
35752
|
+
res = generator.generateSync(astJson);
|
|
35629
35753
|
}
|
|
35630
35754
|
};
|
|
35631
|
-
const astToAst =
|
|
35755
|
+
const astToAst = (astJson) => {
|
|
35632
35756
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
35633
35757
|
};
|
|
35634
|
-
const astToJson =
|
|
35758
|
+
const astToJson = (astJson) => {
|
|
35635
35759
|
if (opts.outputFile) {
|
|
35636
35760
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35637
|
-
|
|
35761
|
+
generator.generateSync(astJson);
|
|
35638
35762
|
} else {
|
|
35639
35763
|
const generator = new JsonObjectGenerator(opts);
|
|
35640
|
-
const json =
|
|
35764
|
+
const json = generator.generateSync(astJson);
|
|
35641
35765
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35642
35766
|
}
|
|
35643
35767
|
};
|
|
35644
|
-
const jsonToBitmark =
|
|
35768
|
+
const jsonToBitmark = (astJson) => {
|
|
35645
35769
|
if (opts.outputFile) {
|
|
35646
35770
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35647
|
-
|
|
35771
|
+
generator.generateSync(astJson);
|
|
35648
35772
|
} else {
|
|
35649
35773
|
const generator = new BitmarkStringGenerator(opts);
|
|
35650
|
-
res =
|
|
35774
|
+
res = generator.generateSync(astJson);
|
|
35651
35775
|
}
|
|
35652
35776
|
};
|
|
35653
|
-
const jsonToAst =
|
|
35777
|
+
const jsonToAst = (astJson) => {
|
|
35654
35778
|
res = this.jsonStringifyPrettify(astJson, jsonOptions);
|
|
35655
35779
|
};
|
|
35656
|
-
const jsonToJson =
|
|
35657
|
-
|
|
35780
|
+
const jsonToJson = (astJson) => {
|
|
35781
|
+
astToJson(astJson);
|
|
35658
35782
|
};
|
|
35659
35783
|
if (isBitmark) {
|
|
35660
35784
|
if (outputBitmark) {
|
|
35661
|
-
|
|
35785
|
+
bitmarkToBitmark(inStr);
|
|
35662
35786
|
} else if (outputAst) {
|
|
35663
|
-
|
|
35787
|
+
bitmarkToAst(inStr);
|
|
35664
35788
|
} else {
|
|
35665
|
-
|
|
35789
|
+
bitmarkToJson(inStr);
|
|
35666
35790
|
}
|
|
35667
35791
|
} else if (isAst) {
|
|
35668
35792
|
ast = ast;
|
|
35669
35793
|
if (outputAst) {
|
|
35670
|
-
|
|
35794
|
+
astToAst(ast);
|
|
35671
35795
|
} else if (outputJson) {
|
|
35672
|
-
|
|
35796
|
+
astToJson(ast);
|
|
35673
35797
|
} else {
|
|
35674
|
-
|
|
35798
|
+
astToBitmark(ast);
|
|
35675
35799
|
}
|
|
35676
35800
|
} else {
|
|
35677
35801
|
ast = ast;
|
|
35678
35802
|
if (outputJson) {
|
|
35679
|
-
|
|
35803
|
+
jsonToJson(ast);
|
|
35680
35804
|
} else if (outputAst) {
|
|
35681
|
-
|
|
35805
|
+
jsonToAst(ast);
|
|
35682
35806
|
} else {
|
|
35683
|
-
|
|
35807
|
+
jsonToBitmark(ast);
|
|
35684
35808
|
}
|
|
35685
35809
|
}
|
|
35686
35810
|
return res;
|
|
@@ -35710,7 +35834,7 @@ var BitmarkParserGenerator = class {
|
|
|
35710
35834
|
* void if writing to a file
|
|
35711
35835
|
* @throws Error if any error occurs
|
|
35712
35836
|
*/
|
|
35713
|
-
|
|
35837
|
+
upgrade(input, options) {
|
|
35714
35838
|
let res;
|
|
35715
35839
|
const opts = Object.assign({}, options);
|
|
35716
35840
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
@@ -35721,8 +35845,8 @@ var BitmarkParserGenerator = class {
|
|
|
35721
35845
|
}
|
|
35722
35846
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35723
35847
|
if (env.isNode) {
|
|
35724
|
-
if (
|
|
35725
|
-
inStr =
|
|
35848
|
+
if (fs6.existsSync(inStr)) {
|
|
35849
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35726
35850
|
encoding: "utf8"
|
|
35727
35851
|
});
|
|
35728
35852
|
}
|
|
@@ -35731,33 +35855,33 @@ var BitmarkParserGenerator = class {
|
|
|
35731
35855
|
let ast = this.jsonParser.toAst(inStr);
|
|
35732
35856
|
const isJson = !!ast?.bits;
|
|
35733
35857
|
const isBitmark = !isJson;
|
|
35734
|
-
const bitmarkToBitmark =
|
|
35858
|
+
const bitmarkToBitmark = (bitmarkStr) => {
|
|
35735
35859
|
const astJson = this.bitmarkParser.toAst(bitmarkStr, {
|
|
35736
35860
|
parserType: bitmarkParserType
|
|
35737
35861
|
});
|
|
35738
35862
|
if (opts.outputFile) {
|
|
35739
35863
|
const generator = new BitmarkFileGenerator(opts.outputFile, opts);
|
|
35740
|
-
|
|
35864
|
+
generator.generateSync(astJson);
|
|
35741
35865
|
} else {
|
|
35742
35866
|
const generator = new BitmarkStringGenerator(opts);
|
|
35743
|
-
res =
|
|
35867
|
+
res = generator.generateSync(astJson);
|
|
35744
35868
|
}
|
|
35745
35869
|
};
|
|
35746
|
-
const jsonToJson =
|
|
35870
|
+
const jsonToJson = (astJson) => {
|
|
35747
35871
|
if (opts.outputFile) {
|
|
35748
35872
|
const generator = new JsonFileGenerator(opts.outputFile, opts);
|
|
35749
|
-
|
|
35873
|
+
generator.generateSync(astJson);
|
|
35750
35874
|
} else {
|
|
35751
35875
|
const generator = new JsonObjectGenerator(opts);
|
|
35752
|
-
const json =
|
|
35876
|
+
const json = generator.generateSync(astJson);
|
|
35753
35877
|
res = this.jsonStringifyPrettify(json, jsonOptions);
|
|
35754
35878
|
}
|
|
35755
35879
|
};
|
|
35756
35880
|
if (isBitmark) {
|
|
35757
|
-
|
|
35881
|
+
bitmarkToBitmark(inStr);
|
|
35758
35882
|
} else {
|
|
35759
35883
|
ast = ast;
|
|
35760
|
-
|
|
35884
|
+
jsonToJson(ast);
|
|
35761
35885
|
}
|
|
35762
35886
|
return res;
|
|
35763
35887
|
}
|
|
@@ -35777,8 +35901,8 @@ var BitmarkParserGenerator = class {
|
|
|
35777
35901
|
const opts = Object.assign({}, options);
|
|
35778
35902
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35779
35903
|
if (env.isNode) {
|
|
35780
|
-
if (
|
|
35781
|
-
inStr =
|
|
35904
|
+
if (fs6.existsSync(inStr)) {
|
|
35905
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35782
35906
|
encoding: "utf8"
|
|
35783
35907
|
});
|
|
35784
35908
|
}
|
|
@@ -35821,7 +35945,7 @@ var BitmarkParserGenerator = class {
|
|
|
35821
35945
|
* void if writing to a file
|
|
35822
35946
|
* @throws Error if any error occurs
|
|
35823
35947
|
*/
|
|
35824
|
-
|
|
35948
|
+
convertText(input, options) {
|
|
35825
35949
|
let res;
|
|
35826
35950
|
let preRes;
|
|
35827
35951
|
const opts = Object.assign({}, options);
|
|
@@ -35835,8 +35959,8 @@ var BitmarkParserGenerator = class {
|
|
|
35835
35959
|
}
|
|
35836
35960
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35837
35961
|
if (env.isNode) {
|
|
35838
|
-
if (
|
|
35839
|
-
inStr =
|
|
35962
|
+
if (fs6.existsSync(inStr)) {
|
|
35963
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35840
35964
|
encoding: "utf8"
|
|
35841
35965
|
});
|
|
35842
35966
|
}
|
|
@@ -35850,7 +35974,7 @@ var BitmarkParserGenerator = class {
|
|
|
35850
35974
|
location: TextLocation.body
|
|
35851
35975
|
});
|
|
35852
35976
|
} else {
|
|
35853
|
-
preRes =
|
|
35977
|
+
preRes = this.textGenerator.generateSync(ast, textFormat, textLocation);
|
|
35854
35978
|
}
|
|
35855
35979
|
if (opts.outputFile) {
|
|
35856
35980
|
const output = opts.outputFile.toString();
|
|
@@ -35859,8 +35983,8 @@ var BitmarkParserGenerator = class {
|
|
|
35859
35983
|
strRes = this.jsonStringifyPrettify(preRes, jsonOptions, true);
|
|
35860
35984
|
}
|
|
35861
35985
|
const flag = fileOptions.append ? "a" : "w";
|
|
35862
|
-
|
|
35863
|
-
|
|
35986
|
+
fs6.ensureDirSync(path4.dirname(output));
|
|
35987
|
+
fs6.writeFileSync(output, strRes, {
|
|
35864
35988
|
flag
|
|
35865
35989
|
});
|
|
35866
35990
|
} else {
|
|
@@ -35902,8 +36026,8 @@ var BitmarkParserGenerator = class {
|
|
|
35902
36026
|
}
|
|
35903
36027
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35904
36028
|
if (env.isNode) {
|
|
35905
|
-
if (
|
|
35906
|
-
inStr =
|
|
36029
|
+
if (fs6.existsSync(inStr)) {
|
|
36030
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35907
36031
|
encoding: "utf8"
|
|
35908
36032
|
});
|
|
35909
36033
|
}
|
|
@@ -35916,8 +36040,8 @@ var BitmarkParserGenerator = class {
|
|
|
35916
36040
|
if (opts.outputFile) {
|
|
35917
36041
|
const output = opts.outputFile.toString();
|
|
35918
36042
|
const flag = fileOptions.append ? "a" : "w";
|
|
35919
|
-
|
|
35920
|
-
|
|
36043
|
+
fs6.ensureDirSync(path4.dirname(output));
|
|
36044
|
+
fs6.writeFileSync(output, res, {
|
|
35921
36045
|
flag
|
|
35922
36046
|
});
|
|
35923
36047
|
} else {
|
|
@@ -35954,8 +36078,8 @@ var BitmarkParserGenerator = class {
|
|
|
35954
36078
|
}
|
|
35955
36079
|
if (!opts.inputFormat || opts.inputFormat === Input.file) {
|
|
35956
36080
|
if (env.isNode) {
|
|
35957
|
-
if (
|
|
35958
|
-
inStr =
|
|
36081
|
+
if (fs6.existsSync(inStr)) {
|
|
36082
|
+
inStr = fs6.readFileSync(inStr, {
|
|
35959
36083
|
encoding: "utf8"
|
|
35960
36084
|
});
|
|
35961
36085
|
}
|
|
@@ -35968,8 +36092,8 @@ var BitmarkParserGenerator = class {
|
|
|
35968
36092
|
if (opts.outputFile) {
|
|
35969
36093
|
const output = opts.outputFile.toString();
|
|
35970
36094
|
const flag = fileOptions.append ? "a" : "w";
|
|
35971
|
-
|
|
35972
|
-
|
|
36095
|
+
fs6.ensureDirSync(path4.dirname(output));
|
|
36096
|
+
fs6.writeFileSync(output, res, {
|
|
35973
36097
|
flag
|
|
35974
36098
|
});
|
|
35975
36099
|
} else {
|