@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.
Files changed (51) hide show
  1. package/dist/cjs/lib/AstCoreFactory.js +136 -149
  2. package/dist/cjs/lib/AstCoreFactory.js.map +1 -0
  3. package/dist/cjs/lib/generator-builder/builderTypes.js +2 -15
  4. package/dist/cjs/lib/generator-builder/builderTypes.js.map +1 -0
  5. package/dist/cjs/lib/generator-builder/dynamicGenerator.js +189 -200
  6. package/dist/cjs/lib/generator-builder/dynamicGenerator.js.map +1 -0
  7. package/dist/cjs/lib/generator-builder/generatorBuilder.js +103 -117
  8. package/dist/cjs/lib/generator-builder/generatorBuilder.js.map +1 -0
  9. package/dist/cjs/lib/generator-builder/generatorTypes.js +2 -15
  10. package/dist/cjs/lib/generator-builder/generatorTypes.js.map +1 -0
  11. package/dist/cjs/lib/index.js +39 -57
  12. package/dist/cjs/lib/index.js.map +1 -0
  13. package/dist/cjs/lib/indirection-builder/IndirBuilder.js +63 -85
  14. package/dist/cjs/lib/indirection-builder/IndirBuilder.js.map +1 -0
  15. package/dist/cjs/lib/indirection-builder/dynamicIndirected.js +28 -50
  16. package/dist/cjs/lib/indirection-builder/dynamicIndirected.js.map +1 -0
  17. package/dist/cjs/lib/indirection-builder/helpers.js +11 -31
  18. package/dist/cjs/lib/indirection-builder/helpers.js.map +1 -0
  19. package/dist/cjs/lib/lexer-builder/LexerBuilder.js +92 -114
  20. package/dist/cjs/lib/lexer-builder/LexerBuilder.js.map +1 -0
  21. package/dist/cjs/lib/parser-builder/builderTypes.js +2 -15
  22. package/dist/cjs/lib/parser-builder/builderTypes.js.map +1 -0
  23. package/dist/cjs/lib/parser-builder/dynamicParser.js +115 -136
  24. package/dist/cjs/lib/parser-builder/dynamicParser.js.map +1 -0
  25. package/dist/cjs/lib/parser-builder/parserBuilder.js +167 -169
  26. package/dist/cjs/lib/parser-builder/parserBuilder.js.map +1 -0
  27. package/dist/cjs/lib/parser-builder/ruleDefTypes.js +2 -15
  28. package/dist/cjs/lib/parser-builder/ruleDefTypes.js.map +1 -0
  29. package/dist/cjs/lib/transformers/TransformerObject.js +196 -198
  30. package/dist/cjs/lib/transformers/TransformerObject.js.map +1 -0
  31. package/dist/cjs/lib/transformers/TransformerSubTyped.js +120 -141
  32. package/dist/cjs/lib/transformers/TransformerSubTyped.js.map +1 -0
  33. package/dist/cjs/lib/transformers/TransformerTyped.js +99 -120
  34. package/dist/cjs/lib/transformers/TransformerTyped.js.map +1 -0
  35. package/dist/cjs/lib/types.js +2 -15
  36. package/dist/cjs/lib/types.js.map +1 -0
  37. package/dist/cjs/lib/utils.js +13 -34
  38. package/dist/cjs/lib/utils.js.map +1 -0
  39. package/package.json +9 -9
  40. package/dist/cjs/test/generatorBuilder/generatorBuilder.types.test.js +0 -30
  41. package/dist/cjs/test/grammar-builder/parserBuilder.types.test.js +0 -27
  42. package/dist/cjs/test/transformer.test.js +0 -82
  43. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.d.ts +0 -1
  44. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js +0 -38
  45. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js.map +0 -1
  46. package/dist/esm/test/grammar-builder/parserBuilder.types.test.d.ts +0 -1
  47. package/dist/esm/test/grammar-builder/parserBuilder.types.test.js +0 -38
  48. package/dist/esm/test/grammar-builder/parserBuilder.types.test.js.map +0 -1
  49. package/dist/esm/test/transformer.test.d.ts +0 -1
  50. package/dist/esm/test/transformer.test.js +0 -82
  51. package/dist/esm/test/transformer.test.js.map +0 -1
