@lionweb/class-core-generator 0.6.13-beta.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/LICENSE +201 -0
- package/dist/api/entity-types.templates.d.ts +4 -0
- package/dist/api/entity-types.templates.d.ts.map +1 -0
- package/dist/api/entity-types.templates.js +171 -0
- package/dist/api/entity-types.templates.js.map +1 -0
- package/dist/api/generation-headers.d.ts +9 -0
- package/dist/api/generation-headers.d.ts.map +1 -0
- package/dist/api/generation-headers.js +40 -0
- package/dist/api/generation-headers.js.map +1 -0
- package/dist/api/generator.d.ts +11 -0
- package/dist/api/generator.d.ts.map +1 -0
- package/dist/api/generator.js +59 -0
- package/dist/api/generator.js.map +1 -0
- package/dist/api/helpers/classifiers.d.ts +6 -0
- package/dist/api/helpers/classifiers.d.ts.map +1 -0
- package/dist/api/helpers/classifiers.js +49 -0
- package/dist/api/helpers/classifiers.js.map +1 -0
- package/dist/api/helpers/dependencies.d.ts +11 -0
- package/dist/api/helpers/dependencies.d.ts.map +1 -0
- package/dist/api/helpers/dependencies.js +52 -0
- package/dist/api/helpers/dependencies.js.map +1 -0
- package/dist/api/helpers/entities.d.ts +5 -0
- package/dist/api/helpers/entities.d.ts.map +1 -0
- package/dist/api/helpers/entities.js +33 -0
- package/dist/api/helpers/entities.js.map +1 -0
- package/dist/api/helpers/features.d.ts +9 -0
- package/dist/api/helpers/features.d.ts.map +1 -0
- package/dist/api/helpers/features.js +96 -0
- package/dist/api/helpers/features.js.map +1 -0
- package/dist/api/helpers/imports-tracking.d.ts +22 -0
- package/dist/api/helpers/imports-tracking.d.ts.map +1 -0
- package/dist/api/helpers/imports-tracking.js +80 -0
- package/dist/api/helpers/imports-tracking.js.map +1 -0
- package/dist/api/helpers/index.d.ts +8 -0
- package/dist/api/helpers/index.d.ts.map +1 -0
- package/dist/api/helpers/index.js +24 -0
- package/dist/api/helpers/index.js.map +1 -0
- package/dist/api/helpers/mps-annotations.d.ts +19 -0
- package/dist/api/helpers/mps-annotations.d.ts.map +1 -0
- package/dist/api/helpers/mps-annotations.js +65 -0
- package/dist/api/helpers/mps-annotations.js.map +1 -0
- package/dist/api/helpers/types.d.ts +3 -0
- package/dist/api/helpers/types.d.ts.map +1 -0
- package/dist/api/helpers/types.js +28 -0
- package/dist/api/helpers/types.js.map +1 -0
- package/dist/api/index-ts.d.ts +4 -0
- package/dist/api/index-ts.d.ts.map +1 -0
- package/dist/api/index-ts.js +52 -0
- package/dist/api/index-ts.js.map +1 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +21 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/language-file.templates.d.ts +4 -0
- package/dist/api/language-file.templates.d.ts.map +1 -0
- package/dist/api/language-file.templates.js +65 -0
- package/dist/api/language-file.templates.js.map +1 -0
- package/dist/api/mega-factory.templates.d.ts +4 -0
- package/dist/api/mega-factory.templates.d.ts.map +1 -0
- package/dist/api/mega-factory.templates.js +61 -0
- package/dist/api/mega-factory.templates.js.map +1 -0
- package/dist/api/reflective-layer.templates.d.ts +4 -0
- package/dist/api/reflective-layer.templates.d.ts.map +1 -0
- package/dist/api/reflective-layer.templates.js +211 -0
- package/dist/api/reflective-layer.templates.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/json-as-ts.d.ts +2 -0
- package/dist/utils/json-as-ts.d.ts.map +1 -0
- package/dist/utils/json-as-ts.js +18 -0
- package/dist/utils/json-as-ts.js.map +1 -0
- package/dist/utils/string-sorting.d.ts +4 -0
- package/dist/utils/string-sorting.d.ts.map +1 -0
- package/dist/utils/string-sorting.js +23 -0
- package/dist/utils/string-sorting.js.map +1 -0
- package/dist/utils/textgen.d.ts +21 -0
- package/dist/utils/textgen.d.ts.map +1 -0
- package/dist/utils/textgen.js +67 -0
- package/dist/utils/textgen.js.map +1 -0
- package/dist/utils/toposort.d.ts +6 -0
- package/dist/utils/toposort.d.ts.map +1 -0
- package/dist/utils/toposort.js +41 -0
- package/dist/utils/toposort.js.map +1 -0
- package/package.json +34 -0
- package/src/api/entity-types.templates.ts +257 -0
- package/src/api/generation-headers.ts +47 -0
- package/src/api/generator.ts +84 -0
- package/src/api/helpers/classifiers.ts +67 -0
- package/src/api/helpers/dependencies.ts +62 -0
- package/src/api/helpers/entities.ts +43 -0
- package/src/api/helpers/features.ts +121 -0
- package/src/api/helpers/imports-tracking.ts +96 -0
- package/src/api/helpers/index.ts +24 -0
- package/src/api/helpers/mps-annotations.ts +69 -0
- package/src/api/helpers/types.ts +31 -0
- package/src/api/index-ts.ts +59 -0
- package/src/api/index.ts +21 -0
- package/src/api/language-file.templates.ts +79 -0
- package/src/api/mega-factory.templates.ts +79 -0
- package/src/api/reflective-layer.templates.ts +273 -0
- package/src/index.ts +19 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/json-as-ts.ts +20 -0
- package/src/utils/string-sorting.ts +29 -0
- package/src/utils/textgen.ts +89 -0
- package/src/utils/toposort.ts +49 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAEtC,OAAO,EAAC,gBAAgB,EAAE,wBAAwB,EAAE,4BAA4B,EAAC,MAAM,gBAAgB,CAAA;AACvG,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,6BAA6B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-file.templates.d.ts","sourceRoot":"","sources":["../../src/api/language-file.templates.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAmB,QAAQ,EAAC,MAAM,eAAe,CAAA;AASxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAA;AAY/C,eAAO,MAAM,eAAe,aAAc,QAAQ,WAAW,gBAAgB,WAuC5E,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
import { Concept, groupBy } from "@lionweb/core";
|
|
18
|
+
import { asString, commaSeparated, when, withNewlineAppended } from "littoral-templates";
|
|
19
|
+
import { typeForLanguageEntity } from "./entity-types.templates.js";
|
|
20
|
+
import { reflectiveClassFor } from "./reflective-layer.templates.js";
|
|
21
|
+
import { indent } from "../utils/textgen.js";
|
|
22
|
+
import { sortedStringsByUppercase } from "../utils/string-sorting.js";
|
|
23
|
+
import { dependencyOrderOf } from "../utils/toposort.js";
|
|
24
|
+
import { Imports } from "./helpers/index.js";
|
|
25
|
+
const importStatement = (dep, items) => when(items.length > 0)([
|
|
26
|
+
`import {`,
|
|
27
|
+
indent(commaSeparated(sortedStringsByUppercase(items))),
|
|
28
|
+
`} from "${dep}";`,
|
|
29
|
+
``
|
|
30
|
+
]);
|
|
31
|
+
export const languageFileFor = (language, options) => {
|
|
32
|
+
const { name, version, key, id, entities } = language;
|
|
33
|
+
const imports = new Imports(language);
|
|
34
|
+
const orderedEntities = dependencyOrderOf(entities, (entity) => (entity instanceof Concept && !!entity.extends) ? [entity.extends] : []);
|
|
35
|
+
if (typeof orderedEntities === "boolean") {
|
|
36
|
+
throw new Error(`language ${name} has a cycle among the graph of entities with edges formed by the inheritance dependency`);
|
|
37
|
+
}
|
|
38
|
+
const mpsAnnotationsPerId = groupBy(options.mpsAnnotations, ({ annotatedNodeId }) => annotatedNodeId);
|
|
39
|
+
const postImportsPart = [
|
|
40
|
+
``,
|
|
41
|
+
reflectiveClassFor(imports)(language),
|
|
42
|
+
``,
|
|
43
|
+
``,
|
|
44
|
+
orderedEntities
|
|
45
|
+
.filter((entity) => entity.language === language)
|
|
46
|
+
.map(withNewlineAppended(typeForLanguageEntity(imports, mpsAnnotationsPerId)))
|
|
47
|
+
];
|
|
48
|
+
return asString([
|
|
49
|
+
options?.header ?? [],
|
|
50
|
+
`/*
|
|
51
|
+
* language's metadata:
|
|
52
|
+
* name: ${name}
|
|
53
|
+
* version: ${version}
|
|
54
|
+
* key: ${key}
|
|
55
|
+
* id: ${id}
|
|
56
|
+
*/`,
|
|
57
|
+
``,
|
|
58
|
+
``,
|
|
59
|
+
importStatement(`@lionweb/core`, imports.coreImports),
|
|
60
|
+
importStatement(options.genericImportLocation, imports.genericImports),
|
|
61
|
+
importStatement(`./index.g.js`, imports.languageImports),
|
|
62
|
+
postImportsPart
|
|
63
|
+
]);
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=language-file.templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language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Annotation } from "./helpers/index.js";
|
|
3
|
+
export declare const megaFactoryFor: (megaFactoryName: string, languages: Language[], mpsAnnotations?: MpsAnnotation[], header?: string) => string;
|
|
4
|
+
//# sourceMappingURL=mega-factory.templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mega-factory.templates.d.ts","sourceRoot":"","sources":["../../src/api/mega-factory.templates.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAa,QAAQ,EAAiB,MAAM,eAAe,CAAA;AAIlE,OAAO,EAAa,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAG7D,eAAO,MAAM,cAAc,oBAAqB,MAAM,aAAa,QAAQ,EAAE,mBAAkB,aAAa,EAAE,WAAgB,MAAM,WAqDnI,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
import { isConcrete } from "@lionweb/core";
|
|
18
|
+
import { asString, commaSeparated } from "littoral-templates";
|
|
19
|
+
import { asJSIdentifier, indent } from "../utils/textgen.js";
|
|
20
|
+
import { Deprecated } from "./helpers/index.js";
|
|
21
|
+
export const megaFactoryFor = (megaFactoryName, languages, mpsAnnotations = [], header) => {
|
|
22
|
+
const isNotDeprecated = (entity) => !mpsAnnotations.some((mpsAnnotation) => mpsAnnotation.annotatedNodeId === entity.id && mpsAnnotation instanceof Deprecated);
|
|
23
|
+
const requiresFactoryMethod = (entity) => isConcrete(entity) && isNotDeprecated(entity);
|
|
24
|
+
const factoryFor = (language) => [
|
|
25
|
+
`${asJSIdentifier(language.name)}Factory = {`,
|
|
26
|
+
indent(commaSeparated(language.entities
|
|
27
|
+
.filter(requiresFactoryMethod)
|
|
28
|
+
.map((classifier) => `create${classifier.name}: () => ${asJSIdentifier(language.name)}.${classifier.name}.create(newId(), this.handleDelta)`))),
|
|
29
|
+
`}`,
|
|
30
|
+
``
|
|
31
|
+
];
|
|
32
|
+
const languagesWithFactoryMethods = languages
|
|
33
|
+
.filter((language) => language.entities.some(requiresFactoryMethod));
|
|
34
|
+
return asString([
|
|
35
|
+
header ?? [],
|
|
36
|
+
`import {DeltaHandler} from "@tls/lionweb-class-core";`,
|
|
37
|
+
``,
|
|
38
|
+
`import {`,
|
|
39
|
+
indent(commaSeparated(languagesWithFactoryMethods.map(({ name }) => asJSIdentifier(name)))),
|
|
40
|
+
`} from "./index.g.js";`,
|
|
41
|
+
``,
|
|
42
|
+
`import {newId} from "../index.js";`,
|
|
43
|
+
``,
|
|
44
|
+
``,
|
|
45
|
+
`export class ${megaFactoryName} {`,
|
|
46
|
+
indent([
|
|
47
|
+
``,
|
|
48
|
+
`constructor(`,
|
|
49
|
+
indent([
|
|
50
|
+
`public readonly handleDelta?: DeltaHandler`
|
|
51
|
+
]),
|
|
52
|
+
`) {`,
|
|
53
|
+
`}`,
|
|
54
|
+
``,
|
|
55
|
+
languagesWithFactoryMethods.map(factoryFor)
|
|
56
|
+
]),
|
|
57
|
+
`}`,
|
|
58
|
+
``
|
|
59
|
+
]);
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=mega-factory.templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,oCAAoC,CAAC,CACpJ,CAAC;QACF,GAAG;QACH,EAAE;KACL,CAAA;IAED,MAAM,2BAA2B,GAAG,SAAS;SACxC,MAAM,CACH,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAC9D,CAAA;IAEL,OAAO,QAAQ,CAAC;QACZ,MAAM,IAAI,EAAE;QACZ,uDAAuD;QACvD,EAAE;QACF,UAAU;QACV,MAAM,CAAC,cAAc,CACjB,2BAA2B,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAC,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CACpE,CAAC;QACF,wBAAwB;QACxB,EAAE;QACF,oCAAoC;QACpC,EAAE;QACF,EAAE;QACF,gBAAgB,eAAe,IAAI;QACnC,MAAM,CAAC;YACH,EAAE;YACF,cAAc;YACd,MAAM,CAAC;gBACH,4CAA4C;aAC/C,CAAC;YACF,KAAK;YACL,GAAG;YACH,EAAE;YACF,2BAA2B,CAAC,GAAG,CAAC,UAAU,CAAC;SAC9C,CAAC;QACF,GAAG;QACH,EAAE;KACL,CAAC,CAAA;AACN,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflective-layer.templates.d.ts","sourceRoot":"","sources":["../../src/api/reflective-layer.templates.ts"],"names":[],"mappings":"AAiBA,OAAO,EAaH,QAAQ,EAOX,MAAM,eAAe,CAAA;AAItB,OAAO,EAA8B,OAAO,EAA6B,MAAM,oBAAoB,CAAA;AAGnG,eAAO,MAAM,kBAAkB,YAAa,OAAO,gBA4J7B,QAAQ,0BAuE7B,CAAA"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
import { Annotation, asArray, Classifier, Concept, Enumeration, featureMetaType, Interface, isConcrete, isEnumeration, isMultiple, Link, nameOf, PrimitiveType, Property } from "@lionweb/core";
|
|
18
|
+
import { when, withNewlineAppended } from "littoral-templates";
|
|
19
|
+
import { indent, switchOrIf } from "../utils/textgen.js";
|
|
20
|
+
import { entityMetaType, extendsFrom, nameOfBaseClassForLanguage } from "./helpers/index.js";
|
|
21
|
+
export const reflectiveClassFor = (imports) => {
|
|
22
|
+
// classifier:
|
|
23
|
+
const reflectiveMembersForFeature = (feature) => {
|
|
24
|
+
const { classifier, name, key, id, optional } = feature;
|
|
25
|
+
const metaType = featureMetaType(feature);
|
|
26
|
+
const qName = `${classifier.name}_${name}`;
|
|
27
|
+
return [
|
|
28
|
+
`private readonly _${qName} = new ${imports.core(metaType)}(this._${classifier.name}, "${name}", "${key}", "${id}")${optional ? ".isOptional()" : ""}${isMultiple(feature) ? ".isMultiple()" : ""};`,
|
|
29
|
+
// | core (2nd x) |
|
|
30
|
+
`get ${qName}(): ${metaType} {`,
|
|
31
|
+
indent([
|
|
32
|
+
`this.ensureWiredUp();`,
|
|
33
|
+
`return this._${qName};`
|
|
34
|
+
]),
|
|
35
|
+
`}`
|
|
36
|
+
];
|
|
37
|
+
};
|
|
38
|
+
const reflectiveMembersForClassifier = (classifier) => {
|
|
39
|
+
const { name, key, id, features } = classifier;
|
|
40
|
+
const metaType = entityMetaType(classifier);
|
|
41
|
+
return [
|
|
42
|
+
`public readonly _${name} = new ${imports.core(metaType)}(this._language, "${name}", "${key}", "${id}"${classifier instanceof Concept ? (", " + classifier.abstract) : ""});`,
|
|
43
|
+
// | core (2nd x) |
|
|
44
|
+
`get ${name}(): ${metaType} {`,
|
|
45
|
+
indent([
|
|
46
|
+
`this.ensureWiredUp();`,
|
|
47
|
+
`return this._${name};`
|
|
48
|
+
]),
|
|
49
|
+
`}`,
|
|
50
|
+
features.map(reflectiveMembersForFeature)
|
|
51
|
+
];
|
|
52
|
+
};
|
|
53
|
+
// enumeration:
|
|
54
|
+
const reflectiveMemberForEnumerationLiteral = ({ enumeration, name, key, id }) => {
|
|
55
|
+
const qName = `${enumeration.name}_${name}`;
|
|
56
|
+
return [
|
|
57
|
+
`private readonly _${qName} = new ${imports.core("EnumerationLiteral")}(this._${enumeration.name}, "${name}", "${key}", "${id}");`,
|
|
58
|
+
// | core (2nd x) |
|
|
59
|
+
`get ${qName}(): EnumerationLiteral {`,
|
|
60
|
+
indent([
|
|
61
|
+
`this.ensureWiredUp();`,
|
|
62
|
+
`return this._${qName};`
|
|
63
|
+
]),
|
|
64
|
+
`}`
|
|
65
|
+
];
|
|
66
|
+
};
|
|
67
|
+
const reflectiveMembersForEnumeration = ({ name, key, id, literals }) => [
|
|
68
|
+
`public readonly _${name} = new ${imports.core("Enumeration")}(this._language, "${name}", "${key}", "${id}");`,
|
|
69
|
+
// | core (2nd x) |
|
|
70
|
+
`get ${name}(): Enumeration {`,
|
|
71
|
+
indent([
|
|
72
|
+
`this.ensureWiredUp();`,
|
|
73
|
+
`return this._${name};`
|
|
74
|
+
]),
|
|
75
|
+
`}`,
|
|
76
|
+
literals.map(reflectiveMemberForEnumerationLiteral)
|
|
77
|
+
];
|
|
78
|
+
const reflectiveMembersForPrimitiveType = ({ name, key, id }) => [
|
|
79
|
+
`public readonly _${name} = new ${imports.core("PrimitiveType")}(this._language, "${name}", "${key}", "${id}");`,
|
|
80
|
+
// | core (2nd x) |
|
|
81
|
+
`get ${name}(): PrimitiveType {`,
|
|
82
|
+
indent([
|
|
83
|
+
`this.ensureWiredUp();`,
|
|
84
|
+
`return this._${name};`
|
|
85
|
+
]),
|
|
86
|
+
`}`
|
|
87
|
+
];
|
|
88
|
+
const reflectiveMembersForEntity = (entity) => {
|
|
89
|
+
if (entity instanceof Classifier) {
|
|
90
|
+
return reflectiveMembersForClassifier(entity);
|
|
91
|
+
}
|
|
92
|
+
if (entity instanceof Enumeration) {
|
|
93
|
+
return reflectiveMembersForEnumeration(entity);
|
|
94
|
+
}
|
|
95
|
+
if (entity instanceof PrimitiveType) {
|
|
96
|
+
return reflectiveMembersForPrimitiveType(entity);
|
|
97
|
+
}
|
|
98
|
+
return `// unhandled language entity <${entityMetaType(entity)}>"${entity.name}"`;
|
|
99
|
+
};
|
|
100
|
+
const refForType = (type) => {
|
|
101
|
+
if (type === null) {
|
|
102
|
+
return `???`;
|
|
103
|
+
}
|
|
104
|
+
if (type.language === imports.thisLanguage) {
|
|
105
|
+
return `this._${type.name}`;
|
|
106
|
+
}
|
|
107
|
+
return `${imports.language(type.language)}.INSTANCE._${type.name}`;
|
|
108
|
+
};
|
|
109
|
+
const wireUpStatementsForProperty = (property) => {
|
|
110
|
+
const { classifier, name, type, optional } = property;
|
|
111
|
+
return `this._${classifier.name}_${name}.ofType(${refForType(type)})${optional ? ".isOptional()" : ""};`;
|
|
112
|
+
};
|
|
113
|
+
const wireUpStatementsForLink = (link) => {
|
|
114
|
+
const { classifier, name, type } = link;
|
|
115
|
+
return `this._${classifier.name}_${name}.ofType(${refForType(type)});`;
|
|
116
|
+
};
|
|
117
|
+
const wireUpStatementsForFeature = (feature) => {
|
|
118
|
+
if (feature instanceof Property) {
|
|
119
|
+
return wireUpStatementsForProperty(feature);
|
|
120
|
+
}
|
|
121
|
+
if (feature instanceof Link) {
|
|
122
|
+
return wireUpStatementsForLink(feature);
|
|
123
|
+
}
|
|
124
|
+
return `// unhandled feature <${featureMetaType(feature)}>"${feature.name}"`;
|
|
125
|
+
};
|
|
126
|
+
const isConcreteClassifier = (classifier) => classifier instanceof Annotation || classifier instanceof Concept;
|
|
127
|
+
const wireUpStatementsForEntity = (entity) => {
|
|
128
|
+
const { name } = entity;
|
|
129
|
+
const thisLocalName = (localName) => `this._${name}_${localName}`;
|
|
130
|
+
if (entity instanceof Classifier) {
|
|
131
|
+
const extends_ = extendsFrom(entity);
|
|
132
|
+
return [
|
|
133
|
+
extends_ instanceof Classifier
|
|
134
|
+
? `this._${name}.extends = ${refForType(extends_)};`
|
|
135
|
+
: [],
|
|
136
|
+
when(entity instanceof Interface && entity.extends.length > 0)(() => `this._${name}.extending(${entity.extends.map((interface_) => refForType(interface_)).join(", ")});`),
|
|
137
|
+
when(isConcreteClassifier(entity) && entity.implements.length > 0)(() => `this._${name}.implementing(${asArray(entity.implements).map((interface_) => refForType(interface_)).join(", ")});`),
|
|
138
|
+
when(entity.features.length > 0)(`this._${name}.havingFeatures(${entity.features.map(nameOf).map(thisLocalName).join(", ")});`),
|
|
139
|
+
entity.features.map(wireUpStatementsForFeature)
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
if (entity instanceof Enumeration) {
|
|
143
|
+
return `this._${name}.havingLiterals(${entity.literals.map(nameOf).map(thisLocalName).join(", ")});`;
|
|
144
|
+
}
|
|
145
|
+
if (entity instanceof PrimitiveType) {
|
|
146
|
+
return []; // (nothing to do)
|
|
147
|
+
}
|
|
148
|
+
return `// unhandled language entity <${entityMetaType(entity)}>"${name}"`;
|
|
149
|
+
};
|
|
150
|
+
return (language) => {
|
|
151
|
+
const { version, id, key, entities } = language;
|
|
152
|
+
const enumerations = entities.filter(isEnumeration);
|
|
153
|
+
const concreteClassifiers = entities.filter(isConcrete);
|
|
154
|
+
const parameterPrefix = concreteClassifiers.length === 0 ? "_" : "";
|
|
155
|
+
const thisLocalName = (localName) => `this._${localName}`;
|
|
156
|
+
return [
|
|
157
|
+
`export class ${imports.thisBaseClassName} implements ${imports.generic("ILanguageBase")} {`,
|
|
158
|
+
``,
|
|
159
|
+
indent([
|
|
160
|
+
// | core | (2nd x)
|
|
161
|
+
`private readonly _language: ${imports.core("Language")} = new Language("${imports.thisLanguageNameAsJsIdentifier}", "${version}", "${id}", "${key}");`,
|
|
162
|
+
// | core | (3rd x)
|
|
163
|
+
`get language(): Language {`,
|
|
164
|
+
indent([
|
|
165
|
+
`this.ensureWiredUp();`,
|
|
166
|
+
`return this._language;`
|
|
167
|
+
]),
|
|
168
|
+
`}`,
|
|
169
|
+
``,
|
|
170
|
+
entities.map(withNewlineAppended(reflectiveMembersForEntity)),
|
|
171
|
+
`private _wiredUp: boolean = false;`,
|
|
172
|
+
`private ensureWiredUp() {`,
|
|
173
|
+
indent([
|
|
174
|
+
`if (this._wiredUp) {`,
|
|
175
|
+
indent(`return;`),
|
|
176
|
+
`}`,
|
|
177
|
+
`this._language.havingEntities(${entities.map(nameOf).map(thisLocalName).join(", ")});`,
|
|
178
|
+
entities.map(wireUpStatementsForEntity),
|
|
179
|
+
`this._wiredUp = true;`
|
|
180
|
+
]),
|
|
181
|
+
`}`,
|
|
182
|
+
``,
|
|
183
|
+
`factory(${parameterPrefix}handleDelta?: ${imports.generic("DeltaHandler")}): ${imports.generic("NodeBaseFactory")} {`,
|
|
184
|
+
indent([
|
|
185
|
+
`return (classifier: ${imports.core("Classifier")}, ${parameterPrefix}id: ${imports.core("Id")}) => {`,
|
|
186
|
+
indent(switchOrIf("classifier.key", concreteClassifiers.map(nameOf).map((name) => [`this._${name}.key`, `${name}.create(id, ${parameterPrefix}handleDelta)`]), [
|
|
187
|
+
`const {language} = classifier;`,
|
|
188
|
+
`throw new Error(\`can't instantiate \${classifier.name} (key=\${classifier.key}): classifier is not known in language \${language.name} (key=\${language.key}, version=\${language.version})\`);`
|
|
189
|
+
])),
|
|
190
|
+
`}`
|
|
191
|
+
]),
|
|
192
|
+
`}`,
|
|
193
|
+
``,
|
|
194
|
+
`enumLiteralFrom<EnumType>(enumerationLiteral: ${imports.core("EnumerationLiteral")}): EnumType {`,
|
|
195
|
+
// (Why can this work?! EnumType is an unsatisfied generic parameter!)
|
|
196
|
+
indent([
|
|
197
|
+
`const {enumeration} = enumerationLiteral;`,
|
|
198
|
+
switchOrIf("enumeration.key", enumerations.map(nameOf).map((name) => [`this._${name}.key`, "enumerationLiteral.key as EnumType"]), [
|
|
199
|
+
`const {language} = enumeration;`,
|
|
200
|
+
`throw new Error(\`enumeration with key \${enumeration.key} is not known in language \${language.name} (key=\${language.key}, version=\${language.version})\`);`
|
|
201
|
+
])
|
|
202
|
+
]),
|
|
203
|
+
`}`,
|
|
204
|
+
``,
|
|
205
|
+
`public static readonly INSTANCE = new ${nameOfBaseClassForLanguage(language)}();`
|
|
206
|
+
]),
|
|
207
|
+
`}`
|
|
208
|
+
];
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=reflective-layer.templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflective-layer.templates.js","sourceRoot":"","sources":["../../src/api/reflective-layer.templates.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAEtC,OAAO,EACH,UAAU,EACV,OAAO,EACP,UAAU,EACV,OAAO,EACP,WAAW,EAGX,eAAe,EACf,SAAS,EACT,UAAU,EACV,aAAa,EACb,UAAU,EAGV,IAAI,EACJ,MAAM,EACN,aAAa,EACb,QAAQ,EAEX,MAAM,eAAe,CAAA;AACtB,OAAO,EAAC,IAAI,EAAE,mBAAmB,EAAC,MAAM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
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
export * from "./api/index.js";
|
|
18
|
+
export * from "./utils/index.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAEtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAC,aAAa,EAAE,wBAAwB,EAAC,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
export { asTypeScript } from "./json-as-ts.js";
|
|
18
|
+
export { sortedStrings, sortedStringsByUppercase } from "./string-sorting.js";
|
|
19
|
+
export { indent } from "./textgen.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAEtC,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAC,aAAa,EAAE,wBAAwB,EAAC,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-as-ts.d.ts","sourceRoot":"","sources":["../../src/utils/json-as-ts.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,YAAY,SAAU,OAAO,WACwB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
export const asTypeScript = (json) => JSON.stringify(json, null, 4).replaceAll(/"(.+?)": /g, `$1: `);
|
|
18
|
+
//# sourceMappingURL=json-as-ts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-as-ts.js","sourceRoot":"","sources":["../../src/utils/json-as-ts.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAa,EAAE,EAAE,CAC1C,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-sorting.d.ts","sourceRoot":"","sources":["../../src/utils/string-sorting.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAA;AAQ1D,eAAO,MAAM,aAAa,cAAkC,CAAA;AAE5D,eAAO,MAAM,wBAAwB,cAAgD,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
const sortedStringsWith = (strMap) => (strings) => {
|
|
18
|
+
strings.sort((l, r) => strMap(l).localeCompare(strMap(r)));
|
|
19
|
+
return strings;
|
|
20
|
+
};
|
|
21
|
+
export const sortedStrings = sortedStringsWith((str) => str);
|
|
22
|
+
export const sortedStringsByUppercase = sortedStringsWith((str) => str.toUpperCase());
|
|
23
|
+
//# sourceMappingURL=string-sorting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-sorting.js","sourceRoot":"","sources":["../../src/utils/string-sorting.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAItC,MAAM,iBAAiB,GAAG,CAAC,MAA+B,EAAgB,EAAE,CACxE,CAAC,OAAO,EAAE,EAAE;IACR,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1D,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAA;AAE5D,MAAM,CAAC,MAAM,wBAAwB,GAAG,iBAAiB,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Template } from "littoral-templates";
|
|
2
|
+
/**
|
|
3
|
+
* @return an indenter function that indents by 4 spaces.
|
|
4
|
+
*/
|
|
5
|
+
export declare const indent: (_: Template) => string[];
|
|
6
|
+
/**
|
|
7
|
+
* @return the given string but with its first character lower-cased (when possible).
|
|
8
|
+
*/
|
|
9
|
+
export declare const withFirstLower: (str: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* @return the given string but with its first character upper-cased (when possible).
|
|
12
|
+
*/
|
|
13
|
+
export declare const withFirstUpper: (str: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* @return a sanitized version of the given string that should be suitable as a valid JavaScript identifier.
|
|
16
|
+
*/
|
|
17
|
+
export declare const asJSIdentifier: (str: string) => string;
|
|
18
|
+
export declare const wrapInIf: (condition: boolean, left: () => string, right: string) => (text: string) => string;
|
|
19
|
+
export type MatchCase = [caseExpression: string, returnValue: string];
|
|
20
|
+
export declare const switchOrIf: (expression: string, cases: MatchCase[], defaultBlock: Template) => Template[];
|
|
21
|
+
//# sourceMappingURL=textgen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textgen.d.ts","sourceRoot":"","sources":["../../src/utils/textgen.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAuB,QAAQ,EAAC,MAAM,oBAAoB,CAAA;AAGjE;;GAEG;AACH,eAAO,MAAM,MAAM,2BAAwB,CAAA;AAY3C;;GAEG;AACH,eAAO,MAAM,cAAc,QAXjB,MAAM,WAWsD,CAAA;AAEtE;;GAEG;AACH,eAAO,MAAM,cAAc,QAhBjB,MAAM,WAgBsD,CAAA;AAGtE;;GAEG;AACH,eAAO,MAAM,cAAc,QAAS,MAAM,KAAG,MAGhB,CAAA;AAG7B,eAAO,MAAM,QAAQ,cAAe,OAAO,QAAQ,MAAM,MAAM,SAAS,MAAM,YACnE,MAAM,WAGC,CAAA;AAGlB,MAAM,MAAM,SAAS,GAAG,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;AAErE,eAAO,MAAM,UAAU,eAAgB,MAAM,SAAS,SAAS,EAAE,gBAAgB,QAAQ,eAiBhF,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright 2025 TRUMPF Laser SE and other contributors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License")
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
/*
|
|
18
|
+
* NOTE: this code is copied verbatim from the @lionweb/utilities package, and subsequently modified/added to.
|
|
19
|
+
* This code should “flow back” to the @lionweb packages.
|
|
20
|
+
*/
|
|
21
|
+
import { asString, indentWith } from "littoral-templates";
|
|
22
|
+
/**
|
|
23
|
+
* @return an indenter function that indents by 4 spaces.
|
|
24
|
+
*/
|
|
25
|
+
export const indent = indentWith(" ")(1);
|
|
26
|
+
const withFirstCased = (charFunc) => (str) => {
|
|
27
|
+
if (str.length === 0) {
|
|
28
|
+
return str;
|
|
29
|
+
}
|
|
30
|
+
return charFunc(str.charAt(0))
|
|
31
|
+
+ (str.length > 1 ? str.substring(1) : "");
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @return the given string but with its first character lower-cased (when possible).
|
|
35
|
+
*/
|
|
36
|
+
export const withFirstLower = withFirstCased((ch) => ch.toLowerCase());
|
|
37
|
+
/**
|
|
38
|
+
* @return the given string but with its first character upper-cased (when possible).
|
|
39
|
+
*/
|
|
40
|
+
export const withFirstUpper = withFirstCased((ch) => ch.toUpperCase());
|
|
41
|
+
/**
|
|
42
|
+
* @return a sanitized version of the given string that should be suitable as a valid JavaScript identifier.
|
|
43
|
+
*/
|
|
44
|
+
export const asJSIdentifier = (str) => str
|
|
45
|
+
.replaceAll(".", "_")
|
|
46
|
+
.replaceAll("-", "_");
|
|
47
|
+
export const wrapInIf = (condition, left, right) => (text) => condition
|
|
48
|
+
? `${left()}${text}${right}`
|
|
49
|
+
: text;
|
|
50
|
+
export const switchOrIf = (expression, cases, defaultBlock) => cases.length > 1
|
|
51
|
+
? [
|
|
52
|
+
`switch (${expression}) {`,
|
|
53
|
+
indent([
|
|
54
|
+
cases.map(([caseExpression, returnValue]) => `case ${caseExpression}: return ${returnValue};`),
|
|
55
|
+
`default: ${typeof defaultBlock === "string" ? defaultBlock : asString(["{", indent(defaultBlock), "}"])}`
|
|
56
|
+
]),
|
|
57
|
+
`}`
|
|
58
|
+
]
|
|
59
|
+
: [
|
|
60
|
+
cases.map(([caseExpression, returnValue]) => [
|
|
61
|
+
`if (${expression} === ${caseExpression}) {`,
|
|
62
|
+
indent(`return ${returnValue};`),
|
|
63
|
+
`}`
|
|
64
|
+
]),
|
|
65
|
+
defaultBlock
|
|
66
|
+
];
|
|
67
|
+
//# sourceMappingURL=textgen.js.map
|