@lionweb/validation 0.6.1-beta.0 → 0.6.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.
- package/dist/diff/LionWebJsonDiff.d.ts.map +1 -1
- package/dist/diff/LionWebJsonDiff.js +18 -23
- package/dist/diff/LionWebJsonDiff.js.map +1 -1
- package/dist/diff/changes/ContainmentChange.d.ts +2 -2
- package/dist/diff/changes/ContainmentChange.d.ts.map +1 -1
- package/dist/diff/changes/ContainmentChange.js.map +1 -1
- package/dist/diff/changes/ReferenceChange.d.ts +3 -3
- package/dist/diff/changes/ReferenceChange.d.ts.map +1 -1
- package/dist/diff/changes/ReferenceChange.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/issues/LanguageIssues.d.ts +37 -13
- package/dist/issues/LanguageIssues.d.ts.map +1 -1
- package/dist/issues/LanguageIssues.js +49 -13
- package/dist/issues/LanguageIssues.js.map +1 -1
- package/dist/issues/ReferenceIssues.d.ts +6 -6
- package/dist/issues/ReferenceIssues.d.ts.map +1 -1
- package/dist/issues/ReferenceIssues.js +6 -6
- package/dist/issues/ReferenceIssues.js.map +1 -1
- package/dist/issues/SyntaxIssues.d.ts +9 -9
- package/dist/issues/SyntaxIssues.d.ts.map +1 -1
- package/dist/issues/SyntaxIssues.js +9 -9
- package/dist/issues/SyntaxIssues.js.map +1 -1
- package/dist/issues/ValidationIssue.d.ts +7 -1
- package/dist/issues/ValidationIssue.d.ts.map +1 -1
- package/dist/issues/ValidationIssue.js +9 -1
- package/dist/issues/ValidationIssue.js.map +1 -1
- package/dist/json/LionWebJson.d.ts +1 -14
- package/dist/json/LionWebJson.d.ts.map +1 -1
- package/dist/json/LionWebJson.js +4 -14
- package/dist/json/LionWebJson.js.map +1 -1
- package/dist/json/LionWebJsonChunkWrapper.d.ts +20 -8
- package/dist/json/LionWebJsonChunkWrapper.d.ts.map +1 -1
- package/dist/json/LionWebJsonChunkWrapper.js +50 -22
- package/dist/json/LionWebJsonChunkWrapper.js.map +1 -1
- package/dist/json/M3definitions.d.ts +176 -0
- package/dist/json/M3definitions.d.ts.map +1 -0
- package/dist/json/M3definitions.js +174 -0
- package/dist/json/M3definitions.js.map +1 -0
- package/dist/json/NodeUtils.d.ts +3 -9
- package/dist/json/NodeUtils.d.ts.map +1 -1
- package/dist/json/NodeUtils.js +18 -31
- package/dist/json/NodeUtils.js.map +1 -1
- package/dist/json/index.d.ts +1 -2
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -2
- package/dist/json/index.js.map +1 -1
- package/dist/languages/CompositeLionWebLanguageWrapper.d.ts +24 -0
- package/dist/languages/CompositeLionWebLanguageWrapper.d.ts.map +1 -0
- package/dist/languages/CompositeLionWebLanguageWrapper.js +56 -0
- package/dist/languages/CompositeLionWebLanguageWrapper.js.map +1 -0
- package/dist/languages/LanguageRegistry.d.ts +19 -0
- package/dist/languages/LanguageRegistry.d.ts.map +1 -0
- package/dist/languages/LanguageRegistry.js +37 -0
- package/dist/languages/LanguageRegistry.js.map +1 -0
- package/dist/languages/LanguageUtils.d.ts +35 -0
- package/dist/languages/LanguageUtils.d.ts.map +1 -0
- package/dist/languages/LanguageUtils.js +52 -0
- package/dist/languages/LanguageUtils.js.map +1 -0
- package/dist/languages/LionCore-M3.json +2356 -0
- package/{src/json/std-builtins-copy.json → dist/languages/LionCore-builtins.json} +57 -52
- package/dist/languages/LionWebLanguageWrapper.d.ts +31 -0
- package/dist/languages/LionWebLanguageWrapper.d.ts.map +1 -0
- package/dist/languages/LionWebLanguageWrapper.js +69 -0
- package/dist/languages/LionWebLanguageWrapper.js.map +1 -0
- package/dist/languages/MetaPointerMap.d.ts +11 -0
- package/dist/languages/MetaPointerMap.d.ts.map +1 -0
- package/dist/languages/MetaPointerMap.js +39 -0
- package/dist/languages/MetaPointerMap.js.map +1 -0
- package/dist/languages/index.d.ts +3 -0
- package/dist/languages/index.d.ts.map +1 -0
- package/dist/languages/index.js +3 -0
- package/dist/languages/index.js.map +1 -0
- package/dist/runners/FileUtils.d.ts +4 -4
- package/dist/runners/FileUtils.d.ts.map +1 -1
- package/dist/runners/FileUtils.js +8 -32
- package/dist/runners/FileUtils.js.map +1 -1
- package/dist/runners/RunCheckFolder.js +3 -1
- package/dist/runners/RunCheckFolder.js.map +1 -1
- package/dist/runners/RunCheckFolderWithLanguage.js +7 -3
- package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -1
- package/dist/runners/RunCheckOneFile.js +3 -1
- package/dist/runners/RunCheckOneFile.js.map +1 -1
- package/dist/runners/RunCheckOneFileWithLanguage.js +12 -3
- package/dist/runners/RunCheckOneFileWithLanguage.js.map +1 -1
- package/dist/runners/Utils.d.ts.map +1 -1
- package/dist/runners/Utils.js +0 -1
- package/dist/runners/Utils.js.map +1 -1
- package/dist/util/graphs.d.ts +18 -0
- package/dist/util/graphs.d.ts.map +1 -0
- package/dist/util/graphs.js +27 -0
- package/dist/util/graphs.js.map +1 -0
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts +5 -4
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.js +96 -34
- package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebLanguageValidator.d.ts +15 -3
- package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageValidator.js +54 -21
- package/dist/validators/LionWebLanguageValidator.js.map +1 -1
- package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebReferenceValidator.js +0 -5
- package/dist/validators/LionWebReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.d.ts +1 -1
- package/dist/validators/LionWebSyntaxValidator.js +1 -1
- package/dist/validators/LionWebValidator.d.ts +3 -3
- package/dist/validators/LionWebValidator.d.ts.map +1 -1
- package/dist/validators/LionWebValidator.js +5 -8
- package/dist/validators/LionWebValidator.js.map +1 -1
- package/package.json +5 -5
- package/src/diff/LionWebJsonDiff.ts +18 -23
- package/src/diff/changes/ContainmentChange.ts +1 -1
- package/src/diff/changes/ReferenceChange.ts +2 -2
- package/src/index.ts +2 -0
- package/src/issues/LanguageIssues.ts +49 -14
- package/src/issues/ReferenceIssues.ts +6 -6
- package/src/issues/SyntaxIssues.ts +9 -9
- package/src/issues/ValidationIssue.ts +12 -2
- package/src/json/LionWebJson.ts +5 -14
- package/src/json/LionWebJsonChunkWrapper.ts +59 -30
- package/src/json/M3definitions.ts +177 -0
- package/src/json/NodeUtils.ts +21 -39
- package/src/json/index.ts +1 -2
- package/src/languages/CompositeLionWebLanguageWrapper.ts +57 -0
- package/src/languages/LanguageRegistry.ts +44 -0
- package/src/languages/LanguageUtils.ts +61 -0
- package/src/languages/LionCore-M3.json +2356 -0
- package/src/languages/LionCore-builtins.json +372 -0
- package/src/languages/LionWebLanguageWrapper.ts +95 -0
- package/src/languages/MetaPointerMap.ts +40 -0
- package/src/languages/index.ts +2 -0
- package/src/runners/FileUtils.ts +9 -36
- package/src/runners/RunCheckFolder.ts +3 -1
- package/src/runners/RunCheckFolderWithLanguage.ts +7 -7
- package/src/runners/RunCheckOneFile.ts +3 -1
- package/src/runners/RunCheckOneFileWithLanguage.ts +12 -7
- package/src/runners/Utils.ts +0 -1
- package/src/util/graphs.ts +36 -0
- package/src/validators/LionWebLanguageReferenceValidator.ts +110 -48
- package/src/validators/LionWebLanguageValidator.ts +62 -21
- package/src/validators/LionWebReferenceValidator.ts +0 -5
- package/src/validators/LionWebSyntaxValidator.ts +2 -2
- package/src/validators/LionWebValidator.ts +5 -9
- package/dist/json/LanguageUtils.d.ts +0 -9
- package/dist/json/LanguageUtils.d.ts.map +0 -1
- package/dist/json/LanguageUtils.js +0 -30
- package/dist/json/LanguageUtils.js.map +0 -1
- package/dist/json/LionWebLanguageDefinition.d.ts +0 -48
- package/dist/json/LionWebLanguageDefinition.d.ts.map +0 -1
- package/dist/json/LionWebLanguageDefinition.js +0 -126
- package/dist/json/LionWebLanguageDefinition.js.map +0 -1
- package/src/json/LanguageUtils.ts +0 -52
- package/src/json/LionWebLanguageDefinition.ts +0 -144
|
@@ -11,22 +11,22 @@ export abstract class Syntax_PropertyIssue extends ValidationIssue {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export class Syntax_PropertyMissingIssue extends Syntax_PropertyIssue {
|
|
14
|
-
readonly
|
|
14
|
+
readonly issueType = "PropertyMissing"
|
|
15
15
|
protected msg = () => `Property "${this.property}" is missing`
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export class Syntax_PropertyUnknownIssue extends Syntax_PropertyIssue {
|
|
19
|
-
readonly
|
|
19
|
+
readonly issueType = "PropertyUnknown"
|
|
20
20
|
protected msg = () => `Property "${this.property}" is not defined as a LionWeb property`
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export class Syntax_PropertyNullIssue extends Syntax_PropertyIssue {
|
|
24
|
-
readonly
|
|
24
|
+
readonly issueType = "PropertyNull"
|
|
25
25
|
protected msg = () => `Property "${this.property}" is null, but it should have a value`
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export class Syntax_PropertyTypeIssue extends Syntax_PropertyIssue {
|
|
29
|
-
readonly
|
|
29
|
+
readonly issueType = "PropertyTypeIncorrect"
|
|
30
30
|
|
|
31
31
|
constructor(
|
|
32
32
|
context: JsonContext,
|
|
@@ -41,7 +41,7 @@ export class Syntax_PropertyTypeIssue extends Syntax_PropertyIssue {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export class Syntax_ArrayContainsNull_Issue extends Syntax_PropertyIssue {
|
|
44
|
-
readonly
|
|
44
|
+
readonly issueType = "ArrayContainsNull"
|
|
45
45
|
|
|
46
46
|
constructor(
|
|
47
47
|
context: JsonContext,
|
|
@@ -64,21 +64,21 @@ export abstract class Syntax_IncorrectFormat_Issue extends ValidationIssue {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export class Syntax_SerializationFormatVersion_Issue extends Syntax_IncorrectFormat_Issue {
|
|
67
|
-
readonly
|
|
67
|
+
readonly issueType = "SerializationFormatVersion"
|
|
68
68
|
protected msg = () => `SerializationFormatVersion "${this.value}" is not a number`
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
export class Syntax_VersionFormat_Issue extends Syntax_IncorrectFormat_Issue {
|
|
72
|
-
readonly
|
|
72
|
+
readonly issueType = "VersionFormat"
|
|
73
73
|
protected msg = () => `Version "${this.value}" is an empty string.`
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
export class Syntax_KeyFormat_Issue extends Syntax_IncorrectFormat_Issue {
|
|
77
|
-
readonly
|
|
77
|
+
readonly issueType = "KeyFormat"
|
|
78
78
|
protected msg = () => `Key "${this.value}" has incorrect format.`
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export class Syntax_IdFormat_Issue extends Syntax_IncorrectFormat_Issue {
|
|
82
|
-
readonly
|
|
82
|
+
readonly issueType = "IdFormat"
|
|
83
83
|
protected msg = () => `Id "${this.value}" has incorrect format.`
|
|
84
84
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JsonContext } from "../json/JsonContext.js"
|
|
2
2
|
|
|
3
3
|
export abstract class ValidationIssue {
|
|
4
|
-
abstract readonly
|
|
4
|
+
abstract readonly issueType: string
|
|
5
5
|
context: JsonContext
|
|
6
6
|
|
|
7
7
|
constructor(context: JsonContext) {
|
|
@@ -11,6 +11,16 @@ export abstract class ValidationIssue {
|
|
|
11
11
|
protected abstract msg(): string
|
|
12
12
|
|
|
13
13
|
public errorMsg(): string {
|
|
14
|
-
return `${this.
|
|
14
|
+
return `${this.issueType}: ${this.msg()} at ${this.context.toString()} `
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
export class GenericIssue extends ValidationIssue {
|
|
19
|
+
readonly issueType = "GenericIssue"
|
|
20
|
+
|
|
21
|
+
constructor(context: JsonContext, public text: string) {
|
|
22
|
+
super(context)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected msg = () => this.text
|
|
26
|
+
}
|
package/src/json/LionWebJson.ts
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
|
+
import { LION_CORE_M3_KEY, LION_CORE_M3_VERSION } from "./M3definitions.js"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The types defining the structure of the LionWeb JSON format.
|
|
3
5
|
* @see https://lionweb-io.github.io/specification/serialization/serialization.html
|
|
4
6
|
* We use types instead of classes, because the purpose is to define the Lionweb JSON to be sent over the line.
|
|
5
7
|
*/
|
|
6
|
-
export const LION_CORE_BUILTINS_KEY = "LionCore-builtins"
|
|
7
|
-
export const LION_CORE_BUILTINS_INAMED_NAME = "LionCore-builtins-INamed-name"
|
|
8
|
-
export const LION_CORE_M3_KEY = "LionCore-M3"
|
|
9
|
-
export const LION_CORE_M3_NAME = "LionCore_M3"
|
|
10
|
-
export const LION_CORE_M3_VERSION = "2023.1"
|
|
11
8
|
|
|
12
|
-
export const LIONWEB_BOOLEAN_TYPE = "LionCore-builtins-Boolean"
|
|
13
|
-
export const LIONWEB_JSON_TYPE = "LionCore-builtins-JSON"
|
|
14
|
-
export const LIONWEB_INTEGER_TYPE = "LionCore-builtins-Integer"
|
|
15
|
-
export const LIONWEB_STRING_TYPE = "LionCore-builtins-String"
|
|
16
9
|
|
|
17
|
-
export
|
|
18
|
-
language
|
|
19
|
-
version: LION_CORE_M3_VERSION,
|
|
20
|
-
key: LION_CORE_BUILTINS_INAMED_NAME
|
|
10
|
+
export function isLionWebM3Language(language: LwJsonUsedLanguage): boolean {
|
|
11
|
+
return language.key === LION_CORE_M3_KEY && language.version === LION_CORE_M3_VERSION
|
|
21
12
|
}
|
|
22
13
|
export type LionWebId = string
|
|
23
14
|
|
|
24
15
|
export type LionWebJsonMetaPointer = {
|
|
25
16
|
language: string
|
|
26
17
|
version: string
|
|
27
|
-
key: string
|
|
18
|
+
key: string // key of concept, property, containment, referenve or property
|
|
28
19
|
}
|
|
29
20
|
|
|
30
21
|
export function isEqualMetaPointer(p1: LionWebJsonMetaPointer, p2: LionWebJsonMetaPointer): boolean {
|
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
isEqualMetaPointer,
|
|
3
3
|
LionWebId,
|
|
4
4
|
LionWebJsonChunk,
|
|
5
|
+
LionWebJsonContainment,
|
|
6
|
+
LionWebJsonMetaPointer,
|
|
5
7
|
LionWebJsonNode,
|
|
6
|
-
|
|
8
|
+
LionWebJsonReference
|
|
7
9
|
} from "./LionWebJson.js"
|
|
8
|
-
import {
|
|
10
|
+
import { MetaPointers } from "./M3definitions.js"
|
|
9
11
|
import { NodeUtils } from "./NodeUtils.js"
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* Wraps around a LionWebJsonChunk, providing access to information inside, using caches to improve performance.
|
|
14
|
+
* Wraps around a LionWebJsonChunk, providing access to information inside, might be using caches to improve performance.
|
|
13
15
|
* NB Make sure that the contents of the chunk are not changed after creating the wrapper!
|
|
16
|
+
* NB BE aware that with `pushChunk(...)` the original chunk will be changed.
|
|
14
17
|
*/
|
|
15
18
|
export class LionWebJsonChunkWrapper {
|
|
16
19
|
jsonChunk: LionWebJsonChunk
|
|
17
|
-
language: LionWebLanguageDefinition | null = null
|
|
18
20
|
/**
|
|
19
21
|
* Map to get quick access to nodes by id.
|
|
20
22
|
* @protected
|
|
21
23
|
*/
|
|
22
24
|
protected nodesIdMap: Map<LionWebId, LionWebJsonNode> = new Map<LionWebId, LionWebJsonNode>()
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Create a wrapper with `chunk` as its chunk
|
|
28
|
+
* @param chunk
|
|
29
|
+
*/
|
|
30
|
+
constructor(chunk: LionWebJsonChunk) {
|
|
31
|
+
this.jsonChunk = chunk
|
|
32
|
+
this.prepareNodeIds(chunk)
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
/** Put all nodes in a map, validate that there are no two nodes with the same id.
|
|
30
36
|
* The check should logically be in LionWebReferenceValidator, but the created map is needed here.
|
|
31
37
|
*/
|
|
32
|
-
prepareNodeIds() {
|
|
33
|
-
|
|
38
|
+
prepareNodeIds(chunk: LionWebJsonChunk) {
|
|
39
|
+
chunk.nodes.forEach(node => {
|
|
34
40
|
this.nodesIdMap.set(node.id, node)
|
|
35
41
|
})
|
|
36
42
|
}
|
|
@@ -39,23 +45,44 @@ export class LionWebJsonChunkWrapper {
|
|
|
39
45
|
return this.nodesIdMap.get(id)
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
return this.jsonChunk.nodes.filter(node => node.classifier
|
|
48
|
+
findNodesOfClassifier(concept: LionWebJsonMetaPointer): LionWebJsonNode[] {
|
|
49
|
+
return this.jsonChunk.nodes.filter(node => isEqualMetaPointer(node.classifier, concept))
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// if (this.language !== null) {
|
|
54
|
-
// // const targetNode = this.language.languageChunkWrapper.getNode(target.reference);
|
|
55
|
-
// // TODO etc., but need to cleanup LanguageDefinition first.
|
|
56
|
-
// }
|
|
57
|
-
// });
|
|
52
|
+
/**
|
|
53
|
+
* Return the target nodes inside `reference` as a list of actual nodes (LionWebJsonNode[])
|
|
54
|
+
* @param reference
|
|
55
|
+
*/
|
|
56
|
+
getReferredNodes(reference: LionWebJsonReference | undefined) {
|
|
57
|
+
if (reference === undefined) {
|
|
58
|
+
return []
|
|
58
59
|
}
|
|
60
|
+
const result = reference.targets.flatMap(target => {
|
|
61
|
+
if (target.reference === null) {
|
|
62
|
+
return []
|
|
63
|
+
} else {
|
|
64
|
+
const referredNode = this.getNode(target.reference)
|
|
65
|
+
return referredNode === undefined ? [] : [referredNode]
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
return result
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Return the target nodes inside `reference` as a list of actual nodes (LionWebJsonNode[])
|
|
73
|
+
* @param reference
|
|
74
|
+
*/
|
|
75
|
+
getChildrenAsNodes(containment: LionWebJsonContainment | undefined) {
|
|
76
|
+
if (containment === undefined) {
|
|
77
|
+
return []
|
|
78
|
+
}
|
|
79
|
+
const result: LionWebJsonNode[] = []
|
|
80
|
+
containment.children.forEach(ch => {
|
|
81
|
+
const childNode = this.getNode(ch)
|
|
82
|
+
if (childNode !== undefined) {
|
|
83
|
+
result.push(childNode)
|
|
84
|
+
}
|
|
85
|
+
})
|
|
59
86
|
return result
|
|
60
87
|
}
|
|
61
88
|
|
|
@@ -71,10 +98,10 @@ export class LionWebJsonChunkWrapper {
|
|
|
71
98
|
|
|
72
99
|
private recursiveToString(node: LionWebJsonNode | undefined, depth: number): string {
|
|
73
100
|
if (node === undefined) {
|
|
74
|
-
return ""
|
|
101
|
+
return ""
|
|
75
102
|
}
|
|
76
103
|
let result: string = ""
|
|
77
|
-
const nameProperty = NodeUtils.findProperty(node,
|
|
104
|
+
const nameProperty = NodeUtils.findProperty(node, MetaPointers.INamedName)
|
|
78
105
|
const name = nameProperty === undefined ? "" : " " + nameProperty.value
|
|
79
106
|
result += this.indent(depth) + "(" + node.id + ")" + name + "\n"
|
|
80
107
|
if (node.annotations !== undefined && node.annotations.length !== 0) {
|
|
@@ -84,9 +111,11 @@ export class LionWebJsonChunkWrapper {
|
|
|
84
111
|
// result += this.indent(depth) + "[[" + JSON.stringify(ann) + "]]\n"
|
|
85
112
|
})
|
|
86
113
|
}
|
|
87
|
-
node.properties
|
|
88
|
-
|
|
89
|
-
|
|
114
|
+
node.properties
|
|
115
|
+
.filter(p => p !== nameProperty)
|
|
116
|
+
.forEach(property => {
|
|
117
|
+
result += this.indent(depth + 1) + "*property* " + property.property.key + ": " + property.value + "\n"
|
|
118
|
+
})
|
|
90
119
|
node.references.forEach(ref => {
|
|
91
120
|
result += this.indent(depth + 1) + "*" + ref.reference.key + "*: " + JSON.stringify(ref.targets) + "\n"
|
|
92
121
|
})
|
|
@@ -100,7 +129,7 @@ export class LionWebJsonChunkWrapper {
|
|
|
100
129
|
})
|
|
101
130
|
return result
|
|
102
131
|
}
|
|
103
|
-
|
|
132
|
+
|
|
104
133
|
private indent(depth: number): string {
|
|
105
134
|
return Array(depth).join(" ")
|
|
106
135
|
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains LionWeb defined M3 keys and identifications.
|
|
3
|
+
*/
|
|
4
|
+
export const LION_CORE_BUILTINS_INAMED_NAME = "LionCore-builtins-INamed-name"
|
|
5
|
+
export const LION_CORE_BUILTINS_KEY = "LionCore-builtins"
|
|
6
|
+
|
|
7
|
+
export const LION_CORE_M3_KEY = "LionCore-M3"
|
|
8
|
+
export const LION_CORE_M3_NAME = "LionCore_M3"
|
|
9
|
+
|
|
10
|
+
export const LION_CORE_M3_VERSION = "2023.1"
|
|
11
|
+
// Builtin datatypes
|
|
12
|
+
export const LIONWEB_BOOLEAN_TYPE = "LionCore-builtins-Boolean"
|
|
13
|
+
export const LIONWEB_JSON_TYPE = "LionCore-builtins-JSON"
|
|
14
|
+
export const LIONWEB_INTEGER_TYPE = "LionCore-builtins-Integer"
|
|
15
|
+
export const LIONWEB_STRING_TYPE = "LionCore-builtins-String"
|
|
16
|
+
|
|
17
|
+
export const M3_Keys = {
|
|
18
|
+
Property: "Property",
|
|
19
|
+
Reference: "Reference",
|
|
20
|
+
Concept: "Concept",
|
|
21
|
+
conceptExtends: "Concept-extends",
|
|
22
|
+
conceptImplements: "Concept-implements",
|
|
23
|
+
concept2: {
|
|
24
|
+
key: "Concept",
|
|
25
|
+
extends: { key: "Concept-extends" },
|
|
26
|
+
implements: { key: "Concept-implements" }
|
|
27
|
+
},
|
|
28
|
+
conceptAbstract: "Concept-abstract",
|
|
29
|
+
conceptPartition: "Concept-partition",
|
|
30
|
+
classifierFeatures: "Classifier-features",
|
|
31
|
+
Interface: "Interface",
|
|
32
|
+
InterfaceExtends: "Interface-extends",
|
|
33
|
+
Containment: "Containment",
|
|
34
|
+
Language: "Language",
|
|
35
|
+
languageVersion: "Language-version",
|
|
36
|
+
IKeyedKey: "IKeyed-key",
|
|
37
|
+
PropertyType: "Property-type",
|
|
38
|
+
Enumeration: "Enumeration",
|
|
39
|
+
EnumerationLiterals: "Enumeration-literals",
|
|
40
|
+
EnumerationLiteral: "EnumerationLiteral",
|
|
41
|
+
INamed: "LionCore-builtins-INamed",
|
|
42
|
+
INamedName: "LionCore-builtins-INamed-name",
|
|
43
|
+
Annotation: "Annotation",
|
|
44
|
+
AnnotationAnnotates: "Annotation-annotates",
|
|
45
|
+
AnnotationExtends: "Annotation-extends",
|
|
46
|
+
AnnotationImplements: "Annotation-implements",
|
|
47
|
+
Node: "LionCore-builtins-Node"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const MetaPointers = {
|
|
51
|
+
Language: {
|
|
52
|
+
version: LION_CORE_M3_VERSION,
|
|
53
|
+
language: LION_CORE_M3_KEY,
|
|
54
|
+
key: M3_Keys.Language
|
|
55
|
+
},
|
|
56
|
+
LanguageVersion: {
|
|
57
|
+
version: LION_CORE_M3_VERSION,
|
|
58
|
+
language: LION_CORE_M3_KEY,
|
|
59
|
+
key: M3_Keys.languageVersion
|
|
60
|
+
},
|
|
61
|
+
ClassifierFeatures: {
|
|
62
|
+
version: LION_CORE_M3_VERSION,
|
|
63
|
+
language: LION_CORE_M3_KEY,
|
|
64
|
+
key: M3_Keys.classifierFeatures
|
|
65
|
+
},
|
|
66
|
+
Concept: {
|
|
67
|
+
version: LION_CORE_M3_VERSION,
|
|
68
|
+
language: LION_CORE_M3_KEY,
|
|
69
|
+
key: M3_Keys.concept2.key
|
|
70
|
+
},
|
|
71
|
+
ConceptAbstract: {
|
|
72
|
+
version: LION_CORE_M3_VERSION,
|
|
73
|
+
language: LION_CORE_M3_KEY,
|
|
74
|
+
key: M3_Keys.conceptAbstract
|
|
75
|
+
},
|
|
76
|
+
ConceptPartition: {
|
|
77
|
+
version: LION_CORE_M3_VERSION,
|
|
78
|
+
language: LION_CORE_M3_KEY,
|
|
79
|
+
key: M3_Keys.conceptPartition
|
|
80
|
+
},
|
|
81
|
+
ConceptExtends: {
|
|
82
|
+
version: LION_CORE_M3_VERSION,
|
|
83
|
+
language: LION_CORE_M3_KEY,
|
|
84
|
+
key: M3_Keys.concept2.extends.key
|
|
85
|
+
},
|
|
86
|
+
ConceptImplements: {
|
|
87
|
+
version: LION_CORE_M3_VERSION,
|
|
88
|
+
language: LION_CORE_M3_KEY,
|
|
89
|
+
key: M3_Keys.concept2.implements.key
|
|
90
|
+
},
|
|
91
|
+
Annotation: {
|
|
92
|
+
version: LION_CORE_M3_VERSION,
|
|
93
|
+
language: LION_CORE_M3_KEY,
|
|
94
|
+
key: M3_Keys.Annotation
|
|
95
|
+
},
|
|
96
|
+
AnnotationAnnotates: {
|
|
97
|
+
version: LION_CORE_M3_VERSION,
|
|
98
|
+
language: LION_CORE_M3_KEY,
|
|
99
|
+
key: M3_Keys.AnnotationAnnotates
|
|
100
|
+
},
|
|
101
|
+
AnnotationExtends: {
|
|
102
|
+
version: LION_CORE_M3_VERSION,
|
|
103
|
+
language: LION_CORE_M3_KEY,
|
|
104
|
+
key: M3_Keys.AnnotationExtends
|
|
105
|
+
},
|
|
106
|
+
AnnotationImplements: {
|
|
107
|
+
version: LION_CORE_M3_VERSION,
|
|
108
|
+
language: LION_CORE_M3_KEY,
|
|
109
|
+
key: M3_Keys.AnnotationImplements
|
|
110
|
+
},
|
|
111
|
+
Interface: {
|
|
112
|
+
version: LION_CORE_M3_VERSION,
|
|
113
|
+
language: LION_CORE_M3_KEY,
|
|
114
|
+
key: M3_Keys.Interface
|
|
115
|
+
},
|
|
116
|
+
InterfaceExtends: {
|
|
117
|
+
version: LION_CORE_M3_VERSION,
|
|
118
|
+
language: LION_CORE_M3_KEY,
|
|
119
|
+
key: M3_Keys.InterfaceExtends
|
|
120
|
+
},
|
|
121
|
+
Enumeration: {
|
|
122
|
+
version: LION_CORE_M3_VERSION,
|
|
123
|
+
language: LION_CORE_M3_KEY,
|
|
124
|
+
key: M3_Keys.Enumeration
|
|
125
|
+
},
|
|
126
|
+
EnumerationLiteral: {
|
|
127
|
+
version: LION_CORE_M3_VERSION,
|
|
128
|
+
language: LION_CORE_M3_KEY,
|
|
129
|
+
key: M3_Keys.EnumerationLiteral
|
|
130
|
+
},
|
|
131
|
+
EnumerationLiterals: {
|
|
132
|
+
version: LION_CORE_M3_VERSION,
|
|
133
|
+
language: LION_CORE_M3_KEY,
|
|
134
|
+
key: M3_Keys.EnumerationLiterals
|
|
135
|
+
},
|
|
136
|
+
Containment: {
|
|
137
|
+
version: LION_CORE_M3_VERSION,
|
|
138
|
+
language: LION_CORE_M3_KEY,
|
|
139
|
+
key: M3_Keys.Containment
|
|
140
|
+
},
|
|
141
|
+
Property: {
|
|
142
|
+
version: LION_CORE_M3_VERSION,
|
|
143
|
+
language: LION_CORE_M3_KEY,
|
|
144
|
+
key: M3_Keys.Property
|
|
145
|
+
},
|
|
146
|
+
PropertyType: {
|
|
147
|
+
version: LION_CORE_M3_VERSION,
|
|
148
|
+
language: LION_CORE_M3_KEY,
|
|
149
|
+
key: M3_Keys.PropertyType
|
|
150
|
+
},
|
|
151
|
+
Reference: {
|
|
152
|
+
version: LION_CORE_M3_VERSION,
|
|
153
|
+
language: LION_CORE_M3_KEY,
|
|
154
|
+
key: M3_Keys.Reference
|
|
155
|
+
},
|
|
156
|
+
IKeyedKey: {
|
|
157
|
+
language: LION_CORE_M3_KEY,
|
|
158
|
+
version: LION_CORE_M3_VERSION,
|
|
159
|
+
key: M3_Keys.IKeyedKey
|
|
160
|
+
},
|
|
161
|
+
// Builtins:
|
|
162
|
+
Node: {
|
|
163
|
+
language: LION_CORE_BUILTINS_KEY,
|
|
164
|
+
version: LION_CORE_M3_VERSION,
|
|
165
|
+
key: M3_Keys.Node
|
|
166
|
+
},
|
|
167
|
+
INamed: {
|
|
168
|
+
language: LION_CORE_BUILTINS_KEY,
|
|
169
|
+
version: LION_CORE_M3_VERSION,
|
|
170
|
+
key: M3_Keys.INamed
|
|
171
|
+
},
|
|
172
|
+
INamedName: {
|
|
173
|
+
language: LION_CORE_BUILTINS_KEY,
|
|
174
|
+
version: LION_CORE_M3_VERSION,
|
|
175
|
+
key: M3_Keys.INamedName
|
|
176
|
+
}
|
|
177
|
+
}
|
package/src/json/NodeUtils.ts
CHANGED
|
@@ -17,16 +17,10 @@ export class NodeUtils {
|
|
|
17
17
|
* @param node
|
|
18
18
|
* @param key
|
|
19
19
|
*/
|
|
20
|
-
static findLwProperty(node: LionWebJsonNode, key: string): LionWebJsonProperty | null {
|
|
21
|
-
for (const property of node.properties) {
|
|
22
|
-
if (property.property.key === key) {
|
|
23
|
-
return property
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return null
|
|
27
|
-
}
|
|
28
|
-
|
|
29
20
|
static findProperty(node: LionWebJsonNode, property: LionWebJsonMetaPointer): LionWebJsonProperty | undefined {
|
|
21
|
+
if (node === undefined) {
|
|
22
|
+
return undefined
|
|
23
|
+
}
|
|
30
24
|
return node.properties.find(
|
|
31
25
|
prop => isEqualMetaPointer(prop.property, property)
|
|
32
26
|
)
|
|
@@ -37,56 +31,44 @@ export class NodeUtils {
|
|
|
37
31
|
* @param node
|
|
38
32
|
* @param key
|
|
39
33
|
*/
|
|
40
|
-
static
|
|
34
|
+
static findChild(node: LionWebJsonNode, key: string): LionWebJsonContainment | undefined {
|
|
35
|
+
if (node === undefined) {
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
41
38
|
for (const containment of node.containments) {
|
|
42
39
|
if (containment.containment.key === key) {
|
|
43
40
|
return containment
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
|
-
return
|
|
43
|
+
return undefined
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
static findContainment(node: LionWebJsonNode, containment: LionWebJsonMetaPointer): LionWebJsonContainment | undefined {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if (node === undefined) {
|
|
48
|
+
return undefined
|
|
49
|
+
}
|
|
50
|
+
return node.containments.find(cont => isEqualMetaPointer(cont.containment, containment))
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (reference.reference.key === key) {
|
|
59
|
-
return reference
|
|
60
|
-
}
|
|
53
|
+
static findReference(node: LionWebJsonNode, reference: LionWebJsonMetaPointer): LionWebJsonReference | undefined {
|
|
54
|
+
if (node === undefined) {
|
|
55
|
+
return undefined
|
|
61
56
|
}
|
|
62
|
-
return
|
|
57
|
+
return node.references.find(ref => isEqualMetaPointer(ref.reference, reference))
|
|
63
58
|
}
|
|
64
59
|
|
|
65
|
-
static
|
|
66
|
-
|
|
60
|
+
static findReferenceTarget(
|
|
61
|
+
referenceTargets: LionWebJsonReferenceTarget[],
|
|
67
62
|
target: LionWebJsonReferenceTarget,
|
|
68
|
-
): LionWebJsonReferenceTarget |
|
|
69
|
-
for (const refTarget of
|
|
63
|
+
): LionWebJsonReferenceTarget | undefined {
|
|
64
|
+
for (const refTarget of referenceTargets) {
|
|
70
65
|
if (isEqualReferenceTarget(refTarget, target)) {
|
|
71
66
|
return refTarget
|
|
72
67
|
}
|
|
73
68
|
}
|
|
74
|
-
return
|
|
69
|
+
return undefined
|
|
75
70
|
}
|
|
76
71
|
|
|
77
|
-
/**
|
|
78
|
-
* Get all nodes that are children for _node_: both the containment and annotation children
|
|
79
|
-
* @param node
|
|
80
|
-
*/
|
|
81
|
-
static allDirectChildren(node: LionWebJsonNode): string[] {
|
|
82
|
-
const result: string[] = []
|
|
83
|
-
for (const containment of node.containments) {
|
|
84
|
-
result.push(...containment.children)
|
|
85
|
-
}
|
|
86
|
-
result.push(...node.annotations)
|
|
87
|
-
return result
|
|
88
|
-
}
|
|
89
|
-
|
|
90
72
|
static findContainmentContainingChild(containments: LionWebJsonContainment[], childId: string): LionWebJsonContainment | undefined {
|
|
91
73
|
return containments.find(cont => cont.children.includes(childId))
|
|
92
74
|
}
|
package/src/json/index.ts
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { LionWebId, LionWebJsonMetaPointer, LionWebJsonNode } from "../json/LionWebJson.js"
|
|
2
|
+
import { LionWebLanguageWrapper } from "./LionWebLanguageWrapper.js"
|
|
3
|
+
import { MetaPointerMap } from "./MetaPointerMap.js"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Collection of language definitions
|
|
7
|
+
*/
|
|
8
|
+
export class CompositeLionWebLanguageWrapper extends LionWebLanguageWrapper {
|
|
9
|
+
metaPointerMap: MetaPointerMap = new MetaPointerMap()
|
|
10
|
+
languageMap = new Map<string, Map<string, LionWebLanguageWrapper>>()
|
|
11
|
+
languages: LionWebLanguageWrapper[] = []
|
|
12
|
+
|
|
13
|
+
addLanguage(lionWebLanguage: LionWebLanguageWrapper) {
|
|
14
|
+
let language = this.languageMap.get(lionWebLanguage.key)
|
|
15
|
+
if (language === undefined) {
|
|
16
|
+
language = new Map<string, LionWebLanguageWrapper>()
|
|
17
|
+
this.languageMap.set(lionWebLanguage.key, language)
|
|
18
|
+
}
|
|
19
|
+
const version = language.get(lionWebLanguage.version)
|
|
20
|
+
if (version === undefined) {
|
|
21
|
+
language.set(lionWebLanguage.version, lionWebLanguage)
|
|
22
|
+
} else {
|
|
23
|
+
// console.error("Language already known")
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
this.languages.push(lionWebLanguage)
|
|
27
|
+
lionWebLanguage.jsonChunk.nodes.forEach(node => {
|
|
28
|
+
this.metaPointerMap.add(lionWebLanguage.key, lionWebLanguage.version, node)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getLanguage(pointer: LionWebJsonMetaPointer): LionWebLanguageWrapper | undefined {
|
|
33
|
+
return this.languageMap.get(pointer.language)?.get(pointer.version)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets the node with _metaPointer_ in any of the known languages
|
|
38
|
+
* @param metaPointer
|
|
39
|
+
*/
|
|
40
|
+
getNodeByMetaPointer(metaPointer: LionWebJsonMetaPointer): LionWebJsonNode | undefined {
|
|
41
|
+
return this.metaPointerMap.get(metaPointer)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get node in any of the languages.
|
|
46
|
+
* @param nodeId
|
|
47
|
+
*/
|
|
48
|
+
getNode(nodeId: LionWebId) {
|
|
49
|
+
for (const chunk of this.languages) {
|
|
50
|
+
const node = chunk.getNode(nodeId)
|
|
51
|
+
if (node !== undefined) {
|
|
52
|
+
return node
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LionWebId, LionWebJsonMetaPointer, LionWebJsonNode } from "../json/LionWebJson.js"
|
|
2
|
+
import { CompositeLionWebLanguageWrapper } from "./CompositeLionWebLanguageWrapper.js"
|
|
3
|
+
import { LionWebLanguageWrapper } from "./LionWebLanguageWrapper.js"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Collection of language definitions
|
|
7
|
+
*/
|
|
8
|
+
export class LanguageRegistry {
|
|
9
|
+
languages: CompositeLionWebLanguageWrapper = new CompositeLionWebLanguageWrapper({nodes: [], languages: [], serializationFormatVersion: "2023.1"})
|
|
10
|
+
|
|
11
|
+
addLanguage(lionWebLanguage: LionWebLanguageWrapper) {
|
|
12
|
+
// console.log("LanguageRegistry.add: " + lionWebLanguage.name + " " + lionWebLanguage.jsonChunk.nodes.length)
|
|
13
|
+
|
|
14
|
+
this.languages.addLanguage(lionWebLanguage)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
clear(): void {
|
|
18
|
+
this.languages = new CompositeLionWebLanguageWrapper({nodes: [], languages: [], serializationFormatVersion: "2023.1"})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getLanguage(pointer: LionWebJsonMetaPointer): LionWebLanguageWrapper | undefined {
|
|
22
|
+
return this.languages.languageMap.get(pointer.language)?.get(pointer.version)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets the node with _metaPointer_ in any of the known languages
|
|
27
|
+
* @param metaPointer
|
|
28
|
+
*/
|
|
29
|
+
getNodeByMetaPointer(metaPointer: LionWebJsonMetaPointer): LionWebJsonNode | undefined {
|
|
30
|
+
return this.languages.getNodeByMetaPointer(metaPointer)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
findNode(nodeId: LionWebId) {
|
|
34
|
+
for (const chunk of this.languages.languages) {
|
|
35
|
+
const node = chunk.getNode(nodeId)
|
|
36
|
+
if (node !== undefined) {
|
|
37
|
+
return node
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return undefined
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// export const KnownLanguages = new LanguageRegistry()
|