@@ -1,144 +1,123 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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 TransformerSubTyped_exports = {};
20
- __export(TransformerSubTyped_exports, {
21
- TransformerSubTyped: () => TransformerSubTyped
22
- });
23
- module.exports = __toCommonJS(TransformerSubTyped_exports);
24
- var import_TransformerTyped = require("./TransformerTyped.js");
25
- class TransformerSubTyped extends import_TransformerTyped.TransformerTyped {
26
- constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
27
- super(defaultContext, defaultNodePreVisitor);
28
- }
29
- clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
30
- return new TransformerSubTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
31
- }
32
- /**
33
- * Shares the functionality and first two arguments with {@link this.transformNode}.
34
- * The third argument allows you to also transform based on the subType of objects.
35
- * Note that when a callback for the subtype is provided, the callback for the general type is **NOT** executed.
36
- * @param startObject
37
- * @param nodeCallBacks
38
- * @param nodeSpecificCallBacks
39
- */
40
- transformNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
41
- const transformWrapper = (copy, orig) => {
42
- let ogTransform;
43
- const casted = copy;
44
- if (casted.type && casted.subType) {
45
- const specific = nodeSpecificCallBacks[casted.type];
46
- if (specific) {
47
- ogTransform = specific[casted.subType]?.transform;
48
- }
49
- if (!ogTransform) {
50
- ogTransform = nodeCallBacks[casted.type]?.transform;
51
- }
52
- }
53
- return ogTransform ? ogTransform(casted, orig) : copy;
54
- };
55
- const preVisitWrapper = (curObject) => {
56
- let ogPreVisit;
57
- const casted = curObject;
58
- if (casted.type && casted.subType) {
59
- const specific = nodeSpecificCallBacks[casted.type];
60
- if (specific) {
61
- ogPreVisit = specific[casted.subType]?.preVisitor;
62
- }
63
- if (!ogPreVisit) {
64
- ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
65
- }
66
- }
67
- return ogPreVisit ? ogPreVisit(casted) : {};
68
- };
69
- return this.transformObject(startObject, transformWrapper, preVisitWrapper);
70
- }
71
- /**
72
- * Similar to {@link this.visitNode} but also allows you to match based on the subtype of objects.
73
- * When both nodeCallBack and NodeSpecific callBack are matched, will only visit nodeSpecifCallback
74
- */
75
- visitNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
76
- const visitWrapper = (curObject) => {
77
- let ogTransform;
78
- const casted = curObject;
79
- if (casted.type && casted.subType) {
80
- const specific = nodeSpecificCallBacks[casted.type];
81
- if (specific) {
82
- ogTransform = specific[casted.subType]?.visitor;
83
- }
84
- if (!ogTransform) {
85
- ogTransform = nodeCallBacks[casted.type]?.visitor;
86
- }
87
- }
88
- if (ogTransform) {
89
- ogTransform(casted);
90
- }
91
- };
92
- const preVisitWrapper = (curObject) => {
93
- let ogPreVisit;
94
- const casted = curObject;
95
- if (casted.type && casted.subType) {
96
- const specific = nodeSpecificCallBacks[casted.type];
97
- if (specific) {
98
- ogPreVisit = specific[casted.subType]?.preVisitor;
99
- }
100
- if (!ogPreVisit) {
101
- ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
102
- }
103
- }
104
- return ogPreVisit ? ogPreVisit(casted) : {};
105
- };
106
- this.visitObject(startObject, visitWrapper, preVisitWrapper);
107
- }
108
- /**
109
- * Similar to {@link this.traverseNodes} but also allows you to match based on the subtype of objects.
110
- * @param currentNode
111
- * @param traverseNode
112
- * @param traverseSubNode
113
- */
114
- traverseSubNodes(currentNode, traverseNode, traverseSubNode) {
115
- let didShortCut = false;
116
- const recurse = (curNode) => {
117
- let traverser;
118
- const subObj = traverseSubNode[curNode.type];
119
- if (subObj) {
120
- traverser = subObj[curNode.subType];
121
- }
122
- if (!traverser) {
123
- traverser = traverseNode[curNode.type];
124
- }
125
- if (traverser) {
126
- const { next, shortcut } = traverser(curNode);
127
- didShortCut = shortcut ?? false;
128
- if (!didShortCut) {
129
- for (const node of next ?? []) {
130
- if (didShortCut) {
131
- return;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformerSubTyped = void 0;
4
+ const TransformerTyped_js_1 = require("./TransformerTyped.js");
5
+ class TransformerSubTyped extends TransformerTyped_js_1.TransformerTyped {
6
+ constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
7
+ super(defaultContext, defaultNodePreVisitor);
8
+ }
9
+ ;
10
+ clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
11
+ return new TransformerSubTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
12
+ }
13
+ /**
14
+ * Shares the functionality and first two arguments with {@link this.transformNode}.
15
+ * The third argument allows you to also transform based on the subType of objects.
16
+ * Note that when a callback for the subtype is provided, the callback for the general type is **NOT** executed.
17
+ * @param startObject
18
+ * @param nodeCallBacks
19
+ * @param nodeSpecificCallBacks
20
+ */
21
+ transformNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
22
+ const transformWrapper = (copy, orig) => {
23
+ let ogTransform;
24
+ const casted = copy;
25
+ if (casted.type && casted.subType) {
26
+ const specific = nodeSpecificCallBacks[casted.type];
27
+ if (specific) {
28
+ ogTransform = specific[casted.subType]?.transform;
29
+ }
30
+ if (!ogTransform) {
31
+ ogTransform = nodeCallBacks[casted.type]?.transform;
32
+ }
132
33
  }
133
- recurse(node);
134
- }
135
- }
136
- }
137
- };
138
- recurse(currentNode);
139
- }
34
+ return ogTransform ? ogTransform(casted, orig) : copy;
35
+ };
36
+ const preVisitWrapper = (curObject) => {
37
+ let ogPreVisit;
38
+ const casted = curObject;
39
+ if (casted.type && casted.subType) {
40
+ const specific = nodeSpecificCallBacks[casted.type];
41
+ if (specific) {
42
+ ogPreVisit = specific[casted.subType]?.preVisitor;
43
+ }
44
+ if (!ogPreVisit) {
45
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
46
+ }
47
+ }
48
+ return ogPreVisit ? ogPreVisit(casted) : {};
49
+ };
50
+ return this.transformObject(startObject, transformWrapper, preVisitWrapper);
51
+ }
52
+ /**
53
+ * Similar to {@link this.visitNode} but also allows you to match based on the subtype of objects.
54
+ * When both nodeCallBack and NodeSpecific callBack are matched, will only visit nodeSpecifCallback
55
+ */
56
+ visitNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
57
+ const visitWrapper = (curObject) => {
58
+ let ogTransform;
59
+ const casted = curObject;
60
+ if (casted.type && casted.subType) {
61
+ const specific = nodeSpecificCallBacks[casted.type];
62
+ if (specific) {
63
+ ogTransform = specific[casted.subType]?.visitor;
64
+ }
65
+ if (!ogTransform) {
66
+ ogTransform = nodeCallBacks[casted.type]?.visitor;
67
+ }
68
+ }
69
+ if (ogTransform) {
70
+ ogTransform(casted);
71
+ }
72
+ };
73
+ const preVisitWrapper = (curObject) => {
74
+ let ogPreVisit;
75
+ const casted = curObject;
76
+ if (casted.type && casted.subType) {
77
+ const specific = nodeSpecificCallBacks[casted.type];
78
+ if (specific) {
79
+ ogPreVisit = specific[casted.subType]?.preVisitor;
80
+ }
81
+ if (!ogPreVisit) {
82
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
83
+ }
84
+ }
85
+ return ogPreVisit ? ogPreVisit(casted) : {};
86
+ };
87
+ this.visitObject(startObject, visitWrapper, preVisitWrapper);
88
+ }
89
+ /**
90
+ * Similar to {@link this.traverseNodes} but also allows you to match based on the subtype of objects.
91
+ * @param currentNode
92
+ * @param traverseNode
93
+ * @param traverseSubNode
94
+ */
95
+ traverseSubNodes(currentNode, traverseNode, traverseSubNode) {
96
+ let didShortCut = false;
97
+ const recurse = (curNode) => {
98
+ let traverser;
99
+ const subObj = traverseSubNode[curNode.type];
100
+ if (subObj) {
101
+ traverser = subObj[curNode.subType];
102
+ }
103
+ if (!traverser) {
104
+ traverser = traverseNode[curNode.type];
105
+ }
106
+ if (traverser) {
107
+ const { next, shortcut } = traverser(curNode);
108
+ didShortCut = shortcut ?? false;
109
+ if (!didShortCut) {
110
+ for (const node of next ?? []) {
111
+ if (didShortCut) {
112
+ return;
113
+ }
114
+ recurse(node);
115
+ }
116
+ }
117
+ }
118
+ };
119
+ recurse(currentNode);
120
+ }
140
121
  }
