@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.
Files changed (113) hide show
  1. package/LICENSE +201 -0
  2. package/dist/api/entity-types.templates.d.ts +4 -0
  3. package/dist/api/entity-types.templates.d.ts.map +1 -0
  4. package/dist/api/entity-types.templates.js +171 -0
  5. package/dist/api/entity-types.templates.js.map +1 -0
  6. package/dist/api/generation-headers.d.ts +9 -0
  7. package/dist/api/generation-headers.d.ts.map +1 -0
  8. package/dist/api/generation-headers.js +40 -0
  9. package/dist/api/generation-headers.js.map +1 -0
  10. package/dist/api/generator.d.ts +11 -0
  11. package/dist/api/generator.d.ts.map +1 -0
  12. package/dist/api/generator.js +59 -0
  13. package/dist/api/generator.js.map +1 -0
  14. package/dist/api/helpers/classifiers.d.ts +6 -0
  15. package/dist/api/helpers/classifiers.d.ts.map +1 -0
  16. package/dist/api/helpers/classifiers.js +49 -0
  17. package/dist/api/helpers/classifiers.js.map +1 -0
  18. package/dist/api/helpers/dependencies.d.ts +11 -0
  19. package/dist/api/helpers/dependencies.d.ts.map +1 -0
  20. package/dist/api/helpers/dependencies.js +52 -0
  21. package/dist/api/helpers/dependencies.js.map +1 -0
  22. package/dist/api/helpers/entities.d.ts +5 -0
  23. package/dist/api/helpers/entities.d.ts.map +1 -0
  24. package/dist/api/helpers/entities.js +33 -0
  25. package/dist/api/helpers/entities.js.map +1 -0
  26. package/dist/api/helpers/features.d.ts +9 -0
  27. package/dist/api/helpers/features.d.ts.map +1 -0
  28. package/dist/api/helpers/features.js +96 -0
  29. package/dist/api/helpers/features.js.map +1 -0
  30. package/dist/api/helpers/imports-tracking.d.ts +22 -0
  31. package/dist/api/helpers/imports-tracking.d.ts.map +1 -0
  32. package/dist/api/helpers/imports-tracking.js +80 -0
  33. package/dist/api/helpers/imports-tracking.js.map +1 -0
  34. package/dist/api/helpers/index.d.ts +8 -0
  35. package/dist/api/helpers/index.d.ts.map +1 -0
  36. package/dist/api/helpers/index.js +24 -0
  37. package/dist/api/helpers/index.js.map +1 -0
  38. package/dist/api/helpers/mps-annotations.d.ts +19 -0
  39. package/dist/api/helpers/mps-annotations.d.ts.map +1 -0
  40. package/dist/api/helpers/mps-annotations.js +65 -0
  41. package/dist/api/helpers/mps-annotations.js.map +1 -0
  42. package/dist/api/helpers/types.d.ts +3 -0
  43. package/dist/api/helpers/types.d.ts.map +1 -0
  44. package/dist/api/helpers/types.js +28 -0
  45. package/dist/api/helpers/types.js.map +1 -0
  46. package/dist/api/index-ts.d.ts +4 -0
  47. package/dist/api/index-ts.d.ts.map +1 -0
  48. package/dist/api/index-ts.js +52 -0
  49. package/dist/api/index-ts.js.map +1 -0
  50. package/dist/api/index.d.ts +5 -0
  51. package/dist/api/index.d.ts.map +1 -0
  52. package/dist/api/index.js +21 -0
  53. package/dist/api/index.js.map +1 -0
  54. package/dist/api/language-file.templates.d.ts +4 -0
  55. package/dist/api/language-file.templates.d.ts.map +1 -0
  56. package/dist/api/language-file.templates.js +65 -0
  57. package/dist/api/language-file.templates.js.map +1 -0
  58. package/dist/api/mega-factory.templates.d.ts +4 -0
  59. package/dist/api/mega-factory.templates.d.ts.map +1 -0
  60. package/dist/api/mega-factory.templates.js +61 -0
  61. package/dist/api/mega-factory.templates.js.map +1 -0
  62. package/dist/api/reflective-layer.templates.d.ts +4 -0
  63. package/dist/api/reflective-layer.templates.d.ts.map +1 -0
  64. package/dist/api/reflective-layer.templates.js +211 -0
  65. package/dist/api/reflective-layer.templates.js.map +1 -0
  66. package/dist/index.d.ts +3 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +19 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/utils/index.d.ts +4 -0
  71. package/dist/utils/index.d.ts.map +1 -0
  72. package/dist/utils/index.js +20 -0
  73. package/dist/utils/index.js.map +1 -0
  74. package/dist/utils/json-as-ts.d.ts +2 -0
  75. package/dist/utils/json-as-ts.d.ts.map +1 -0
  76. package/dist/utils/json-as-ts.js +18 -0
  77. package/dist/utils/json-as-ts.js.map +1 -0
  78. package/dist/utils/string-sorting.d.ts +4 -0
  79. package/dist/utils/string-sorting.d.ts.map +1 -0
  80. package/dist/utils/string-sorting.js +23 -0
  81. package/dist/utils/string-sorting.js.map +1 -0
  82. package/dist/utils/textgen.d.ts +21 -0
  83. package/dist/utils/textgen.d.ts.map +1 -0
  84. package/dist/utils/textgen.js +67 -0
  85. package/dist/utils/textgen.js.map +1 -0
  86. package/dist/utils/toposort.d.ts +6 -0
  87. package/dist/utils/toposort.d.ts.map +1 -0
  88. package/dist/utils/toposort.js +41 -0
  89. package/dist/utils/toposort.js.map +1 -0
  90. package/package.json +34 -0
  91. package/src/api/entity-types.templates.ts +257 -0
  92. package/src/api/generation-headers.ts +47 -0
  93. package/src/api/generator.ts +84 -0
  94. package/src/api/helpers/classifiers.ts +67 -0
  95. package/src/api/helpers/dependencies.ts +62 -0
  96. package/src/api/helpers/entities.ts +43 -0
  97. package/src/api/helpers/features.ts +121 -0
  98. package/src/api/helpers/imports-tracking.ts +96 -0
  99. package/src/api/helpers/index.ts +24 -0
  100. package/src/api/helpers/mps-annotations.ts +69 -0
  101. package/src/api/helpers/types.ts +31 -0
  102. package/src/api/index-ts.ts +59 -0
  103. package/src/api/index.ts +21 -0
  104. package/src/api/language-file.templates.ts +79 -0
  105. package/src/api/mega-factory.templates.ts +79 -0
  106. package/src/api/reflective-layer.templates.ts +273 -0
  107. package/src/index.ts +19 -0
  108. package/src/utils/index.ts +21 -0
  109. package/src/utils/json-as-ts.ts +20 -0
  110. package/src/utils/string-sorting.ts +29 -0
  111. package/src/utils/textgen.ts +89 -0
  112. package/src/utils/toposort.ts +49 -0
  113. package/tsconfig.json +7 -0
