@traqula/core 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/AstCoreFactory.js +136 -149
- package/dist/cjs/lib/AstCoreFactory.js.map +1 -0
- package/dist/cjs/lib/generator-builder/builderTypes.js +2 -15
- package/dist/cjs/lib/generator-builder/builderTypes.js.map +1 -0
- package/dist/cjs/lib/generator-builder/dynamicGenerator.js +189 -200
- package/dist/cjs/lib/generator-builder/dynamicGenerator.js.map +1 -0
- package/dist/cjs/lib/generator-builder/generatorBuilder.js +103 -117
- package/dist/cjs/lib/generator-builder/generatorBuilder.js.map +1 -0
- package/dist/cjs/lib/generator-builder/generatorTypes.js +2 -15
- package/dist/cjs/lib/generator-builder/generatorTypes.js.map +1 -0
- package/dist/cjs/lib/index.js +39 -57
- package/dist/cjs/lib/index.js.map +1 -0
- package/dist/cjs/lib/indirection-builder/IndirBuilder.js +63 -85
- package/dist/cjs/lib/indirection-builder/IndirBuilder.js.map +1 -0
- package/dist/cjs/lib/indirection-builder/dynamicIndirected.js +28 -50
- package/dist/cjs/lib/indirection-builder/dynamicIndirected.js.map +1 -0
- package/dist/cjs/lib/indirection-builder/helpers.js +11 -31
- package/dist/cjs/lib/indirection-builder/helpers.js.map +1 -0
- package/dist/cjs/lib/lexer-builder/LexerBuilder.js +92 -114
- package/dist/cjs/lib/lexer-builder/LexerBuilder.js.map +1 -0
- package/dist/cjs/lib/parser-builder/builderTypes.js +2 -15
- package/dist/cjs/lib/parser-builder/builderTypes.js.map +1 -0
- package/dist/cjs/lib/parser-builder/dynamicParser.js +115 -136
- package/dist/cjs/lib/parser-builder/dynamicParser.js.map +1 -0
- package/dist/cjs/lib/parser-builder/parserBuilder.js +167 -169
- package/dist/cjs/lib/parser-builder/parserBuilder.js.map +1 -0
- package/dist/cjs/lib/parser-builder/ruleDefTypes.js +2 -15
- package/dist/cjs/lib/parser-builder/ruleDefTypes.js.map +1 -0
- package/dist/cjs/lib/transformers/TransformerObject.js +196 -198
- package/dist/cjs/lib/transformers/TransformerObject.js.map +1 -0
- package/dist/cjs/lib/transformers/TransformerSubTyped.js +120 -141
- package/dist/cjs/lib/transformers/TransformerSubTyped.js.map +1 -0
- package/dist/cjs/lib/transformers/TransformerTyped.js +99 -120
- package/dist/cjs/lib/transformers/TransformerTyped.js.map +1 -0
- package/dist/cjs/lib/types.js +2 -15
- package/dist/cjs/lib/types.js.map +1 -0
- package/dist/cjs/lib/utils.js +13 -34
- package/dist/cjs/lib/utils.js.map +1 -0
- package/package.json +9 -9
- package/dist/cjs/test/generatorBuilder/generatorBuilder.types.test.js +0 -30
- package/dist/cjs/test/grammar-builder/parserBuilder.types.test.js +0 -27
- package/dist/cjs/test/transformer.test.js +0 -82
- package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.d.ts +0 -1
- package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js +0 -38
- package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js.map +0 -1
- package/dist/esm/test/grammar-builder/parserBuilder.types.test.d.ts +0 -1
- package/dist/esm/test/grammar-builder/parserBuilder.types.test.js +0 -38
- package/dist/esm/test/grammar-builder/parserBuilder.types.test.js.map +0 -1
- package/dist/esm/test/transformer.test.d.ts +0 -1
- package/dist/esm/test/transformer.test.js +0 -82
- package/dist/esm/test/transformer.test.js.map +0 -1
|
@@ -1,152 +1,139 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var AstCoreFactory_exports = {};
|
|
20
|
-
__export(AstCoreFactory_exports, {
|
|
21
|
-
AstCoreFactory: () => AstCoreFactory
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(AstCoreFactory_exports);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AstCoreFactory = void 0;
|
|
24
4
|
class AstCoreFactory {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
5
|
+
wrap(val, loc) {
|
|
6
|
+
return { val, loc };
|
|
7
|
+
}
|
|
8
|
+
isLocalized(obj) {
|
|
9
|
+
return typeof obj === 'object' && obj !== null && 'loc' in obj &&
|
|
10
|
+
typeof obj.loc === 'object' && obj.loc !== null && 'sourceLocationType' in obj.loc;
|
|
11
|
+
}
|
|
12
|
+
sourceLocation(...elements) {
|
|
13
|
+
const pureElements = elements.filter(x => x !== undefined);
|
|
14
|
+
if (pureElements.length === 0) {
|
|
15
|
+
return this.sourceLocationNoMaterialize();
|
|
16
|
+
}
|
|
17
|
+
const filtered = pureElements.filter(element => !this.isLocalized(element) || this.isSourceLocationSource(element.loc) ||
|
|
18
|
+
this.isSourceLocationStringReplace(element.loc) || this.isSourceLocationNodeReplace(element.loc));
|
|
19
|
+
if (filtered.length === 0) {
|
|
20
|
+
return this.gen();
|
|
21
|
+
}
|
|
22
|
+
const first = filtered.at(0);
|
|
23
|
+
const last = filtered.at(-1);
|
|
24
|
+
return {
|
|
25
|
+
sourceLocationType: 'source',
|
|
26
|
+
start: this.isLocalized(first) ?
|
|
27
|
+
first.loc.start :
|
|
28
|
+
first.startOffset,
|
|
29
|
+
end: this.isLocalized(last) ?
|
|
30
|
+
last.loc.end :
|
|
31
|
+
(last.endOffset + 1),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
sourceLocationNoMaterialize() {
|
|
35
|
+
return { sourceLocationType: 'noMaterialize' };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns a copy of the argument that is not materialized
|
|
39
|
+
*/
|
|
40
|
+
dematerialized(arg) {
|
|
41
|
+
return { ...arg, loc: this.sourceLocationNoMaterialize() };
|
|
42
|
+
}
|
|
43
|
+
safeObjectTransform(value, mapper) {
|
|
44
|
+
if (value && typeof value === 'object') {
|
|
45
|
+
// If you wonder why this is all so hard, this is the reason. We cannot lose the methods of our Array objects
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return value.map(x => this.safeObjectTransform(x, mapper));
|
|
48
|
+
}
|
|
49
|
+
return mapper(value);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
forcedAutoGenTree(obj) {
|
|
54
|
+
const copy = { ...obj };
|
|
55
|
+
for (const [key, value] of Object.entries(copy)) {
|
|
56
|
+
copy[key] = this.safeObjectTransform(value, obj => this.forcedAutoGenTree(obj));
|
|
57
|
+
}
|
|
58
|
+
if (this.isLocalized(copy)) {
|
|
59
|
+
copy.loc = this.gen();
|
|
60
|
+
}
|
|
61
|
+
return copy;
|
|
62
|
+
}
|
|
63
|
+
forceMaterialized(arg) {
|
|
64
|
+
if (this.isSourceLocationNoMaterialize(arg.loc)) {
|
|
65
|
+
return this.forcedAutoGenTree(arg);
|
|
66
|
+
}
|
|
67
|
+
return { ...arg };
|
|
68
|
+
}
|
|
69
|
+
isSourceLocation(loc) {
|
|
70
|
+
return 'sourceLocationType' in loc;
|
|
71
|
+
}
|
|
72
|
+
sourceLocationSource(start, end) {
|
|
73
|
+
return {
|
|
74
|
+
sourceLocationType: 'source',
|
|
75
|
+
start,
|
|
76
|
+
end,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
gen() {
|
|
80
|
+
return { sourceLocationType: 'autoGenerate' };
|
|
81
|
+
}
|
|
82
|
+
isSourceLocationSource(loc) {
|
|
83
|
+
return this.isSourceLocation(loc) && loc.sourceLocationType === 'source';
|
|
84
|
+
}
|
|
85
|
+
isSourceLocationStringReplace(loc) {
|
|
86
|
+
return this.isSourceLocation(loc) && loc.sourceLocationType === 'stringReplace';
|
|
87
|
+
}
|
|
88
|
+
sourceLocationNodeReplaceUnsafe(loc) {
|
|
89
|
+
if (this.isSourceLocationSource(loc)) {
|
|
90
|
+
return this.sourceLocationNodeReplace(loc);
|
|
91
|
+
}
|
|
92
|
+
throw new Error('not possible');
|
|
93
|
+
}
|
|
94
|
+
sourceLocationNodeReplace(startOrLoc, end) {
|
|
95
|
+
let starting;
|
|
96
|
+
let ending;
|
|
97
|
+
if (typeof startOrLoc === 'number') {
|
|
98
|
+
starting = startOrLoc;
|
|
99
|
+
ending = end;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
starting = startOrLoc.start;
|
|
103
|
+
ending = startOrLoc.end;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
sourceLocationType: 'nodeReplace',
|
|
107
|
+
start: starting,
|
|
108
|
+
end: ending,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
isSourceLocationNodeReplace(loc) {
|
|
112
|
+
return this.isSourceLocation(loc) && loc.sourceLocationType === 'nodeReplace';
|
|
113
|
+
}
|
|
114
|
+
isSourceLocationNodeAutoGenerate(loc) {
|
|
115
|
+
return this.isSourceLocation(loc) && loc.sourceLocationType === 'autoGenerate';
|
|
116
|
+
}
|
|
117
|
+
nodeShouldPrint(node) {
|
|
118
|
+
return this.isSourceLocationNodeReplace(node.loc) ||
|
|
119
|
+
this.isSourceLocationNodeAutoGenerate(node.loc);
|
|
120
|
+
}
|
|
121
|
+
printFilter(node, callback) {
|
|
122
|
+
if (this.nodeShouldPrint(node)) {
|
|
123
|
+
callback();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
isSourceLocationNoMaterialize(loc) {
|
|
127
|
+
return this.isSourceLocation(loc) && loc.sourceLocationType === 'noMaterialize';
|
|
128
|
+
}
|
|
129
|
+
isOfType(obj, type) {
|
|
130
|
+
const casted = obj;
|
|
131
|
+
return casted.type === type;
|
|
132
|
+
}
|
|
133
|
+
isOfSubType(obj, type, subType) {
|
|
134
|
+
const temp = obj;
|
|
135
|
+
return temp.type === type && temp.subType === subType;
|
|
136
|
+
}
|
|
148
137
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
AstCoreFactory
|
|
152
|
-
});
|
|
138
|
+
exports.AstCoreFactory = AstCoreFactory;
|
|
139
|
+
//# sourceMappingURL=AstCoreFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AstCoreFactory.js","sourceRoot":"","sources":["../../../lib/AstCoreFactory.ts"],"names":[],"mappings":";;;AAgBA,MAAa,cAAc;IAClB,IAAI,CAAI,GAAM,EAAE,GAAmB;QACxC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACtB,CAAC;IAEM,WAAW,CAAC,GAAY;QAC7B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG;YAC5D,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI,IAAI,oBAAoB,IAAI,GAAG,CAAC,GAAG,CAAC;IACvF,CAAC;IAEM,cAAc,CAAC,GAAG,QAA4C;QACnE,M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CAAC,GAAW;QAC5C,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,kBAAkB,KAAK,aAAa,CAAC;IAChF,CAAC;IAEM,gCAAgC,CAAC,GAAW;QACjD,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,kBAAkB,KAAK,cAAc,CAAC;IACjF,CAAC;IAEM,eAAe,CAAC,IAAe;QACpC,OAAO,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,GAAG,CAAC;YAC/C,IAAI,CAAC,gCAAgC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpD,CAAC;IAEM,WAAW,CAAC,IAAe,EAAE,QAAoB;QACtD,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAEM,6BAA6B,CAAC,GAAW;QAC9C,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,kBAAkB,KAAK,eAAe,CAAC;IAClF,CAAC;IAEM,QAAQ,CAAsB,GAAW,EAAE,IAAU;QAC1D,MAAM,MAAM,GAAmB,GAAG,CAAC;QACnC,OAAO,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC;IAC9B,CAAC;IAEM,WAAW,CAA8C,GAAW,EAAE,IAAU,EAAE,OAAgB;QAEvG,MAAM,IAAI,GAA0C,GAAG,CAAC;QACxD,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC;IACxD,CAAC;CACF;AA7JD,wCA6JC","sourcesContent":["import type { IToken } from '@traqula/chevrotain';\n\nimport type {\n SourceLocation,\n SourceLocationNodeAutoGenerate,\n SourceLocationNodeReplace,\n SourceLocationNoMaterialize,\n SourceLocationSource,\n SourceLocationStringReplace,\n Node,\n Localized,\n Wrap,\n Typed,\n SubTyped,\n} from './types.js';\n\nexport class AstCoreFactory {\n public wrap<T>(val: T, loc: SourceLocation): Wrap<T> {\n return { val, loc };\n }\n\n public isLocalized(obj: unknown): obj is Localized {\n return typeof obj === 'object' && obj !== null && 'loc' in obj &&\n typeof obj.loc === 'object' && obj.loc !== null && 'sourceLocationType' in obj.loc;\n }\n\n public sourceLocation(...elements: (undefined | IToken | Localized)[]): SourceLocation {\n const pureElements = elements.filter(x => x !== undefined);\n if (pureElements.length === 0) {\n return this.sourceLocationNoMaterialize();\n }\n const filtered = pureElements.filter(element =>\n !this.isLocalized(element) || this.isSourceLocationSource(element.loc) ||\n this.isSourceLocationStringReplace(element.loc) || this.isSourceLocationNodeReplace(element.loc));\n if (filtered.length === 0) {\n return this.gen();\n }\n const first = filtered.at(0)!;\n const last = filtered.at(-1)!;\n return {\n sourceLocationType: 'source',\n start: this.isLocalized(first) ?\n (<SourceLocationSource | SourceLocationStringReplace> first.loc).start :\n first.startOffset,\n end: this.isLocalized(last) ?\n (<SourceLocationSource | SourceLocationStringReplace> last.loc).end :\n (last.endOffset! + 1),\n };\n }\n\n public sourceLocationNoMaterialize(): SourceLocationNoMaterialize {\n return { sourceLocationType: 'noMaterialize' };\n }\n\n /**\n * Returns a copy of the argument that is not materialized\n */\n public dematerialized<T extends Node>(arg: T): T & { loc: SourceLocationNoMaterialize } {\n return { ...arg, loc: this.sourceLocationNoMaterialize() };\n }\n\n public safeObjectTransform(value: unknown, mapper: (some: object) => any): any {\n if (value && typeof value === 'object') {\n // If you wonder why this is all so hard, this is the reason. We cannot lose the methods of our Array objects\n if (Array.isArray(value)) {\n return value.map(x => this.safeObjectTransform(x, mapper));\n }\n return mapper(value);\n }\n return value;\n }\n\n public forcedAutoGenTree<T extends object>(obj: T): T {\n const copy = { ...obj };\n for (const [ key, value ] of Object.entries(copy)) {\n (<Record<string, object>> copy)[key] = this.safeObjectTransform(value, obj => this.forcedAutoGenTree(obj));\n }\n if (this.isLocalized(copy)) {\n copy.loc = this.gen();\n }\n return copy;\n }\n\n public forceMaterialized<T extends Node>(arg: T): T {\n if (this.isSourceLocationNoMaterialize(arg.loc)) {\n return this.forcedAutoGenTree(arg);\n }\n return { ...arg };\n }\n\n public isSourceLocation(loc: object): loc is SourceLocation {\n return 'sourceLocationType' in loc;\n }\n\n public sourceLocationSource(start: number, end: number): SourceLocationSource {\n return {\n sourceLocationType: 'source',\n start,\n end,\n };\n }\n\n public gen(): SourceLocationNodeAutoGenerate {\n return { sourceLocationType: 'autoGenerate' };\n }\n\n public isSourceLocationSource(loc: object): loc is SourceLocationSource {\n return this.isSourceLocation(loc) && loc.sourceLocationType === 'source';\n }\n\n public isSourceLocationStringReplace(loc: object): loc is SourceLocationStringReplace {\n return this.isSourceLocation(loc) && loc.sourceLocationType === 'stringReplace';\n }\n\n public sourceLocationNodeReplaceUnsafe(loc: SourceLocation): SourceLocationNodeReplace {\n if (this.isSourceLocationSource(loc)) {\n return this.sourceLocationNodeReplace(loc);\n }\n throw new Error('not possible');\n }\n\n public sourceLocationNodeReplace(location: SourceLocationSource): SourceLocationNodeReplace;\n public sourceLocationNodeReplace(start: number, end: number): SourceLocationNodeReplace;\n public sourceLocationNodeReplace(startOrLoc: number | SourceLocationSource, end?: number): SourceLocationNodeReplace {\n let starting;\n let ending;\n if (typeof startOrLoc === 'number') {\n starting = startOrLoc;\n ending = end!;\n } else {\n starting = startOrLoc.start;\n ending = startOrLoc.end;\n }\n return {\n sourceLocationType: 'nodeReplace',\n start: starting,\n end: ending,\n };\n }\n\n public isSourceLocationNodeReplace(loc: object): loc is SourceLocationNodeReplace {\n return this.isSourceLocation(loc) && loc.sourceLocationType === 'nodeReplace';\n }\n\n public isSourceLocationNodeAutoGenerate(loc: object): loc is SourceLocationNodeAutoGenerate {\n return this.isSourceLocation(loc) && loc.sourceLocationType === 'autoGenerate';\n }\n\n public nodeShouldPrint(node: Localized): boolean {\n return this.isSourceLocationNodeReplace(node.loc) ||\n this.isSourceLocationNodeAutoGenerate(node.loc);\n }\n\n public printFilter(node: Localized, callback: () => void): void {\n if (this.nodeShouldPrint(node)) {\n callback();\n }\n }\n\n public isSourceLocationNoMaterialize(loc: object): loc is SourceLocationNoMaterialize {\n return this.isSourceLocation(loc) && loc.sourceLocationType === 'noMaterialize';\n }\n\n public isOfType<Type extends string>(obj: object, type: Type): obj is Typed<Type> {\n const casted: { type?: any } = obj;\n return casted.type === type;\n }\n\n public isOfSubType<Type extends string, SubType extends string>(obj: object, type: Type, subType: SubType):\n obj is SubTyped<Type, SubType> {\n const temp: { type?: unknown; subType?: unknown } = obj;\n return temp.type === type && temp.subType === subType;\n }\n}\n"]}
|
|
@@ -1,16 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var builderTypes_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(builderTypes_exports);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=builderTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builderTypes.js","sourceRoot":"","sources":["../../../../lib/generator-builder/builderTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { ParseNamesFromList } from '../parser-builder/builderTypes.js';\nimport type { GeneratorRule } from './generatorTypes.js';\n\n/**\n * Convert a list of ruledefs to a record that maps each rule name to its definition.\n */\nexport type GenRuleMap<RuleNames extends string> = {[Key in RuleNames]: GeneratorRule<any, Key> };\n\n/**\n * Convert a list of RuleDefs to a Record with the name of the RuleDef as the key, matching the RuleDefMap type.\n */\nexport type GenRulesToObject<\n T extends readonly GeneratorRule[],\n Names extends string = ParseNamesFromList<T>,\n Agg extends Record<string, GeneratorRule> = Record<never, never>,\n> = T extends readonly [infer First, ...infer Rest] ? (\n First extends GeneratorRule ? (\n Rest extends readonly GeneratorRule[] ? (\n GenRulesToObject<Rest, Names, {[K in keyof Agg | First['name']]: K extends First['name'] ? First : Agg[K] }>\n ) : never\n ) : never\n) : GenRuleMap<Names> & Agg;\n\nexport type GeneratorFromRules<Context, Names extends string, RuleDefs extends GenRuleMap<Names>> = {\n [K in Names]: RuleDefs[K] extends GeneratorRule<Context, K, infer RET, infer ARGS> ?\n (input: RET, context: Context & { origSource: string; offset?: number }, ...args: ARGS) => string : never\n};\n"]}
|