141
- // Annotate the CommonJS export names for ESM import in node:
142
- 0 && (module.exports = {
143
- TransformerSubTyped
144
- });
122
+ exports.TransformerSubTyped = TransformerSubTyped;
123
+ //# sourceMappingURL=TransformerSubTyped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransformerSubTyped.js","sourceRoot":"","sources":["../../../../lib/transformers/TransformerSubTyped.ts"],"names":[],"mappings":";;;AAOA,+DAAyD;AAEzD,MAAa,mBAAyC,SAAQ,sCAAuB;IACnF,YACE,iBAAmC,EAAE,EACrC,wBAAsD,EAAE;QAExD,KAAK,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;IAC/C,CAAC;IAAA,CAAC;IAEc,KAAK,CACnB,oBAAsC,EAAE,EACxC,2BAAyD,EAAE;QAE3D,OAAO,IAAI,mBAAmB,CAC5B,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,iBAAiB,EAAE,EAChD,EAAE,GAAG,IAAI,CAAC,qBAAqB,EAAE,GAAG,wBAAwB,EAAE,CAC/D,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,qBAAqB,CAC1B,WAAmB,EACnB,aAGE,EACF,qBAIK;QAEL,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAW,EAAE;YAC/D,IAAI,WAA4D,CAAC;YACjE,MAAM,MAAM,GAA4B,IAAI,CAAC;YAC7C,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBAClC,MAAM,QAAQ,GA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Ae,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;OAKG;IACI,gBAAgB,CACrB,WAAkB,EAClB,YACyE,EACzE,eAEwF;QAExF,IAAI,WAAW,GAAG,KAAK,CAAC;QAExB,MAAM,OAAO,GAAG,CAAC,OAAc,EAAQ,EAAE;YACvC,IAAI,SAAwE,CAAC;YAC7E,MAAM,MAAM,GAAG,eAAe,CAAgB,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5D,IAAI,MAAM,EAAE,CAAC;gBACX,SAAS,GAAG,MAAM,CAAsB,OAAO,CAAC,OAAO,CAAC,CAAC;YAC3D,CAAC;YACD,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,SAAS,GAAG,YAAY,CAAgB,OAAO,CAAC,IAAI,CAAC,CAAC;YACxD,CAAC;YACD,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAM,OAAO,CAAC,CAAC;gBACnD,WAAW,GAAG,QAAQ,IAAI,KAAK,CAAC;gBAChC,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjB,KAAK,MAAM,IAAI,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;wBAC9B,IAAI,WAAW,EAAE,CAAC;4BAChB,OAAO;wBACT,CAAC;wBACD,OAAO,CAAC,IAAI,CAAC,CAAC;oBAChB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,CAAC,WAAW,CAAC,CAAC;IACvB,CAAC;CACF;AA/JD,kDA+JC","sourcesContent":["import type { SubTyped, Typed } from '../types.js';\nimport type {\n SelectiveTraversalContext,\n TransformContext,\n VisitContext,\n} from './TransformerObject.js';\nimport type { DefaultNodePreVisitor, Safeness, SafeWrap } from './TransformerTyped.js';\nimport { TransformerTyped } from './TransformerTyped.js';\n\nexport class TransformerSubTyped<Nodes extends Typed> extends TransformerTyped<Nodes> {\n public constructor(\n defaultContext: TransformContext = {},\n defaultNodePreVisitor: DefaultNodePreVisitor<Nodes> = {},\n ) {\n super(defaultContext, defaultNodePreVisitor);\n };\n\n public override clone(\n newDefaultContext: TransformContext = {},\n newDefaultNodePreVisitor: DefaultNodePreVisitor<Nodes> = {},\n ): TransformerSubTyped<Nodes> {\n return new TransformerSubTyped(\n { ...this.defaultContext, ...newDefaultContext },\n { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor },\n );\n }\n\n /**\n * Shares the functionality and first two arguments with {@link this.transformNode}.\n * The third argument allows you to also transform based on the subType of objects.\n * Note that when a callback for the subtype is provided, the callback for the general type is **NOT** executed.\n * @param startObject\n * @param nodeCallBacks\n * @param nodeSpecificCallBacks\n */\n public transformNodeSpecific<Safe extends Safeness = 'safe', OutType = unknown>(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n transform?: (copy: SafeWrap<Safe, Extract<Nodes, Typed<T>>>, orig: Extract<Nodes, Typed<T>>) => unknown;\n preVisitor?: (orig: Extract<Nodes, Typed<T>>) => TransformContext;\n }},\n nodeSpecificCallBacks: {[Type in Nodes['type']]?: {\n [SubType in Extract<Nodes, SubTyped<Type>>['subType']]?: {\n transform?: (op: SafeWrap<Safe, Extract<Nodes, SubTyped<Type, SubType>>>) => unknown;\n preVisitor?: (op: Extract<Nodes, SubTyped<Type, SubType>>) => TransformContext;\n }}},\n ): Safe extends 'unsafe' ? OutType : unknown {\n const transformWrapper = (copy: object, orig: object): unknown => {\n let ogTransform: ((copy: any, orig: any) => unknown) | undefined;\n const casted = <SubTyped<Nodes['type']>>copy;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n ogTransform = specific[<keyof typeof specific> casted.subType]?.transform;\n }\n if (!ogTransform) {\n ogTransform = nodeCallBacks[casted.type]?.transform;\n }\n }\n return ogTransform ? ogTransform(casted, orig) : copy;\n };\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n const casted = <SubTyped<Nodes['type']>>curObject;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n ogPreVisit = specific[<keyof typeof specific> casted.subType]?.preVisitor;\n }\n if (!ogPreVisit) {\n ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;\n }\n }\n return ogPreVisit ? ogPreVisit(casted) : {};\n };\n return <any> this.transformObject(startObject, transformWrapper, preVisitWrapper);\n }\n\n /**\n * Similar to {@link this.visitNode} but also allows you to match based on the subtype of objects.\n * When both nodeCallBack and NodeSpecific callBack are matched, will only visit nodeSpecifCallback\n */\n public visitNodeSpecific(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n visitor?: (op: Extract<Nodes, Typed<T>>) => void;\n preVisitor?: (op: Extract<Nodes, Typed<T>>) => VisitContext;\n }},\n nodeSpecificCallBacks: {[Type in Nodes['type']]?:\n {[Subtype in Extract<Nodes, SubTyped<Type>>['subType']]?: {\n visitor?: (op: Extract<Nodes, SubTyped<Type, Subtype>>) => void;\n preVisitor?: (op: Extract<Nodes, SubTyped<Type, Subtype>>) => VisitContext;\n }}},\n ): void {\n const visitWrapper = (curObject: object): void => {\n let ogTransform: ((node: any) => void) | undefined;\n const casted = <SubTyped<Nodes['type']>>curObject;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n ogTransform = specific[<keyof typeof specific> casted.subType]?.visitor;\n }\n if (!ogTransform) {\n ogTransform = nodeCallBacks[casted.type]?.visitor;\n }\n }\n if (ogTransform) {\n ogTransform(casted);\n }\n };\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n const casted = <SubTyped<Nodes['type']>>curObject;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n ogPreVisit = specific[<keyof typeof specific> casted.subType]?.preVisitor;\n }\n if (!ogPreVisit) {\n ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;\n }\n }\n return ogPreVisit ? ogPreVisit(casted) : {};\n };\n this.visitObject(startObject, visitWrapper, preVisitWrapper);\n }\n\n /**\n * Similar to {@link this.traverseNodes} but also allows you to match based on the subtype of objects.\n * @param currentNode\n * @param traverseNode\n * @param traverseSubNode\n */\n public traverseSubNodes(\n currentNode: Nodes,\n traverseNode: {[Type in Nodes['type']]?:\n (op: Extract<Nodes, Typed<Type>>) => SelectiveTraversalContext<Nodes> },\n traverseSubNode: {[Type in Nodes['type']]?:\n {[Subtype in Extract<Nodes, SubTyped<Type>>['subType']]?:\n (op: Extract<Nodes, SubTyped<Type, Subtype>>) => SelectiveTraversalContext<Nodes> }},\n ): void {\n let didShortCut = false;\n\n const recurse = (curNode: Nodes): void => {\n let traverser: ((call: any) => SelectiveTraversalContext<Nodes>) | undefined;\n const subObj = traverseSubNode[<Nodes['type']>curNode.type];\n if (subObj) {\n traverser = subObj[<keyof typeof subObj>curNode.subType];\n }\n if (!traverser) {\n traverser = traverseNode[<Nodes['type']>curNode.type];\n }\n if (traverser) {\n const { next, shortcut } = traverser(<any>curNode);\n didShortCut = shortcut ?? false;\n if (!didShortCut) {\n for (const node of next ?? []) {\n if (didShortCut) {\n return;\n }\n recurse(node);\n }\n }\n }\n };\n\n recurse(currentNode);\n }\n}\n"]}
@@ -1,123 +1,102 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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 TransformerTyped_exports = {};
20
- __export(TransformerTyped_exports, {
21
- TransformerTyped: () => TransformerTyped
22
- });
23
- module.exports = __toCommonJS(TransformerTyped_exports);
24
- var import_TransformerObject = require("./TransformerObject.js");
25
- class TransformerTyped extends import_TransformerObject.TransformerObject {
26
- defaultNodePreVisitor;
27
- constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
28
- super(defaultContext);
29
- this.defaultNodePreVisitor = defaultNodePreVisitor;
30
- }
31
- clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
32
- return new TransformerTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
33
- }
34
- /**
35
- * Transform a single node.
36
- * The transformation calls the preVisitor from starting from the startObject.
37
- * The preVisitor can dictate whether transformation should be stopped.
38
- * Note that stopping the transformation also prevets further copying.
39
- * The transformer itself transforms object starting with the deepest one that can be visited.
40
- * The transformer callback is performed on a copy of the original.
41
- * @param startObject
42
- * @param nodeCallBacks
43
- */
44
- transformNode(startObject, nodeCallBacks) {
45
- const transformWrapper = (copy, orig) => {
46
- let ogTransform;
47
- const casted = copy;
48
- if (casted.type) {
49
- ogTransform = nodeCallBacks[casted.type]?.transform;
50
- }
51
- return ogTransform ? ogTransform(casted, orig) : copy;
52
- };
53
- const nodeDefaults = this.defaultNodePreVisitor;
54
- const preVisitWrapper = (curObject) => {
55
- let ogPreVisit;
56
- let nodeContext = {};
57
- const casted = curObject;
58
- if (casted.type) {
59
- ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
60
- nodeContext = nodeDefaults[casted.type] ?? nodeContext;
61
- }
62
- return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
63
- };
64
- return this.transformObject(startObject, transformWrapper, preVisitWrapper);
65
- }
66
- /**
67
- * Similar to {@link this.transformNode}, but without copying the startObject.
68
- * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.
69
- * @param startObject
70
- * @param nodeCallBacks
71
- */
72
- visitNode(startObject, nodeCallBacks) {
73
- const visitorWrapper = (curObject) => {
74
- const casted = curObject;
75
- if (casted.type) {
76
- const ogTransform = nodeCallBacks[casted.type]?.visitor;
77
- if (ogTransform) {
78
- ogTransform(casted);
79
- }
80
- }
81
- };
82
- const nodeDefaults = this.defaultNodePreVisitor;
83
- const preVisitWrapper = (curObject) => {
84
- let ogPreVisit;
85
- let nodeContext = {};
86
- const casted = curObject;
87
- if (casted.type) {
88
- ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
89
- nodeContext = nodeDefaults[casted.type] ?? nodeContext;
90
- }
91
- return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
92
- };
93
- return this.visitObject(startObject, visitorWrapper, preVisitWrapper);
94
- }
95
- /**
96
- * Traverses only selected nodes as returned by the function.
97
- * @param currentNode
98
- * @param traverse
99
- */
100
- traverseNodes(currentNode, traverse) {
101
- let didShortCut = false;
102
- const recurse = (curNode) => {
103
- const traverser = traverse[curNode.type];
104
- if (traverser) {
105
- const { next, shortcut } = traverser(curNode);
106
- didShortCut = shortcut ?? false;
107
- if (!didShortCut) {
108
- for (const node of next ?? []) {
109
- if (didShortCut) {
110
- return;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformerTyped = void 0;
4
+ const TransformerObject_js_1 = require("./TransformerObject.js");
5
+ class TransformerTyped extends TransformerObject_js_1.TransformerObject {
6
+ defaultNodePreVisitor;
7
+ constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
8
+ super(defaultContext);
9
+ this.defaultNodePreVisitor = defaultNodePreVisitor;
10
+ }
11
+ ;
12
+ clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
13
+ return new TransformerTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
14
+ }
15
+ /**
16
+ * Transform a single node.
17
+ * The transformation calls the preVisitor from starting from the startObject.
18
+ * The preVisitor can dictate whether transformation should be stopped.
19
+ * Note that stopping the transformation also prevets further copying.
20
+ * The transformer itself transforms object starting with the deepest one that can be visited.
21
+ * The transformer callback is performed on a copy of the original.
22
+ * @param startObject
23
+ * @param nodeCallBacks
24
+ */
25
+ transformNode(startObject, nodeCallBacks) {
26
+ const transformWrapper = (copy, orig) => {
27
+ let ogTransform;
28
+ const casted = copy;
29
+ if (casted.type) {
30
+ ogTransform = nodeCallBacks[casted.type]?.transform;
111
31
  }
112
- recurse(node);
113
- }
114
- }
115
- }
116
- };
117
- recurse(currentNode);
118
- }
32
+ return ogTransform ? ogTransform(casted, orig) : copy;
33
+ };
34
+ const nodeDefaults = this.defaultNodePreVisitor;
35
+ const preVisitWrapper = (curObject) => {
36
+ let ogPreVisit;
37
+ let nodeContext = {};
38
+ const casted = curObject;
39
+ if (casted.type) {
40
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
41
+ nodeContext = nodeDefaults[casted.type] ?? nodeContext;
42
+ }
43
+ return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
44
+ };
45
+ return this.transformObject(startObject, transformWrapper, preVisitWrapper);
46
+ }
47
+ /**
48
+ * Similar to {@link this.transformNode}, but without copying the startObject.
49
+ * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.
50
+ * @param startObject
51
+ * @param nodeCallBacks
52
+ */
53
+ visitNode(startObject, nodeCallBacks) {
54
+ const visitorWrapper = (curObject) => {
55
+ const casted = curObject;
56
+ if (casted.type) {
57
+ const ogTransform = nodeCallBacks[casted.type]?.visitor;
58
+ if (ogTransform) {
59
+ ogTransform(casted);
60
+ }
61
+ }
62
+ };
63
+ const nodeDefaults = this.defaultNodePreVisitor;
64
+ const preVisitWrapper = (curObject) => {
65
+ let ogPreVisit;
66
+ let nodeContext = {};
67
+ const casted = curObject;
68
+ if (casted.type) {
69
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
70
+ nodeContext = nodeDefaults[casted.type] ?? nodeContext;
71
+ }
72
+ return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
73
+ };
74
+ return this.visitObject(startObject, visitorWrapper, preVisitWrapper);
75
+ }
76
+ /**
77
+ * Traverses only selected nodes as returned by the function.
78
+ * @param currentNode
79
+ * @param traverse
80
+ */
81
+ traverseNodes(currentNode, traverse) {
82
+ let didShortCut = false;
83
+ const recurse = (curNode) => {
84
+ const traverser = traverse[curNode.type];
85
+ if (traverser) {
86
+ const { next, shortcut } = traverser(curNode);
87
+ didShortCut = shortcut ?? false;
88
+ if (!didShortCut) {
89
+ for (const node of next ?? []) {
90
+ if (didShortCut) {
91
+ return;
92
+ }
93
+ recurse(node);
94
+ }
95
+ }
96
+ }
97
+ };
98
+ recurse(currentNode);
99
+ }
119
100
  }
