@lionweb/core 0.7.0-beta.9 → 0.7.1

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 (80) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/deserializer.d.ts +2 -3
  3. package/dist/deserializer.d.ts.map +1 -1
  4. package/dist/deserializer.js +9 -12
  5. package/dist/deserializer.js.map +1 -1
  6. package/dist/extraction.d.ts.map +1 -1
  7. package/dist/functions.d.ts.map +1 -1
  8. package/dist/handler.d.ts +1 -1
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +0 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/m1/reference-utils.d.ts +1 -1
  14. package/dist/m1/reference-utils.d.ts.map +1 -1
  15. package/dist/m3/builtins.d.ts +16 -0
  16. package/dist/m3/builtins.d.ts.map +1 -1
  17. package/dist/m3/builtins.js +24 -1
  18. package/dist/m3/builtins.js.map +1 -1
  19. package/dist/m3/constraints.d.ts.map +1 -1
  20. package/dist/m3/deserializer.d.ts.map +1 -1
  21. package/dist/m3/deserializer.js +2 -2
  22. package/dist/m3/deserializer.js.map +1 -1
  23. package/dist/m3/feature-resolvers.d.ts +23 -0
  24. package/dist/m3/feature-resolvers.d.ts.map +1 -0
  25. package/dist/m3/feature-resolvers.js +48 -0
  26. package/dist/m3/feature-resolvers.js.map +1 -0
  27. package/dist/m3/functions.d.ts.map +1 -1
  28. package/dist/m3/index.d.ts +2 -0
  29. package/dist/m3/index.d.ts.map +1 -1
  30. package/dist/m3/index.js +2 -0
  31. package/dist/m3/index.js.map +1 -1
  32. package/dist/m3/reference-checker.d.ts.map +1 -1
  33. package/dist/m3/serializer.d.ts.map +1 -1
  34. package/dist/{symbol-table.d.ts → m3/symbol-table.d.ts} +14 -14
  35. package/dist/m3/symbol-table.d.ts.map +1 -0
  36. package/dist/m3/symbol-table.js +43 -0
  37. package/dist/m3/symbol-table.js.map +1 -0
  38. package/dist/m3/types.d.ts.map +1 -1
  39. package/dist/references.d.ts +7 -2
  40. package/dist/references.d.ts.map +1 -1
  41. package/dist/references.js +5 -1
  42. package/dist/references.js.map +1 -1
  43. package/dist/serializer.d.ts +1 -1
  44. package/dist/serializer.d.ts.map +1 -1
  45. package/dist/serializer.js +22 -12
  46. package/dist/serializer.js.map +1 -1
  47. package/dist/version.d.ts +1 -1
  48. package/dist/version.js +1 -1
  49. package/dist/writing.js +1 -1
  50. package/package.json +31 -31
  51. package/src/deserializer.ts +228 -0
  52. package/src/dynamic-facade.ts +63 -0
  53. package/src/extraction.ts +31 -0
  54. package/src/functions.ts +28 -0
  55. package/src/handler.ts +57 -0
  56. package/src/index.ts +13 -0
  57. package/src/m1/reference-utils.ts +106 -0
  58. package/src/m3/README.md +16 -0
  59. package/src/m3/builtins.ts +196 -0
  60. package/src/m3/constraints.ts +109 -0
  61. package/src/m3/deserializer.ts +38 -0
  62. package/src/m3/facade.ts +130 -0
  63. package/src/m3/factory.ts +98 -0
  64. package/src/m3/feature-resolvers.ts +72 -0
  65. package/src/m3/functions.ts +379 -0
  66. package/src/m3/index.ts +12 -0
  67. package/src/m3/lioncore.ts +139 -0
  68. package/src/m3/reference-checker.ts +38 -0
  69. package/src/m3/serializer.ts +13 -0
  70. package/src/m3/symbol-table.ts +125 -0
  71. package/src/m3/types.ts +325 -0
  72. package/src/reading.ts +55 -0
  73. package/src/references.ts +39 -0
  74. package/src/serializer.ts +244 -0
  75. package/src/types.ts +11 -0
  76. package/src/version.ts +5 -0
  77. package/src/writing.ts +79 -0
  78. package/dist/symbol-table.d.ts.map +0 -1
  79. package/dist/symbol-table.js +0 -59
  80. package/dist/symbol-table.js.map +0 -1
