-
Notifications
You must be signed in to change notification settings - Fork 0
/
sbvr-compiler-libs.ometajs
109 lines (97 loc) · 2.75 KB
/
sbvr-compiler-libs.ometajs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var SBVRLibs = require('@balena/sbvr-parser/sbvr-libs').SBVRLibs;
export ometa SBVRCompilerLibs <: SBVRLibs {
ResolveSynonym :name =
?this.synonyms[name]
-> this.synonyms[name]
| -> name
}
SBVRCompilerLibs.initialize = function() {
SBVRLibs.initialize.call(this);
this.synonyms = {};
};
SBVRCompilerLibs.TYPE_VOCAB = 'Type';
SBVRCompilerLibs.IsPrimitive = function(term) {
// do {
if (term[2] == this.TYPE_VOCAB) {
return term[1];
}
// } while (this.conceptTypes.hasOwnProperty(termName) && (termName = this.conceptTypes[termName]));
if( (term = this.FollowConceptType(term)) !== false ) {
if (term[2] == this.TYPE_VOCAB) {
return term[1];
}
}
return false;
};
SBVRCompilerLibs.IsChild = function(child, parent) {
// Parent should be in the form ['Term', ...], where we care about the ... bit.
do {
if(this.IdentifiersEqual(child, parent)) {
return true;
}
} while( (child = this.FollowConceptType(child)) !== false );
return false;
};
SBVRCompilerLibs.MappedFactType = function(factType) {
var traverseInfo = this._traverseFactType(factType),
mappedFactType = [];
if(traverseInfo===false || !traverseInfo.hasOwnProperty('__valid')) {
return false;
}
for(var i = 0; i < traverseInfo.__valid.length; i++) {
mappedFactType[i] = traverseInfo.__valid[i].slice();
}
// Keep the negated status the same as fact type passed in.
mappedFactType[1][2] = factType[1][2];
return mappedFactType;
};
SBVRCompilerLibs.UnmappedFactType = function(factType) {
var mappedFactType = this.MappedFactType(factType);
if(mappedFactType === false) {
return false;
}
for(var i = 0; i < mappedFactType.length; i++) {
mappedFactType[i] = mappedFactType[i].slice(0, 3);
}
return mappedFactType;
};
SBVRCompilerLibs.GetResourceName = function(termOrFactType) {
var i = 0, resource = [];
if(typeof termOrFactType === 'string') {
return this.ResolveSynonym(termOrFactType);
}
else {
for(;i < termOrFactType.length; i++) {
resource.push(this.ResolveSynonym(termOrFactType[i][1]));
}
return resource.join('-');
}
};
SBVRCompilerLibs.GetTable = function(termNameOrFactType) {
return this.tables[this.GetResourceName(termNameOrFactType)];
};
SBVRCompilerLibs.GetTableID = function(termOrFactType) {
switch(termOrFactType[0]) {
case 'Term':
case 'Name':
return termOrFactType[1];
default:
return termOrFactType;
}
};
SBVRCompilerLibs.GetTableField = function(table, fieldName) {
var fieldID = this.GetTableFieldID(table, fieldName);
if(fieldID === false) {
return false;
}
return table.fields[fieldID];
};
SBVRCompilerLibs.GetTableFieldID = function(table, fieldName) {
var tableFields = table.fields;
for(var i = 0; i < tableFields.length; i++) {
if(tableFields[i].fieldName == fieldName) {
return i;
}
}
return false;
};