120
- // Annotate the CommonJS export names for ESM import in node:
121
- 0 && (module.exports = {
122
- TransformerTyped
123
- });
101
+ exports.TransformerTyped = TransformerTyped;
102
+ //# sourceMappingURL=TransformerTyped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransformerTyped.js","sourceRoot":"","sources":["../../../../lib/transformers/TransformerTyped.ts"],"names":[],"mappings":";;;AAEA,iEAA2D;AAQ3D,MAAa,gBAAsC,SAAQ,wCAAiB;IAG9D;IAFZ,YACE,iBAAmC,EAAE,EAC3B,wBAAsD,EAAE;QAElE,KAAK,CAAC,cAAc,CAAC,CAAC;QAFZ,0BAAqB,GAArB,qBAAqB,CAAmC;IAGpE,CAAC;IAAA,CAAC;IAEc,KAAK,CACnB,oBAAsC,EAAE,EACxC,2BAAyD,EAAE;QAE3D,OAAO,IAAI,gBAAgB,CACzB,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,iBAAiB,EAAE,EAChD,EAAE,GAAG,IAAI,CAAC,qBAAqB,EAAE,GAAG,wBAAwB,EAAE,CAC/D,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACI,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K,MAAM,IAAI,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;wBAC9B,IAAI,WAAW,EAAE,CAAC;4BAChB,OAAO;wBACT,CAAC;wBACD,OAAO,CAAC,IAAI,CAAC,CAAC;oBAChB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,CAAC,WAAW,CAAC,CAAC;IACvB,CAAC;CACF;AA1HD,4CA0HC","sourcesContent":["import type { Typed } from '../types.js';\nimport type { SelectiveTraversalContext, TransformContext, VisitContext } from './TransformerObject.js';\nimport { TransformerObject } from './TransformerObject.js';\n\nexport type Safeness = 'safe' | 'unsafe';\nexport type SafeWrap<Safe extends Safeness, obj extends object> =\n Safe extends 'safe' ? {[key in keyof obj]: unknown } : obj;\n\nexport type DefaultNodePreVisitor<Nodes extends Typed> = {[T in Nodes['type']]?: TransformContext };\n\nexport class TransformerTyped<Nodes extends Typed> extends TransformerObject {\n public constructor(\n defaultContext: TransformContext = {},\n protected defaultNodePreVisitor: DefaultNodePreVisitor<Nodes> = {},\n ) {\n super(defaultContext);\n };\n\n public override clone(\n newDefaultContext: TransformContext = {},\n newDefaultNodePreVisitor: DefaultNodePreVisitor<Nodes> = {},\n ): TransformerTyped<Nodes> {\n return new TransformerTyped(\n { ...this.defaultContext, ...newDefaultContext },\n { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor },\n );\n }\n\n /**\n * Transform a single node.\n * The transformation calls the preVisitor from starting from the startObject.\n * The preVisitor can dictate whether transformation should be stopped.\n * Note that stopping the transformation also prevets further copying.\n * The transformer itself transforms object starting with the deepest one that can be visited.\n * The transformer callback is performed on a copy of the original.\n * @param startObject\n * @param nodeCallBacks\n */\n public transformNode<Safe extends Safeness = 'safe', OutType = unknown>(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n transform?: (copy: SafeWrap<Safe, Extract<Nodes, Typed<T>>>, orig: Extract<Nodes, Typed<T>>) => unknown;\n preVisitor?: (orig: Extract<Nodes, Typed<T>>) => TransformContext;\n }},\n ): Safe extends 'unsafe' ? OutType : unknown {\n const transformWrapper = (copy: object, orig: object): unknown => {\n let ogTransform: ((copy: any, orig: any) => unknown) | undefined;\n const casted = <Typed<Nodes['type']>>copy;\n if (casted.type) {\n ogTransform = nodeCallBacks[casted.type]?.transform;\n }\n return ogTransform ? ogTransform(casted, orig) : copy;\n };\n const nodeDefaults = this.defaultNodePreVisitor;\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n let nodeContext: VisitContext = {};\n const casted = <Typed<Nodes['type']>>curObject;\n if (casted.type) {\n ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;\n nodeContext = nodeDefaults[casted.type] ?? nodeContext;\n }\n return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;\n };\n return <any> this.transformObject(startObject, transformWrapper, preVisitWrapper);\n }\n\n /**\n * Similar to {@link this.transformNode}, but without copying the startObject.\n * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.\n * @param startObject\n * @param nodeCallBacks\n */\n public visitNode(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n visitor?: (op: Extract<Nodes, Typed<T>>) => void;\n preVisitor?: (op: Extract<Nodes, Typed<T>>) => VisitContext;\n }},\n ): void {\n const visitorWrapper = (curObject: object): void => {\n const casted = <Typed<Nodes['type']>>curObject;\n if (casted.type) {\n const ogTransform = nodeCallBacks[casted.type]?.visitor;\n if (ogTransform) {\n ogTransform(<any> casted);\n }\n }\n };\n const nodeDefaults = this.defaultNodePreVisitor;\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n let nodeContext: VisitContext = {};\n const casted = <Typed<Nodes['type']>>curObject;\n if (casted.type) {\n ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;\n nodeContext = nodeDefaults[casted.type] ?? nodeContext;\n }\n return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;\n };\n return this.visitObject(startObject, visitorWrapper, preVisitWrapper);\n }\n\n /**\n * Traverses only selected nodes as returned by the function.\n * @param currentNode\n * @param traverse\n */\n public traverseNodes(\n currentNode: Nodes,\n traverse: {[T in Nodes['type']]?: (op: Extract<Nodes, Typed<T>>) => SelectiveTraversalContext<Nodes> },\n ): void {\n let didShortCut = false;\n\n const recurse = (curNode: Nodes): void => {\n const traverser = traverse[<Nodes['type']>curNode.type];\n if (traverser) {\n const { next, shortcut } = traverser(<any>curNode);\n didShortCut = shortcut ?? false;\n if (!didShortCut) {\n for (const node of next ?? []) {\n if (didShortCut) {\n return;\n }\n recurse(node);\n }\n }\n }\n };\n\n recurse(currentNode);\n }\n}\n"]}
@@ -1,16 +1,3 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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 types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface Typed<Type extends string = string> {\n type: Type;\n subType?: string;\n}\n\nexport interface SubTyped<Type extends string = string, SubType extends string = string> extends Typed<Type> {\n subType: SubType;\n}\n\nexport interface Localized {\n /**\n * Location undefined means the node does have a string representation, but it was not clarified.\n * This happens when an AST node is patched by a client of the lib.\n */\n loc: SourceLocation;\n}\n\nexport interface Wrap<T> extends Localized {\n val: T;\n}\n\n/**\n * A AST node. Nodes are indexable by their types.\n * When generating, the SUBRULES called should be located within the current location range.\n */\nexport interface Node extends Localized, Typed {}\n\nexport interface SourceLocationBase {\n sourceLocationType: string;\n}\n\nexport interface SourceLocationSource extends SourceLocationBase {\n sourceLocationType: 'source';\n start: number;\n end: number;\n}\n\n/**\n * NoStringManifestation means the node does not have a string representation.\n * For example the literal '5' has an integer type (which is an AST node),\n * but the type does not have an associated string representation.\n * When set to true, the node will not be printed, start and end are meaningless in this case.\n */\nexport interface SourceLocationNoMaterialize extends SourceLocationBase {\n sourceLocationType: 'noMaterialize';\n}\n\nexport interface SourceLocationStringReplace extends SourceLocationBase {\n sourceLocationType: 'stringReplace';\n newSource: string;\n start: number;\n end: number;\n}\n\nexport interface SourceLocationNodeReplace extends SourceLocationBase {\n sourceLocationType: 'nodeReplace';\n start: number;\n end: number;\n}\n/**\n * Must have an ancestor of type {@link SourceLocationNodeReplace}\n */\nexport interface SourceLocationNodeAutoGenerate extends SourceLocationBase {\n sourceLocationType: 'autoGenerate';\n}\n\nexport type SourceLocation =\n | SourceLocationSource\n | SourceLocationNoMaterialize\n | SourceLocationStringReplace\n | SourceLocationNodeReplace\n | SourceLocationNodeAutoGenerate;\n"]}
@@ -1,39 +1,18 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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 utils_exports = {};
20
- __export(utils_exports, {
21
- createToken: () => createToken,
22
- traqulaIndentation: () => traqulaIndentation,
23
- unCapitalize: () => unCapitalize
24
- });
25
- module.exports = __toCommonJS(utils_exports);
26
- var import_chevrotain = require("@traqula/chevrotain");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.traqulaIndentation = void 0;
4
+ exports.unCapitalize = unCapitalize;
5
+ exports.createToken = createToken;
6
+ const chevrotain_1 = require("@traqula/chevrotain");
27
7
  function unCapitalize(str) {
28
- return str.charAt(0).toLowerCase() + str.slice(1);
8
+ return (str.charAt(0).toLowerCase() + str.slice(1));
29
9
  }
