@traqula/core 0.0.24 → 1.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/README.md +4 -1
- package/dist/cjs/lib/AstCoreFactory.js +50 -5
- package/dist/cjs/lib/AstCoreFactory.js.map +1 -1
- package/dist/cjs/lib/generator-builder/dynamicGenerator.js +20 -0
- package/dist/cjs/lib/generator-builder/dynamicGenerator.js.map +1 -1
- package/dist/cjs/lib/parser-builder/dynamicParser.js +1 -0
- package/dist/cjs/lib/parser-builder/dynamicParser.js.map +1 -1
- package/dist/cjs/lib/parser-builder/parserBuilder.js +2 -2
- package/dist/cjs/lib/parser-builder/parserBuilder.js.map +1 -1
- package/dist/cjs/lib/transformers/TransformerObject.js.map +1 -1
- package/dist/cjs/lib/transformers/TransformerSubTyped.js +30 -40
- package/dist/cjs/lib/transformers/TransformerSubTyped.js.map +1 -1
- package/dist/cjs/lib/transformers/TransformerTyped.js +23 -35
- package/dist/cjs/lib/transformers/TransformerTyped.js.map +1 -1
- package/dist/cjs/lib/types.js.map +1 -1
- package/dist/cjs/lib/utils.js +7 -0
- package/dist/cjs/lib/utils.js.map +1 -1
- package/dist/esm/lib/AstCoreFactory.d.ts +19 -7
- package/dist/esm/lib/AstCoreFactory.js +50 -5
- package/dist/esm/lib/AstCoreFactory.js.map +1 -1
- package/dist/esm/lib/generator-builder/dynamicGenerator.d.ts +5 -0
- package/dist/esm/lib/generator-builder/dynamicGenerator.js +20 -0
- package/dist/esm/lib/generator-builder/dynamicGenerator.js.map +1 -1
- package/dist/esm/lib/parser-builder/dynamicParser.js +1 -0
- package/dist/esm/lib/parser-builder/dynamicParser.js.map +1 -1
- package/dist/esm/lib/parser-builder/parserBuilder.js +2 -2
- package/dist/esm/lib/parser-builder/parserBuilder.js.map +1 -1
- package/dist/esm/lib/transformers/TransformerObject.d.ts +1 -1
- package/dist/esm/lib/transformers/TransformerObject.js.map +1 -1
- package/dist/esm/lib/transformers/TransformerSubTyped.d.ts +31 -22
- package/dist/esm/lib/transformers/TransformerSubTyped.js +30 -40
- package/dist/esm/lib/transformers/TransformerSubTyped.js.map +1 -1
- package/dist/esm/lib/transformers/TransformerTyped.d.ts +24 -20
- package/dist/esm/lib/transformers/TransformerTyped.js +23 -35
- package/dist/esm/lib/transformers/TransformerTyped.js.map +1 -1
- package/dist/esm/lib/types.d.ts +68 -6
- package/dist/esm/lib/types.js.map +1 -1
- package/dist/esm/lib/utils.d.ts +10 -0
- package/dist/esm/lib/utils.js +7 -0
- package/dist/esm/lib/utils.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Typed } from '../types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TransformContext, VisitContext } from './TransformerObject.js';
|
|
3
3
|
import { TransformerObject } from './TransformerObject.js';
|
|
4
4
|
export type Safeness = 'safe' | 'unsafe';
|
|
5
5
|
export type SafeWrap<Safe extends Safeness, obj extends object> = Safe extends 'safe' ? {
|
|
@@ -13,14 +13,17 @@ export declare class TransformerTyped<Nodes extends Typed> extends TransformerOb
|
|
|
13
13
|
constructor(defaultContext?: TransformContext, defaultNodePreVisitor?: DefaultNodePreVisitor<Nodes>);
|
|
14
14
|
clone(newDefaultContext?: TransformContext, newDefaultNodePreVisitor?: DefaultNodePreVisitor<Nodes>): TransformerTyped<Nodes>;
|
|
15
15
|
/**
|
|
16
|
-
* Transform a single node.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
16
|
+
* Transform a single node ({@link Typed}).
|
|
17
|
+
* @param startObject the object from which we will start the transformation,
|
|
18
|
+
* potentially visiting and transforming its descendants along the way.
|
|
19
|
+
* @param nodeCallBacks a dictionary mapping the various node types to objects optionally
|
|
20
|
+
* containing preVisitor and transformer.
|
|
21
|
+
* The preVisitor allows you to provide {@link TransformContext} for the current object,
|
|
22
|
+
* altering how it will be transformed.
|
|
23
|
+
* The transformer allows you to manipulate the copy of the current object,
|
|
24
|
+
* and expects you to return the value that should take the current objects place.
|
|
25
|
+
* @return the result of transforming the requested descendant operations (based on the preVisitor)
|
|
26
|
+
* using a transformer that works its way back up from the descendant to the startObject.
|
|
24
27
|
*/
|
|
25
28
|
transformNode<Safe extends Safeness = 'safe', OutType = unknown>(startObject: object, nodeCallBacks: {
|
|
26
29
|
[T in Nodes['type']]?: {
|
|
@@ -29,10 +32,19 @@ export declare class TransformerTyped<Nodes extends Typed> extends TransformerOb
|
|
|
29
32
|
};
|
|
30
33
|
}): Safe extends 'unsafe' ? OutType : unknown;
|
|
31
34
|
/**
|
|
32
|
-
*
|
|
35
|
+
* Visit a selected subTree given a startObject, steering the visits based on {@link Typed} nodes.
|
|
36
|
+
* Will first call the preVisitor on the project and notice it should not iterate on its descendants.
|
|
37
|
+
* It then visits the project, and the outermost distinct, printing '21'.
|
|
33
38
|
* The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.
|
|
34
|
-
* @param startObject
|
|
35
|
-
*
|
|
39
|
+
* @param startObject the object from which we will start visiting,
|
|
40
|
+
* potentially visiting its descendants along the way.
|
|
41
|
+
* @param nodeCallBacks a dictionary mapping the various operation types to objects optionally
|
|
42
|
+
* containing preVisitor and visitor.
|
|
43
|
+
* The preVisitor allows you to provide {@link VisitContext} for the current object,
|
|
44
|
+
* altering how it will be visited.
|
|
45
|
+
* The visitor allows you to visit the object from deepest to the outermost object.
|
|
46
|
+
* This is useful if you for example want to manipulate the objects you visit during your visits,
|
|
47
|
+
* similar to {@link this.transformNode}.
|
|
36
48
|
*/
|
|
37
49
|
visitNode(startObject: object, nodeCallBacks: {
|
|
38
50
|
[T in Nodes['type']]?: {
|
|
@@ -40,12 +52,4 @@ export declare class TransformerTyped<Nodes extends Typed> extends TransformerOb
|
|
|
40
52
|
preVisitor?: (op: Extract<Nodes, Typed<T>>) => VisitContext;
|
|
41
53
|
};
|
|
42
54
|
}): void;
|
|
43
|
-
/**
|
|
44
|
-
* Traverses only selected nodes as returned by the function.
|
|
45
|
-
* @param currentNode
|
|
46
|
-
* @param traverse
|
|
47
|
-
*/
|
|
48
|
-
traverseNodes(currentNode: Nodes, traverse: {
|
|
49
|
-
[T in Nodes['type']]?: (op: Extract<Nodes, Typed<T>>) => SelectiveTraversalContext<Nodes>;
|
|
50
|
-
}): void;
|
|
51
55
|
}
|
|
@@ -10,14 +10,17 @@ export class TransformerTyped extends TransformerObject {
|
|
|
10
10
|
return new TransformerTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* Transform a single node.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
13
|
+
* Transform a single node ({@link Typed}).
|
|
14
|
+
* @param startObject the object from which we will start the transformation,
|
|
15
|
+
* potentially visiting and transforming its descendants along the way.
|
|
16
|
+
* @param nodeCallBacks a dictionary mapping the various node types to objects optionally
|
|
17
|
+
* containing preVisitor and transformer.
|
|
18
|
+
* The preVisitor allows you to provide {@link TransformContext} for the current object,
|
|
19
|
+
* altering how it will be transformed.
|
|
20
|
+
* The transformer allows you to manipulate the copy of the current object,
|
|
21
|
+
* and expects you to return the value that should take the current objects place.
|
|
22
|
+
* @return the result of transforming the requested descendant operations (based on the preVisitor)
|
|
23
|
+
* using a transformer that works its way back up from the descendant to the startObject.
|
|
21
24
|
*/
|
|
22
25
|
transformNode(startObject, nodeCallBacks) {
|
|
23
26
|
const transformWrapper = (copy, orig) => {
|
|
@@ -42,10 +45,19 @@ export class TransformerTyped extends TransformerObject {
|
|
|
42
45
|
return this.transformObject(startObject, transformWrapper, preVisitWrapper);
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
|
-
*
|
|
48
|
+
* Visit a selected subTree given a startObject, steering the visits based on {@link Typed} nodes.
|
|
49
|
+
* Will first call the preVisitor on the project and notice it should not iterate on its descendants.
|
|
50
|
+
* It then visits the project, and the outermost distinct, printing '21'.
|
|
46
51
|
* The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.
|
|
47
|
-
* @param startObject
|
|
48
|
-
*
|
|
52
|
+
* @param startObject the object from which we will start visiting,
|
|
53
|
+
* potentially visiting its descendants along the way.
|
|
54
|
+
* @param nodeCallBacks a dictionary mapping the various operation types to objects optionally
|
|
55
|
+
* containing preVisitor and visitor.
|
|
56
|
+
* The preVisitor allows you to provide {@link VisitContext} for the current object,
|
|
57
|
+
* altering how it will be visited.
|
|
58
|
+
* The visitor allows you to visit the object from deepest to the outermost object.
|
|
59
|
+
* This is useful if you for example want to manipulate the objects you visit during your visits,
|
|
60
|
+
* similar to {@link this.transformNode}.
|
|
49
61
|
*/
|
|
50
62
|
visitNode(startObject, nodeCallBacks) {
|
|
51
63
|
const visitorWrapper = (curObject) => {
|
|
@@ -70,29 +82,5 @@ export class TransformerTyped extends TransformerObject {
|
|
|
70
82
|
};
|
|
71
83
|
return this.visitObject(startObject, visitorWrapper, preVisitWrapper);
|
|
72
84
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Traverses only selected nodes as returned by the function.
|
|
75
|
-
* @param currentNode
|
|
76
|
-
* @param traverse
|
|
77
|
-
*/
|
|
78
|
-
traverseNodes(currentNode, traverse) {
|
|
79
|
-
let didShortCut = false;
|
|
80
|
-
const recurse = (curNode) => {
|
|
81
|
-
const traverser = traverse[curNode.type];
|
|
82
|
-
if (traverser) {
|
|
83
|
-
const { next, shortcut } = traverser(curNode);
|
|
84
|
-
didShortCut = shortcut ?? false;
|
|
85
|
-
if (!didShortCut) {
|
|
86
|
-
for (const node of next ?? []) {
|
|
87
|
-
if (didShortCut) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
recurse(node);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
recurse(currentNode);
|
|
96
|
-
}
|
|
97
85
|
}
|
|
98
86
|
//# sourceMappingURL=TransformerTyped.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransformerTyped.js","sourceRoot":"","sources":["../../../../lib/transformers/TransformerTyped.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAQ3D,MAAM,OAAO,gBAAsC,SAAQ,iBAAiB;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
|
|
1
|
+
{"version":3,"file":"TransformerTyped.js","sourceRoot":"","sources":["../../../../lib/transformers/TransformerTyped.ts"],"names":[],"mappings":"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","sourcesContent":["import type { Typed } from '../types.js';\nimport type { 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 ({@link Typed}).\n * @param startObject the object from which we will start the transformation,\n * potentially visiting and transforming its descendants along the way.\n * @param nodeCallBacks a dictionary mapping the various node types to objects optionally\n * containing preVisitor and transformer.\n * The preVisitor allows you to provide {@link TransformContext} for the current object,\n * altering how it will be transformed.\n * The transformer allows you to manipulate the copy of the current object,\n * and expects you to return the value that should take the current objects place.\n * @return the result of transforming the requested descendant operations (based on the preVisitor)\n * using a transformer that works its way back up from the descendant to the startObject.\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 * Visit a selected subTree given a startObject, steering the visits based on {@link Typed} nodes.\n * Will first call the preVisitor on the project and notice it should not iterate on its descendants.\n * It then visits the project, and the outermost distinct, printing '21'.\n * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.\n * @param startObject the object from which we will start visiting,\n * potentially visiting its descendants along the way.\n * @param nodeCallBacks a dictionary mapping the various operation types to objects optionally\n * containing preVisitor and visitor.\n * The preVisitor allows you to provide {@link VisitContext} for the current object,\n * altering how it will be visited.\n * The visitor allows you to visit the object from deepest to the outermost object.\n * This is useful if you for example want to manipulate the objects you visit during your visits,\n * similar to {@link this.transformNode}.\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"]}
|
package/dist/esm/lib/types.d.ts
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type that is used by the Traqula core package to type raw objects/ Data Transfer Objects (DTO).
|
|
3
|
+
* Enforces the presence of a type string, and that in case the subType key is present, it also be a string.
|
|
4
|
+
*/
|
|
1
5
|
export interface Typed<Type extends string = string> {
|
|
2
6
|
type: Type;
|
|
3
7
|
subType?: string;
|
|
4
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* A {@link Typed} object that is sure to have a subType
|
|
11
|
+
*/
|
|
5
12
|
export interface SubTyped<Type extends string = string, SubType extends string = string> extends Typed<Type> {
|
|
6
13
|
subType: SubType;
|
|
7
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Type used by the parser and generator builders of the core Traqula package to annotate
|
|
17
|
+
* the relation between AST objects and the source string.
|
|
18
|
+
*/
|
|
8
19
|
export interface Localized {
|
|
9
|
-
/**
|
|
10
|
-
* Location undefined means the node does have a string representation, but it was not clarified.
|
|
11
|
-
* This happens when an AST node is patched by a client of the lib.
|
|
12
|
-
*/
|
|
13
20
|
loc: SourceLocation;
|
|
14
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Wrapper type for localization,
|
|
24
|
+
* can be used to state localization information about any other type (including primitive types)
|
|
25
|
+
*/
|
|
15
26
|
export interface Wrap<T> extends Localized {
|
|
16
27
|
val: T;
|
|
17
28
|
}
|
|
18
29
|
/**
|
|
19
|
-
*
|
|
30
|
+
* An AST node. Nodes are indexable by their types.
|
|
20
31
|
* When generating, the SUBRULES called should be located within the current location range.
|
|
21
32
|
*/
|
|
22
33
|
export interface Node extends Localized, Typed {
|
|
@@ -24,11 +35,38 @@ export interface Node extends Localized, Typed {
|
|
|
24
35
|
export interface SourceLocationBase {
|
|
25
36
|
sourceLocationType: string;
|
|
26
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* SourceLocation type that annotates that the node represents the AST representation of
|
|
40
|
+
* the given range in the source string.
|
|
41
|
+
*/
|
|
27
42
|
export interface SourceLocationSource extends SourceLocationBase {
|
|
28
43
|
sourceLocationType: 'source';
|
|
29
44
|
start: number;
|
|
30
45
|
end: number;
|
|
31
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Similar to {@link SourceLocationSource} but also carrying the source it related too.
|
|
49
|
+
* All sourceLocation nodes that are descends of this one, relate themselves to this source.
|
|
50
|
+
*/
|
|
51
|
+
export interface SourceLocationInlinedSource extends SourceLocationBase, Localized {
|
|
52
|
+
sourceLocationType: 'inlinedSource';
|
|
53
|
+
/**
|
|
54
|
+
* The string that will be used as the source for this node and the descends of this node.
|
|
55
|
+
* Note that the generator will print the characters from newSource[0] until start. Likewise for the suffix.
|
|
56
|
+
*/
|
|
57
|
+
newSource: string;
|
|
58
|
+
/**
|
|
59
|
+
* Behavior of the current loc, after replacing the source string.
|
|
60
|
+
*/
|
|
61
|
+
loc: SourceLocation;
|
|
62
|
+
/**
|
|
63
|
+
* The range that this node replaces in the context of the original source.
|
|
64
|
+
*/
|
|
65
|
+
start: number;
|
|
66
|
+
end: number;
|
|
67
|
+
startOnNew: number;
|
|
68
|
+
endOnNew: number;
|
|
69
|
+
}
|
|
32
70
|
/**
|
|
33
71
|
* NoStringManifestation means the node does not have a string representation.
|
|
34
72
|
* For example the literal '5' has an integer type (which is an AST node),
|
|
@@ -38,15 +76,39 @@ export interface SourceLocationSource extends SourceLocationBase {
|
|
|
38
76
|
export interface SourceLocationNoMaterialize extends SourceLocationBase {
|
|
39
77
|
sourceLocationType: 'noMaterialize';
|
|
40
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* SourceLocation type that annotates that the node has been replaced
|
|
81
|
+
* in relation to the original string by a new string.
|
|
82
|
+
* It means that this node should be generated, and that the source string from start to end has been changed.
|
|
83
|
+
*/
|
|
41
84
|
export interface SourceLocationStringReplace extends SourceLocationBase {
|
|
42
85
|
sourceLocationType: 'stringReplace';
|
|
86
|
+
/**
|
|
87
|
+
* The string that will replace the given range in the original source.
|
|
88
|
+
*/
|
|
43
89
|
newSource: string;
|
|
90
|
+
/**
|
|
91
|
+
* The start of the region in the original source string that this node replaces.
|
|
92
|
+
*/
|
|
44
93
|
start: number;
|
|
94
|
+
/**
|
|
95
|
+
* The end of the region in the original source string that this node replaces.
|
|
96
|
+
*/
|
|
45
97
|
end: number;
|
|
46
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* SourceLocation type that annotates that the node has been replaced in relation to the original string.
|
|
101
|
+
* It means that this node should be generated, and that the source string from start to end has been changed.
|
|
102
|
+
*/
|
|
47
103
|
export interface SourceLocationNodeReplace extends SourceLocationBase {
|
|
48
104
|
sourceLocationType: 'nodeReplace';
|
|
105
|
+
/**
|
|
106
|
+
* The start of the region in the original source string that this node replaces.
|
|
107
|
+
*/
|
|
49
108
|
start: number;
|
|
109
|
+
/**
|
|
110
|
+
* The end of the region in the original source string that this node replaces.
|
|
111
|
+
*/
|
|
50
112
|
end: number;
|
|
51
113
|
}
|
|
52
114
|
/**
|
|
@@ -55,4 +117,4 @@ export interface SourceLocationNodeReplace extends SourceLocationBase {
|
|
|
55
117
|
export interface SourceLocationNodeAutoGenerate extends SourceLocationBase {
|
|
56
118
|
sourceLocationType: 'autoGenerate';
|
|
57
119
|
}
|
|
58
|
-
export type SourceLocation = SourceLocationSource | SourceLocationNoMaterialize | SourceLocationStringReplace | SourceLocationNodeReplace | SourceLocationNodeAutoGenerate;
|
|
120
|
+
export type SourceLocation = SourceLocationSource | SourceLocationInlinedSource | SourceLocationNoMaterialize | SourceLocationStringReplace | SourceLocationNodeReplace | SourceLocationNodeAutoGenerate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Type that is used by the Traqula core package to type raw objects/ Data Transfer Objects (DTO).\n * Enforces the presence of a type string, and that in case the subType key is present, it also be a string.\n */\nexport interface Typed<Type extends string = string> {\n type: Type;\n subType?: string;\n}\n\n/**\n * A {@link Typed} object that is sure to have a subType\n */\nexport interface SubTyped<Type extends string = string, SubType extends string = string> extends Typed<Type> {\n subType: SubType;\n}\n\n/**\n * Type used by the parser and generator builders of the core Traqula package to annotate\n * the relation between AST objects and the source string.\n */\nexport interface Localized {\n loc: SourceLocation;\n}\n\n/**\n * Wrapper type for localization,\n * can be used to state localization information about any other type (including primitive types)\n */\nexport interface Wrap<T> extends Localized {\n val: T;\n}\n\n/**\n * An 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\n/**\n * SourceLocation type that annotates that the node represents the AST representation of\n * the given range in the source string.\n */\nexport interface SourceLocationSource extends SourceLocationBase {\n sourceLocationType: 'source';\n start: number;\n end: number;\n}\n\n/**\n * Similar to {@link SourceLocationSource} but also carrying the source it related too.\n * All sourceLocation nodes that are descends of this one, relate themselves to this source.\n */\nexport interface SourceLocationInlinedSource extends SourceLocationBase, Localized {\n sourceLocationType: 'inlinedSource';\n /**\n * The string that will be used as the source for this node and the descends of this node.\n * Note that the generator will print the characters from newSource[0] until start. Likewise for the suffix.\n */\n newSource: string;\n /**\n * Behavior of the current loc, after replacing the source string.\n */\n loc: SourceLocation;\n /**\n * The range that this node replaces in the context of the original source.\n */\n start: number;\n end: number;\n startOnNew: number;\n endOnNew: 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\n/**\n * SourceLocation type that annotates that the node has been replaced\n * in relation to the original string by a new string.\n * It means that this node should be generated, and that the source string from start to end has been changed.\n */\nexport interface SourceLocationStringReplace extends SourceLocationBase {\n sourceLocationType: 'stringReplace';\n /**\n * The string that will replace the given range in the original source.\n */\n newSource: string;\n /**\n * The start of the region in the original source string that this node replaces.\n */\n start: number;\n /**\n * The end of the region in the original source string that this node replaces.\n */\n end: number;\n}\n\n/**\n * SourceLocation type that annotates that the node has been replaced in relation to the original string.\n * It means that this node should be generated, and that the source string from start to end has been changed.\n */\nexport interface SourceLocationNodeReplace extends SourceLocationBase {\n sourceLocationType: 'nodeReplace';\n /**\n * The start of the region in the original source string that this node replaces.\n */\n start: number;\n /**\n * The end of the region in the original source string that this node replaces.\n */\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 // Relate yourself to the source\n | SourceLocationSource\n // Add a new source\n | SourceLocationInlinedSource\n // No not generate anything for the current node and descendants\n | SourceLocationNoMaterialize\n // Replace some range by a string\n | SourceLocationStringReplace\n // Replace this node by some autogen\n | SourceLocationNodeReplace\n // Auto gen current node.\n | SourceLocationNodeAutoGenerate;\n"]}
|
package/dist/esm/lib/utils.d.ts
CHANGED
|
@@ -3,13 +3,23 @@ import type { ITokenConfig, TokenType } from '@traqula/chevrotain';
|
|
|
3
3
|
* Check whether the first two types overlap, if no, return the 3th argument, else the 4th.
|
|
4
4
|
*/
|
|
5
5
|
export type CheckOverlap<T, U, V, W = never> = T & U extends never ? V : W;
|
|
6
|
+
/**
|
|
7
|
+
* Lowercase the first letter of a given string.
|
|
8
|
+
* @param str
|
|
9
|
+
*/
|
|
6
10
|
export declare function unCapitalize<T extends string>(str: T): Uncapitalize<T>;
|
|
7
11
|
export type NamedToken<Name extends string = string> = TokenType & {
|
|
8
12
|
name: Name;
|
|
9
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Create a token in a typesafe way necessary by the traqula core builders.
|
|
16
|
+
*/
|
|
10
17
|
export declare function createToken<Name extends string>(config: ITokenConfig & {
|
|
11
18
|
name: Name;
|
|
12
19
|
}): NamedToken<Name>;
|
|
20
|
+
/**
|
|
21
|
+
* Patch a given type by changing the value-type of a specific key in the given object type.
|
|
22
|
+
*/
|
|
13
23
|
export type Patch<T extends object, Patch extends {
|
|
14
24
|
[Key in keyof T]?: unknown;
|
|
15
25
|
}> = {
|
package/dist/esm/lib/utils.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { createToken as chevcT } from '@traqula/chevrotain';
|
|
2
|
+
/**
|
|
3
|
+
* Lowercase the first letter of a given string.
|
|
4
|
+
* @param str
|
|
5
|
+
*/
|
|
2
6
|
export function unCapitalize(str) {
|
|
3
7
|
return (str.charAt(0).toLowerCase() + str.slice(1));
|
|
4
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a token in a typesafe way necessary by the traqula core builders.
|
|
11
|
+
*/
|
|
5
12
|
export function createToken(config) {
|
|
6
13
|
return chevcT(config);
|
|
7
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAO5D,MAAM,UAAU,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,MAAM,UAAU,WAAW,CAAsB,MAAqC;IACpF,OAAoC,MAAM,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAO5D;;;GAGG;AACH,MAAM,UAAU,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;;GAEG;AACH,MAAM,UAAU,WAAW,CAAsB,MAAqC;IACpF,OAAoC,MAAM,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC;AAQD;;;GAGG;AACH,MAAM,CAAC,MAAM,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\n/**\n * Lowercase the first letter of a given string.\n * @param str\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\n/**\n * Create a token in a typesafe way necessary by the traqula core builders.\n */\nexport function createToken<Name extends string>(config: ITokenConfig & { name: Name }): NamedToken<Name> {\n return <TokenType & { name: Name }> chevcT(config);\n}\n\n/**\n * Patch a given type by changing the value-type of a specific key in the given object type.\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"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traqula/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"description": "Core components of Traqula",
|
|
6
6
|
"lsd:module": true,
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"build:cjs": "node \"../../node_modules/typescript/bin/tsc\" -b tsconfig.cjs.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@traqula/chevrotain": "^0.0
|
|
44
|
+
"@traqula/chevrotain": "^1.0.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "9e648d6d9081a3b4f994599fa22116414914746f"
|
|
47
47
|
}
|