@@ -0,0 +1,39 @@
1
+ import { LionWebId } from "@lionweb/json"
2
+ import { Node } from "./types.js"
3
+
4
+
5
+ /**
6
+ * The `unresolved` symbol indicates a reference value which hasn't been resolved yet.
7
+ * It differs from an unset (`undefined`) value.
8
+ */
9
+ export const unresolved = null
10
+
11
+ /**
12
+ * A type definition for a reference value that can be unresolved.
13
+ */
14
+ export type SingleRef<T> = typeof unresolved | T
15
+
16
+ /**
17
+ * @return whether a given (at most) single-valued reference actually refers to something.
18
+ */
19
+ export const isRef = <T>(ref?: SingleRef<T>): ref is T =>
20
+ ref !== undefined && ref !== unresolved
21
+
22
+ /**
23
+ * A type alias for a multi-valued reference, to make it look consistent with {@link SingleRef}.
24
+ */
25
+ export type MultiRef<T> = T[]
26
+
27
+
28
+ /**
29
+ * A type that expresses a value is either an {@link LionWebId} or a value to indicate that resolution to a node previously failed.
30
+ */
31
+ export type IdOrUnresolved = LionWebId | typeof unresolved;
32
+
33
+
34
+ /**
35
+ * @return the serialization of the given {@link SingleRef single reference target}, as a {@link LionWebId LionWeb ID}.
36
+ */
37
+ export const serializedRef = <NT extends Node>(ref: SingleRef<NT>): LionWebId | typeof unresolved =>
38
+ ref === unresolved ? unresolved : ref.id
39
+
@@ -0,0 +1,244 @@
1
+ import {
2
+ currentSerializationFormatVersion,
3
+ LionWebId,
4
+ LionWebJsonChunk,
5
+ LionWebJsonMetaPointer,
6
+ LionWebJsonNode
7
+ } from "@lionweb/json"
8
+ import { asArray, keepDefineds, lazyMapGet, Nested3Map, uniquesAmong } from "@lionweb/ts-utils"
9
+ import { asIds } from "./functions.js"
10
+ import { Reader } from "./reading.js"
11
+ import { Node } from "./types.js"
12
+ import { builtinPropertyValueSerializer } from "./m3/builtins.js"
13
+ import { inheritsDirectlyFrom } from "./m3/functions.js"
14
+ import {
15
+ Classifier,
16
+ Containment,
17
+ Enumeration,
18
+ Feature,
19
+ Language,
20
+ PrimitiveType,
21
+ Property,
22
+ Reference,
23
+ simpleNameDeducer
24
+ } from "./m3/types.js"
25
+
26
+
27
+ /**
28
+ * Interface for objects that expose a method to serialize a property's value.
29
+ */
30
+ export interface PropertyValueSerializer {
31
+ serializeValue(value: unknown, property: Property): string | null
32
+ }
33
+
34
+ /**
35
+ * Misspelled alias of {@link PropertyValueSerializer}, kept for backward compatibility, and to be deprecated and removed later.
36
+ */
37
+ export interface PrimitiveTypeSerializer extends PropertyValueSerializer {}
38
+
39
+
40
+ const isPropertyValueSerializer = (value: unknown): value is PropertyValueSerializer =>
41
+ typeof value === "object" && value !== null && "serializeValue" in value && typeof value.serializeValue === "function"
42
+ // (we can't check the rest of the signature – i.e. arguments and their types – at runtime, because that's JavaScript)
43
+
44
+
45
+ /**
46
+ * Type to provide (non-required) options to the serializer.
47
+ */
48
+ export type SerializationOptions = Partial<{
49
+
50
+ /**
51
+ * Determines whether empty feature values are explicitly serialized or skipped during serialization.
52
+ * (The specification states that empty feature values SHOULD be serialized, but not that they MUST be.)
53
+ * Default = true, meaning that empty feature values are *not* skipped.
54
+ */
55
+ serializeEmptyFeatures: boolean
56
+
57
+ /**
58
+ * A {@link PropertyValueSerializer} implementation.
59
+ * Default = DefaultPropertyValueSerializer.
60
+ */
61
+ propertyValueSerializer: PropertyValueSerializer
62
+
63
+ /**
64
+ * Misspelled alias of {@link #propertyValueSerializer}, kept for backward compatibility, and to be deprecated and removed later.
65
+ */
66
+ primitiveTypeSerializer: PropertyValueSerializer
67
+
68
+ }>
69
+
70
+ /**
71
+ * @return the {@link LionWebJsonMetaPointer} for the given {@link Feature}.
72
+ */
73
+ export const metaPointerFor = (feature: Feature): LionWebJsonMetaPointer => {
74
+ const { language } = feature.classifier
75
+ return {
76
+ language: language.key,
77
+ version: language.version,
78
+ key: feature.key
79
+ }
80
+ }
81
+
82
+
83
+ /**
84
+ * @return a function that serializes the {@link Node nodes} passed to it.
85
+ */
86
+ export const nodeSerializer = <NT extends Node>(reader: Reader<NT>, serializationOptions?: SerializationOptions) => {
87
+ const propertyValueSerializer =
88
+ serializationOptions?.propertyValueSerializer ?? serializationOptions?.primitiveTypeSerializer ?? builtinPropertyValueSerializer
89
+ const serializeEmptyFeatures = serializationOptions?.serializeEmptyFeatures ?? true
90
+
91
+ const languageKey2version2classifierKey2allFeatures: Nested3Map<Feature[]> = {}
92
+ const memoisedAllFeaturesOf = (classifier: Classifier): Feature[] =>
93
+ lazyMapGet(
94
+ lazyMapGet(
95
+ lazyMapGet(
96
+ languageKey2version2classifierKey2allFeatures,
97
+ classifier.language.key,
98
+ () => ({})
99
+ ),
100
+ classifier.language.version,
101
+ () => ({})
102
+ ),
103
+ classifier.key,
104
+ () => uniquesAmong( // make unique in case a feature was inherited from multiple super-classifiers
105
+ [ ...classifier.features, ...(inheritsDirectlyFrom(classifier).flatMap(memoisedAllFeaturesOf)) ]
106
+ /*
107
+ * [NOTE]
108
+ * The allFeaturesOf function uses flatMapNonCyclingFollowing which avoids that features of a super-classifier are added multiple times.
109
+ * Unfortunately, to make use of the memoising, we can't use flatMapNonCyclingFollowing in the same way here.
110
+ * So, we have to remove duplicates ourselves.
111
+ */
112
+ )
113
+ )
114
+
115
+ return (nodes: NT[]): LionWebJsonChunk => {
116
+ const serializedNodes: LionWebJsonNode[] = [] // keep nodes as much as possible "in order"
117
+ const ids: { [id: LionWebId]: boolean } = {} // maintain a map to keep track of IDs of nodes that have been serialized
118
+ const languagesUsed: Language[] = []
119
+ const usedLanguageKey2Version2Boolean: { [key: string]: { [version: string]: boolean } } = {}
120
+ const registerLanguageUsed = (language: Language) => {
121
+ const version2Boolean = lazyMapGet<{ [version: string]: boolean }>(usedLanguageKey2Version2Boolean, language.key, () => ({}))
122
+ if (!version2Boolean[language.version]) {
123
+ version2Boolean[language.version] = true
124
+ languagesUsed.push(language)
125
+ }
126
+ }
127
+
128
+ const visit = (node: NT, parent?: NT) => {
129
+ if (node.id in ids) {
130
+ return
131
+ }
132
+
133
+ const classifier = reader.classifierOf(node)
134
+ const language = classifier.language
135
+ registerLanguageUsed(language)
136
+ const serializedNode: LionWebJsonNode = {
137
+ id: node.id,
138
+ classifier: classifier.metaPointer(),
139
+ properties: [],
140
+ containments: [],
141
+ references: [],
142
+ annotations: [],
143
+ parent: null
144
+ }
145
+ serializedNodes.push(serializedNode)
146
+ ids[node.id] = true
147
+ memoisedAllFeaturesOf(classifier).forEach((feature) => {
148
+ const value = reader.getFeatureValue(node, feature)
149
+ const featureLanguage = feature.classifier.language
150
+ registerLanguageUsed(featureLanguage)
151
+ const featureMetaPointer = metaPointerFor(feature)
152
+ if (feature instanceof Property) {
153
+ if (value === undefined && !serializeEmptyFeatures) {
154
+ // for immediate backward compatibility: skip empty property values regardless of options?.skipEmptyValues
155
+ return
156
+ }
157
+ const encodedValue = (() => {
158
+ // (could also just inspect type of value:)
159
+ if (feature.type instanceof PrimitiveType) {
160
+ return propertyValueSerializer.serializeValue(value, feature)
161
+ }
162
+ if (feature.type instanceof Enumeration) {
163
+ return reader.enumerationLiteralFrom(value, feature.type)?.key
164
+ }
165
+ return undefined
166
+ })()
167
+ serializedNode.properties.push({
168
+ property: featureMetaPointer,
169
+ value: (encodedValue as string) ?? null // (undefined -> null)
170
+ })
171
+ return
172
+ }
173
+ if (feature instanceof Containment) {
174
+ const children = asArray(value) as (NT | null)[]
175
+ if (children.length === 0 && !serializeEmptyFeatures) {
176
+ return
177
+ }
178
+ serializedNode.containments.push({
179
+ containment: featureMetaPointer,
180
+ children: keepDefineds(asIds(children))
181
+ .map(childId => childId as string)
182
+ })
183
+ children.forEach(childOrNull => {
184
+ if (childOrNull !== null) {
185
+ visit(childOrNull, node)
186
+ }
187
+ })
188
+ return
189
+ }
190
+ if (feature instanceof Reference) {
191
+ // Note: value can be null === typeof unresolved, e.g. on an unset (or previously unresolved) single-valued reference
192
+ const targets = asArray(value) as (NT | null)[]
193
+ if (targets.length === 0 && !serializeEmptyFeatures) {
194
+ return
195
+ }
196
+ serializedNode.references.push({
197
+ reference: featureMetaPointer,
198
+ targets: keepDefineds(targets) // (skip "non-connected" targets)
199
+ .map(t => t as NT)
200
+ .map(t => ({
201
+ resolveInfo:
202
+ (reader.resolveInfoFor ? reader.resolveInfoFor(t) : simpleNameDeducer(t)) ?? null,
203
+ reference: t.id
204
+ }))
205
+ })
206
+ return
207
+ }
208
+ })
209
+
210
+ const annotations = asArray(node.annotations) as NT[] // assumes that annotations also all are of type NT (which is not unreasonable)
211
+ serializedNode.annotations = annotations.map(annotation => annotation.id)
212
+ annotations.forEach(annotation => visit(annotation, node))
213
+
214
+ serializedNode.parent = parent?.id ?? null // (undefined -> null)
215
+ }
216
+
217
+ nodes.forEach(node => visit(node, undefined))
218
+
219
+ return {
220
+ serializationFormatVersion: currentSerializationFormatVersion,
221
+ languages: languagesUsed.map(({ key, version }) => ({ key, version })),
222
+ nodes: serializedNodes
223
+ }
224
+ }
225
+ }
226
+
227
+ /**
228
+ * @return a {@link LionWebJsonChunk} of the given model (i.e., an array of {@link Node nodes} - the first argument) to the LionWeb serialization JSON format.
229
+ * *Note:* this function will be deprecated and removed later — use {@link nodeSerializer} instead.
230
+ */
231
+ export const serializeNodes = <NT extends Node>(
232
+ nodes: NT[],
233
+ reader: Reader<NT>,
234
+ propertyValueSerializerOrOptions?: PropertyValueSerializer | SerializationOptions
235
+ ): LionWebJsonChunk =>
236
+ nodeSerializer<NT>(
237
+ reader,
238
+ isPropertyValueSerializer(propertyValueSerializerOrOptions)
239
+ ? {
240
+ propertyValueSerializer: propertyValueSerializerOrOptions
241
+ }
242
+ : propertyValueSerializerOrOptions
243
+ )(nodes)
244
+
package/src/types.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { LionWebId } from "@lionweb/json"
2
+
3
+ /**
4
+ * Type definition for a LionWeb-compliant AST node.
5
+ */
6
+ export type Node = {
7
+ id: LionWebId
8
+ parent?: Node
9
+ annotations: Node[]
10
+ }
11
+
package/src/version.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The *current* release(d) version.
3
+ */
4
+ export const currentReleaseVersion = "2023.1"
5
+
package/src/writing.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { LionWebId, LionWebKey } from "@lionweb/json"
2
+
3
+ import { Classifier, EnumerationLiteral, Feature, Link } from "./m3/types.js"
4
+ import { Node } from "./types.js"
5
+
6
+
7
+ /**
8
+ * An interface that's used to parametrize generic deserialization of serialization chunks to
9
+ * (in-memory) nodes of the given type (parameter).
10
+ * Implementations of these interfaces {w|c}ould be:
11
+ * - specific to LionCore (so to match m3/types.ts)
12
+ * - generic to deserialize into {@link DynamicNode dynamic nodes}
13
+ */
14
+ export interface Writer<NT extends Node, PNT extends Node = NT> {
15
+
16
+ /**
17
+ * @return An instance of the given concept, also given its parent (or {@link undefined} for root nodes),
18
+ * its ID and the values of the node's properties ("settings").
19
+ * (The latter may be required as arguments for the constructor of a class, whose instances represent nodes.)
20
+ */
21
+ nodeFor: (parent: PNT | undefined, classifier: Classifier, id: LionWebId, propertySettings: { [propertyKey: LionWebKey]: unknown }) => NT
22
+ // TODO this prohibits multiple properties with the same key but different language => use a variant of LionWebJsonProperty[] with the value already deserialized
23
+
24
+ /**
25
+ * Sets the *single* given value of the indicated {@link Feature} on the given node.
26
+ * This means adding it in case the feature is multi-valued, meaning it is a {@link Link} with {@code multiple = true}.
27
+ */
28
+ setFeatureValue: (node: NT, feature: Feature, value: unknown) => void
29
+ // TODO split to setPropertyValue, &c.?
30
+
31
+ /**
32
+ * @return The runtime encoding of the given {@link EnumerationLiteral}.
33
+ */
34
+ encodingOf: (literal: EnumerationLiteral) => unknown
35
+
36
+ }
37
+
38
+ /**
39
+ * Alias for {@link Writer}, kept for backward compatibility, and to be deprecated and removed later.
40
+ */
41
+ export interface InstantiationFacade<NT extends Node, PNT extends Node = NT> extends Writer<NT, PNT> {}
42
+
43
+
44
+ /**
45
+ * Type def. for functions that update features’ values on a settings object.
46
+ */
47
+ export type SettingsUpdater = (settings: Record<string, unknown>, feature: Feature, value: unknown) => void
48
+
49
+ /**
50
+ * @return a {@link SettingsUpdater} that uses the given “meta key” – which is a property/key on the {@link Feature} type –
51
+ * to look up what key to look a feature’s value up on a settings object.
52
+ * *Note:* for internal use only — use with some care!
53
+ */
54
+ const settingsUpdater = (metaKey: keyof Feature): SettingsUpdater =>
55
+ (settings: Record<string, unknown>, feature: Feature, value: unknown): void => {
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ const key = (feature as any)[metaKey] as string
58
+ if (feature instanceof Link && feature.multiple) {
59
+ if (!Array.isArray(settings[key])) {
60
+ settings[key] = []
61
+ }
62
+ (settings[key] as unknown[]).push(value)
63
+ } else {
64
+ settings[key] = value
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Updates the value of the given {@link Feature feature} on the given "settings" object
70
+ * (either a {@link Node node} or a sub object of it), using the feature's *name*.
71
+ */
72
+ export const updateSettingsNameBased: SettingsUpdater = settingsUpdater("name")
73
+
74
+ /**
75
+ * Updates the value of the given {@link Feature feature} on the given "settings" object
76
+ * (either a {@link Node node} or a sub object of it), using the feature's *key*.
77
+ */
78
+ export const updateSettingsKeyBased = settingsUpdater("key")
79
+
@@ -1 +0,0 @@
1
- {"version":3,"file":"symbol-table.d.ts","sourceRoot":"","sources":["../src/symbol-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAGlE,OAAO,EAAc,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAG7E;;;;GAIG;AACH,UAAU,WAAW;IAEjB;;OAEG;IACH,gBAAgB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IAExE;;;OAGG;IACH,cAAc,CAAC,iBAAiB,EAAE,sBAAsB,GAAG,cAAc,GAAG,SAAS,CAAA;IAErF;;;;;;OAMG;IACH,eAAe,CAAC,iBAAiB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,sBAAsB,GAAG,OAAO,GAAG,SAAS,CAAA;CAE9H;AAGD;;GAEG;AACH,cAAM,gBAAiB,YAAW,WAAW;IAEzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;gBAE1B,SAAS,EAAE,QAAQ,EAAE;IAIjC,gBAAgB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAOxE,cAAc,CAAC,iBAAiB,EAAE,sBAAsB,GAAG,cAAc,GAAG,SAAS;IAMrF,eAAe,CAAC,qBAAqB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,sBAAsB,GAAG,OAAO,GAAG,SAAS;CASlI;AASD,cAAM,oBAAqB,YAAW,WAAW;IAE7C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;gBAE1B,SAAS,EAAE,QAAQ,EAAE;IAIjC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAqE;IAElH,gBAAgB,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAYhF,OAAO,CAAC,QAAQ,CAAC,wCAAwC,CAAkH;IAE3K,OAAO,CAAC,kBAAkB;IAiB1B,cAAc,CAAC,iBAAiB,EAAE,sBAAsB,GAAG,cAAc,GAAG,SAAS;IAIrF,eAAe,CAAC,qBAAqB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,sBAAsB,GAAG,OAAO,GAAG,SAAS;CAYlI;AAGD,YAAY,EACR,WAAW,EACd,CAAA;AAED,OAAO,EACH,oBAAoB,EACpB,gBAAgB,EACnB,CAAA"}
@@ -1,59 +0,0 @@
1
- import { lazyMapGet } from "@lionweb/ts-utils";
2
- import { allFeaturesOf } from "./m3/functions.js";
3
- import { Classifier } from "./m3/types.js";
4
- /**
5
- * Naive, non-performant implementation of {@link SymbolTable}.
6
- */
7
- class NaiveSymbolTable {
8
- constructor(languages) {
9
- this.languages = languages;
10
- }
11
- languageMatching(key, version) {
12
- return this.languages.find((language) => language.key === key
13
- && language.version === version);
14
- }
15
- entityMatching(entityMetaPointer) {
16
- return this.languageMatching(entityMetaPointer.language, entityMetaPointer.version)
17
- ?.entities
18
- .find((entity) => entity.key === entityMetaPointer.key);
19
- }
20
- featureMatching(classifierMetaPointer, featureMetaPointer) {
21
- const classifier = this.entityMatching(classifierMetaPointer);
22
- if (classifier === undefined || !(classifier instanceof Classifier)) {
23
- return undefined;
24
- }
25
- const allFeatures = allFeaturesOf(classifier);
26
- return allFeatures.find((feature) => feature.key === featureMetaPointer.key);
27
- }
28
- }
29
- class MemoisingSymbolTable {
30
- constructor(languages) {
31
- this.languageKey2version2language = {};
32
- this.languageKey2version2entityKey2entityInfo = {};
33
- this.languages = languages;
34
- }
35
- languageMatching(languageKey, version) {
36
- return lazyMapGet(lazyMapGet(this.languageKey2version2language, languageKey, () => ({})), version, () => this.languages.find((language) => language.key === languageKey
37
- && language.version === version));
38
- }
39
- entityInfoMatching(entityMetaPointer) {
40
- return lazyMapGet(lazyMapGet(lazyMapGet(this.languageKey2version2entityKey2entityInfo, entityMetaPointer.language, () => ({})), entityMetaPointer.version, () => ({})), entityMetaPointer.key, () => {
41
- const entity = this.languageMatching(entityMetaPointer.language, entityMetaPointer.version)
42
- ?.entities
43
- .find((entity) => entity.key === entityMetaPointer.key);
44
- return entity && { entity, allFeatures: entity instanceof Classifier ? allFeaturesOf(entity) : [], featureKey2feature: {} };
45
- });
46
- }
47
- entityMatching(entityMetaPointer) {
48
- return this.entityInfoMatching(entityMetaPointer)?.entity;
49
- }
50
- featureMatching(classifierMetaPointer, featureMetaPointer) {
51
- const entityInfo = this.entityInfoMatching(classifierMetaPointer);
52
- if (entityInfo === undefined || !(entityInfo.entity instanceof Classifier)) {
53
- return undefined;
54
- }
55
- return lazyMapGet(entityInfo.featureKey2feature, featureMetaPointer.key, () => entityInfo.allFeatures.find((feature) => feature.key === featureMetaPointer.key));
56
- }
57
- }
58
- export { MemoisingSymbolTable, NaiveSymbolTable };
59
- //# sourceMappingURL=symbol-table.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"symbol-table.js","sourceRoot":"","sources":["../src/symbol-table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB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