30
10
  function createToken(config) {
31
- return (0, import_chevrotain.createToken)(config);
11
+ return (0, chevrotain_1.createToken)(config);
32
12
  }
33
- const traqulaIndentation = "When you use this string, you expect traqula to handle indentation after every newline";
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {
36
- createToken,
37
- traqulaIndentation,
38
- unCapitalize
39
- });
13
+ /**
14
+ * Key that allows you to set the space based indentation of your query when generating newlines using the NEW_LINE.
15
+ * A value of -1 disables the generation of newlines from the NEW_LINE function
16
+ */
17
+ exports.traqulaIndentation = 'When you use this string, you expect traqula to handle indentation after every newline';
18
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/utils.ts"],"names":[],"mappings":";;;AAQA,oCAEC;AAID,kCAEC;AAfD,oDAA4D;AAO5D,SAAgB,YAAY,CAAmB,GAAM;IACnD,OAAyB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC;AAID,SAAgB,WAAW,CAAsB,MAAqC;IACpF,OAAoC,IAAA,wBAAM,EAAC,MAAM,CAAC,CAAC;AACrD,CAAC;AAKD;;;GAGG;AACU,QAAA,kBAAkB,GAC7B,wFAAwF,CAAC","sourcesContent":["import type { ITokenConfig, TokenType } from '@traqula/chevrotain';\nimport { createToken as chevcT } from '@traqula/chevrotain';\n\n/**\n * Check whether the first two types overlap, if no, return the 3th argument, else the 4th.\n */\nexport type CheckOverlap<T, U, V, W = never> = T & U extends never ? V : W;\n\nexport function unCapitalize<T extends string>(str: T): Uncapitalize<T> {\n return <Uncapitalize<T>> (str.charAt(0).toLowerCase() + str.slice(1));\n}\n\nexport type NamedToken<Name extends string = string> = TokenType & { name: Name };\n\nexport function createToken<Name extends string>(config: ITokenConfig & { name: Name }): NamedToken<Name> {\n return <TokenType & { name: Name }> chevcT(config);\n}\n\nexport type Patch<T extends object, Patch extends {[Key in keyof T ]?: unknown }> =\n {[Key in keyof T]: Key extends keyof Patch ? Patch[Key] : T[Key] };\n\n/**\n * Key that allows you to set the space based indentation of your query when generating newlines using the NEW_LINE.\n * A value of -1 disables the generation of newlines from the NEW_LINE function\n */\nexport const traqulaIndentation =\n 'When you use this string, you expect traqula to handle indentation after every newline';\n"]}