@@ -0,0 +1,121 @@
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
+ import {
19
+ builtinClassifiers,
20
+ Classifier,
21
+ Datatype,
22
+ Enumeration,
23
+ Feature,
24
+ isContainment,
25
+ isProperty,
26
+ isReference,
27
+ LanguageEntity,
28
+ Link,
29
+ PrimitiveType,
30
+ Property,
31
+ SingleRef
32
+ } from "@lionweb/core"
33
+ import {Imports, tsTypeForPrimitiveType} from "./index.js"
34
+
35
+
36
+ export const typeOf = (feature: Feature): SingleRef<LanguageEntity> => {
37
+ if (feature instanceof Property) {
38
+ return feature.type
39
+ }
40
+ if (feature instanceof Link) {
41
+ return feature.type
42
+ }
43
+ return null
44
+ }
45
+
46
+
47
+ export const tsTypeForDatatype = (datatype: SingleRef<Datatype>, imports: Imports) => {
48
+ if (datatype === null) {
49
+ return `unknown /* [ERROR] can't compute a TS type for a null datatype */`
50
+ }
51
+ if (datatype instanceof PrimitiveType) {
52
+ return tsTypeForPrimitiveType(datatype)
53
+ }
54
+ if (datatype instanceof Enumeration) {
55
+ return imports.entity(datatype)
56
+ }
57
+ return `unknown /* [ERROR] can't compute a TS type for datatype ${datatype.name} that has an unhandled/-known meta-type ${datatype.constructor.name} */`
58
+ }
59
+
60
+
61
+ export const tsTypeForClassifier = (classifier: SingleRef<Classifier>, imports: Imports) => {
62
+ if (classifier === null) {
63
+ return `unknown /* [ERROR] can't compute a TS type for a null classifier */`
64
+ }
65
+ return classifier === builtinClassifiers.node ? imports.generic("INodeBase") : imports.entity(classifier)
66
+ }
67
+
68
+
69
+ export const optionalityPostfix = (feature: Feature) => feature.optional ? " | undefined" : ""
70
+
71
+ export const tsFieldTypeForFeature = (feature: Feature, imports: Imports): string => {
72
+ const type = typeOf(feature)
73
+ if (type === null) {
74
+ return `unknown /* [ERROR] can't compute a TS type for feature ${feature.name} on classifier ${feature.classifier.name} with null type */`
75
+ }
76
+ if (isProperty(feature)) {
77
+ const typeId = (() => {
78
+ if (type instanceof PrimitiveType) {
79
+ return tsTypeForPrimitiveType(type)
80
+ }
81
+ if (type instanceof Enumeration) {
82
+ return type.name
83
+ }
84
+ return `unknown /* [ERROR] can't compute a TS type for feature ${feature.name} on classifier ${feature.classifier.name} whose type has an unhandled/-known meta-type ${type.constructor.name} */`
85
+ })()
86
+ return `${typeId}${(optionalityPostfix(feature))}`
87
+ }
88
+ if (isContainment(feature)) {
89
+ const typeId = type === builtinClassifiers.node ? imports.generic("INodeBase") : imports.entity(type)
90
+ return `${typeId}${feature.multiple ? "[]" : optionalityPostfix(feature)}`
91
+ }
92
+ if (isReference(feature)) {
93
+ const typeId = type === builtinClassifiers.node ? imports.generic("INodeBase") : imports.entity(type)
94
+ return `${imports.core("SingleRef")}<${typeId}>${feature.multiple ? "[]" : optionalityPostfix(feature)}`
95
+ }
96
+ return `unknown /* [ERROR] can't compute a TS type for feature ${feature.name} on classifier ${feature.classifier.name} whose type has an unhandled/-known meta-type ${type.constructor.name} */`
97
+ }
98
+
99
+ export const tsTypeForValueManager = (feature: Feature, imports: Imports): string => {
100
+ const type = typeOf(feature)
101
+ if (type === null) {
102
+ return `unknown /* [ERROR] can't compute a TS type for feature ${feature.name} on classifier ${feature.classifier.name} with null type */`
103
+ }
104
+ if (isProperty(feature)) {
105
+ const typeId = (() => {
106
+ if (type instanceof PrimitiveType) {
107
+ return tsTypeForPrimitiveType(type)
108
+ }
109
+ if (type instanceof Enumeration) {
110
+ return type.name
111
+ }
112
+ return `unknown /* [ERROR] can't compute a TS type for feature ${feature.name} on classifier ${feature.classifier.name} whose type has an unhandled/-known meta-type ${type.constructor.name} */`
113
+ })()
114
+ return typeId
115
+ }
116
+ if (isContainment(feature) || isReference(feature)) {
117
+ return type === builtinClassifiers.node ? imports.generic("INodeBase") : imports.entity(type)
118
+ }
119
+ return `unknown /* [ERROR] can't compute a TS type for feature ${feature.name} on classifier ${feature.classifier.name} whose type has an unhandled/-known meta-type ${type.constructor.name} */`
120
+ }
121
+
@@ -0,0 +1,96 @@
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
+ import {Language, LanguageEntity, lioncoreBuiltins} from "@lionweb/core"
19
+ import {asJSIdentifier} from "../../utils/textgen.js"
20
+
21
+
22
+ export const importRenamingForLanguage = (language: Language) =>
23
+ asJSIdentifier(language.name)
24
+
25
+ export const nameOfBaseClassForLanguage = (language: Language) =>
26
+ asJSIdentifier(language.name) + "Base"
27
+
28
+
29
+ const lionCoreBuiltinsIdentifier = nameOfBaseClassForLanguage(lioncoreBuiltins)
30
+
31
+
32
+ export class Imports {
33
+
34
+ constructor(public readonly thisLanguage: Language) {
35
+ }
36
+
37
+ get thisLanguageNameAsJsIdentifier() {
38
+ return asJSIdentifier(this.thisLanguage.name)
39
+ }
40
+
41
+ get thisBaseClassName() {
42
+ return this.thisLanguageNameAsJsIdentifier + "Base"
43
+ }
44
+
45
+ private readonly _coreImports = new Set<string>()
46
+ get coreImports() {
47
+ return [...this._coreImports]
48
+ }
49
+ core(identifier: string) {
50
+ this._coreImports.add(identifier)
51
+ return identifier
52
+ }
53
+
54
+ private readonly _genericImports = new Set<string>()
55
+ get genericImports() {
56
+ return [...this._genericImports]
57
+ }
58
+ generic(identifier: string) {
59
+ this._genericImports.add(identifier)
60
+ return identifier
61
+ }
62
+
63
+ private readonly _indexImports = new Set<string>()
64
+ get indexImports() {
65
+ return [...this._indexImports]
66
+ }
67
+ entity(entity: LanguageEntity) {
68
+ if (entity.language === lioncoreBuiltins) {
69
+ this._genericImports.add(entity.name)
70
+ return entity.name
71
+ }
72
+ if (entity.language === this.thisLanguage) {
73
+ return entity.name
74
+ }
75
+ this._languageImports.add(importRenamingForLanguage(entity.language))
76
+ return `${importRenamingForLanguage(entity.language)}.${entity.name}`
77
+ }
78
+
79
+ private readonly _languageImports = new Set<string>()
80
+ get languageImports() {
81
+ return [...this._languageImports]
82
+ }
83
+ language(language: Language) {
84
+ if (language === lioncoreBuiltins) {
85
+ this._genericImports.add(lionCoreBuiltinsIdentifier)
86
+ return lionCoreBuiltinsIdentifier
87
+ }
88
+ const externalName = importRenamingForLanguage(language)
89
+ if (language === this.thisLanguage) {
90
+ return nameOfBaseClassForLanguage(language)
91
+ }
92
+ this._languageImports.add(externalName)
93
+ return `${externalName}.${nameOfBaseClassForLanguage(language)}`
94
+ }
95
+ }
96
+
@@ -0,0 +1,24 @@
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
+ export * from "./classifiers.js"
19
+ export * from "./dependencies.js"
20
+ export * from "./entities.js"
21
+ export * from "./features.js"
22
+ export * from "./imports-tracking.js"
23
+ export * from "./mps-annotations.js"
24
+ export * from "./types.js"
@@ -0,0 +1,69 @@
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
+ import {Id, SerializationChunk} from "@lionweb/core"
19
+
20
+
21
+ export abstract class MpsAnnotation {
22
+ constructor(public readonly annotatedNodeId: Id) {
23
+ }
24
+ }
25
+
26
+ export class ConceptDescription extends MpsAnnotation {
27
+ constructor(annotatedNodeId: Id, public readonly shortDescription: string | null, public readonly alias: string | null) {
28
+ super(annotatedNodeId)
29
+ }
30
+ toString() {
31
+ return `<ConceptDescription> annotatedNodeId=${this.annotatedNodeId}, shortDescription="${this.shortDescription}"`
32
+ }
33
+ }
34
+
35
+ export class Deprecated extends MpsAnnotation {
36
+ constructor(annotatedNodeId: Id, public readonly comment: string | null, public readonly build: string | null) {
37
+ super(annotatedNodeId)
38
+ }
39
+ toString() {
40
+ return `<Deprecated> annotatedNodeId=${this.annotatedNodeId}, comment="${this.comment}", build="${this.build}"`
41
+ }
42
+ }
43
+
44
+
45
+ export const extractedMpsAnnotations = ({nodes}: SerializationChunk): MpsAnnotation[] =>
46
+ nodes.flatMap<MpsAnnotation>(({classifier, properties, parent}) => {
47
+ const propertyValue = (key: string): string | null => {
48
+ const property = properties.find(({property}) => property.key === key)
49
+ return property === undefined
50
+ ? null
51
+ : property.value
52
+ }
53
+ if (classifier.language !== "io-lionweb-mps-specific" || classifier.version !== "0") {
54
+ return []
55
+ }
56
+ switch (classifier.key) {
57
+ case "ConceptDescription": {
58
+ return [new ConceptDescription(parent!, propertyValue("ConceptDescription-conceptShortDescription"), propertyValue("ConceptDescription-conceptAlias"))]
59
+ }
60
+ case "Deprecated": {
61
+ return [new Deprecated(parent!, propertyValue("Deprecated-comment"), propertyValue("Deprecated-build"))]
62
+ }
63
+ default: {
64
+ console.log(`couldn't handle MPS annotation with key ${classifier.key}`)
65
+ return []
66
+ }
67
+ }
68
+ })
69
+
@@ -0,0 +1,31 @@
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
+ import {builtinPrimitives, PrimitiveType} from "@lionweb/core"
19
+
20
+
21
+ export const tsTypeForPrimitiveType = (primitiveType: PrimitiveType): string => {
22
+ switch (primitiveType) {
23
+ case builtinPrimitives.booleanDatatype: return `boolean`
24
+ case builtinPrimitives.stringDatatype: return `string`
25
+ case builtinPrimitives.integerDatatype: return `number`
26
+ case builtinPrimitives.jsonDatatype: return `unknown`
27
+ default:
28
+ return `string`
29
+ }
30
+ }
31
+
@@ -0,0 +1,59 @@
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
+ import {Language} from "@lionweb/core"
19
+ import {asString, commaSeparated} from "littoral-templates"
20
+
21
+ import {indent} from "../utils/textgen.js"
22
+ import {dependencyOrderOf} from "../utils/toposort.js"
23
+ import {dependenciesThroughDirectInheritanceOf, importRenamingForLanguage, nameOfBaseClassForLanguage} from "./helpers/index.js"
24
+ import {GeneratorOptions} from "./generator.js"
25
+
26
+
27
+ export const indexTsFor = (languages: Language[], options: GeneratorOptions) => {
28
+ const dependenciesInOrderOfDirectInheritance = dependencyOrderOf(languages, dependenciesThroughDirectInheritanceOf)
29
+ if (dependenciesInOrderOfDirectInheritance === false) {
30
+ console.error(`⚠ CYCLE detected! Proceeding with order of languages as-is, instead of in type-wise (through direct inheritance) dependency order ⇒ generated code might not initialize!`)
31
+ }
32
+ const languagesForImports = dependenciesInOrderOfDirectInheritance === false
33
+ ? languages
34
+ : dependenciesInOrderOfDirectInheritance
35
+ .filter((language) => languages.indexOf(language) > -1)
36
+
37
+ return asString([
38
+ options.header === undefined ? [] : [options.header, ``],
39
+ `import {ILanguageBase, LionCore_builtinsBase} from "${options.genericImportLocation}";`,
40
+ ``,
41
+ languagesForImports.map((language) => `import * as ${importRenamingForLanguage(language)} from "./${language.name}.g.js";`),
42
+ ``,
43
+ `// ensure that all languages get wired up by triggering that through their first entity:`,
44
+ `LionCore_builtinsBase.INSTANCE.String;`,
45
+ languages
46
+ .filter(({entities}) => entities.length > 0)
47
+ .map((language) => `${importRenamingForLanguage(language)}.${nameOfBaseClassForLanguage(language)}.INSTANCE.${language.entities[0].name};`),
48
+ ``,
49
+ `export const allLanguageBases: ILanguageBase[] = [`,
50
+ indent(commaSeparated(languagesForImports.map((language) => `${importRenamingForLanguage(language)}.${nameOfBaseClassForLanguage(language)}.INSTANCE`))),
51
+ `];`,
52
+ ``,
53
+ `export {`,
54
+ indent(commaSeparated(languages.map(importRenamingForLanguage))),
55
+ `};`,
56
+ ``
57
+ ])
58
+ }
59
+
@@ -0,0 +1,21 @@
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
+ export {generateLanguage, generateApiFromLanguages, generateApiFromLanguagesJson} from "./generator.js"
19
+ export * from "./generation-headers.js"
20
+ export * from "./helpers/mps-annotations.js"
21
+ export * from "./mega-factory.templates.js"
@@ -0,0 +1,79 @@
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
+ import {Concept, groupBy, Language} from "@lionweb/core"
19
+ import {asString, commaSeparated, when, withNewlineAppended} from "littoral-templates"
20
+
21
+ import {typeForLanguageEntity} from "./entity-types.templates.js"
22
+ import {reflectiveClassFor} from "./reflective-layer.templates.js"
23
+ import {indent} from "../utils/textgen.js"
24
+ import {sortedStringsByUppercase} from "../utils/string-sorting.js"
25
+ import {dependencyOrderOf} from "../utils/toposort.js"
26
+ import {Imports} from "./helpers/index.js"
27
+ import {GeneratorOptions} from "./generator.js"
28
+
29
+
30
+ const importStatement = (dep: string, items: string[]) =>
31
+ when(items.length > 0)([
32
+ `import {`,
33
+ indent(commaSeparated(sortedStringsByUppercase(items))),
34
+ `} from "${dep}";`,
35
+ ``
36
+ ])
37
+
38
+
39
+ export const languageFileFor = (language: Language, options: GeneratorOptions) => {
40
+
41
+ const {name, version, key, id, entities} = language
42
+
43
+ const imports = new Imports(language)
44
+
45
+ const orderedEntities = dependencyOrderOf(entities, (entity) => (entity instanceof Concept && !!entity.extends) ? [entity.extends] : [])
46
+ if (typeof orderedEntities === "boolean") {
47
+ throw new Error(`language ${name} has a cycle among the graph of entities with edges formed by the inheritance dependency`)
48
+ }
49
+
50
+ const mpsAnnotationsPerId = groupBy(options.mpsAnnotations, ({annotatedNodeId}) => annotatedNodeId)
51
+
52
+ const postImportsPart = [
53
+ ``,
54
+ reflectiveClassFor(imports)(language),
55
+ ``,
56
+ ``,
57
+ orderedEntities
58
+ .filter((entity) => entity.language === language)
59
+ .map(withNewlineAppended(typeForLanguageEntity(imports, mpsAnnotationsPerId)))
60
+ ]
61
+
62
+ return asString([
63
+ options?.header ?? [],
64
+ `/*
65
+ * language's metadata:
66
+ * name: ${name}
67
+ * version: ${version}
68
+ * key: ${key}
69
+ * id: ${id}
70
+ */`,
71
+ ``,
72
+ ``,
73
+ importStatement(`@lionweb/core`, imports.coreImports),
74
+ importStatement(options.genericImportLocation, imports.genericImports),
75
+ importStatement(`./index.g.js`, imports.languageImports),
76
+ postImportsPart
77
+ ])
78
+ }
79
+
@@ -0,0 +1,79 @@
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
+ import {isConcrete, Language, LanguageEntity} from "@lionweb/core"
19
+ import {asString, commaSeparated} from "littoral-templates"
20
+
21
+ import {asJSIdentifier, indent} from "../utils/textgen.js"
22
+ import {Deprecated, MpsAnnotation} from "./helpers/index.js";
23
+
24
+
25
+ export const megaFactoryFor = (megaFactoryName: string, languages: Language[], mpsAnnotations: MpsAnnotation[] = [], header?: string) => {
26
+ const isNotDeprecated = (entity: LanguageEntity)=>
27
+ !mpsAnnotations.some(
28
+ (mpsAnnotation) => mpsAnnotation.annotatedNodeId === entity.id && mpsAnnotation instanceof Deprecated
29
+ )
30
+
31
+ const requiresFactoryMethod = (entity: LanguageEntity) =>
32
+ isConcrete(entity) && isNotDeprecated(entity)
33
+
34
+ const factoryFor = (language: Language) => [
35
+ `${asJSIdentifier(language.name)}Factory = {`,
36
+ indent(commaSeparated(
37
+ language.entities
38
+ .filter(requiresFactoryMethod)
39
+ .map((classifier) => `create${classifier.name}: () => ${asJSIdentifier(language.name)}.${classifier.name}.create(newId(), this.handleDelta)`)
40
+ )),
41
+ `}`,
42
+ ``
43
+ ]
44
+
45
+ const languagesWithFactoryMethods = languages
46
+ .filter(
47
+ (language) => language.entities.some(requiresFactoryMethod)
48
+ )
49
+
50
+ return asString([
51
+ header ?? [],
52
+ `import {DeltaHandler} from "@tls/lionweb-class-core";`,
53
+ ``,
54
+ `import {`,
55
+ indent(commaSeparated(
56
+ languagesWithFactoryMethods.map(({name}) => asJSIdentifier(name))
57
+ )),
58
+ `} from "./index.g.js";`,
59
+ ``,
60
+ `import {newId} from "../index.js";`,
61
+ ``,
62
+ ``,
63
+ `export class ${megaFactoryName} {`,
64
+ indent([
65
+ ``,
66
+ `constructor(`,
67
+ indent([
68
+ `public readonly handleDelta?: DeltaHandler`
69
+ ]),
70
+ `) {`,
71
+ `}`,
72
+ ``,
73
+ languagesWithFactoryMethods.map(factoryFor)
74
+ ]),
75
+ `}`,
76
+ ``
77
+ ])
78
+ }
79
+