occam-verify-cli 0.0.1265 → 0.0.1267

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 (37) hide show
  1. package/lib/dom/assertion/type.js +3 -3
  2. package/lib/dom/combinator.js +1 -15
  3. package/lib/dom/constructor.js +2 -17
  4. package/lib/dom/declaration/combinator.js +24 -4
  5. package/lib/dom/declaration/complexType.js +32 -3
  6. package/lib/dom/declaration/constructor.js +55 -5
  7. package/lib/dom/declaration/metavariable.js +55 -4
  8. package/lib/dom/declaration/type.js +30 -3
  9. package/lib/dom/declaration/variable.js +55 -6
  10. package/lib/dom/metavariable.js +2 -58
  11. package/lib/dom/property.js +10 -18
  12. package/lib/dom/statement.js +1 -15
  13. package/lib/dom/term.js +1 -43
  14. package/lib/dom/type.js +86 -31
  15. package/lib/dom/variable.js +2 -26
  16. package/lib/index.js +2 -1
  17. package/lib/utilities/customGrammar.js +2 -2
  18. package/lib/utilities/json.js +24 -1
  19. package/package.json +1 -1
  20. package/src/dom/assertion/type.js +2 -2
  21. package/src/dom/combinator.js +0 -18
  22. package/src/dom/constructor.js +1 -20
  23. package/src/dom/declaration/combinator.js +24 -3
  24. package/src/dom/declaration/complexType.js +43 -2
  25. package/src/dom/declaration/constructor.js +64 -4
  26. package/src/dom/declaration/metavariable.js +68 -3
  27. package/src/dom/declaration/type.js +38 -2
  28. package/src/dom/declaration/variable.js +69 -5
  29. package/src/dom/metavariable.js +1 -73
  30. package/src/dom/property.js +21 -22
  31. package/src/dom/statement.js +0 -18
  32. package/src/dom/term.js +0 -53
  33. package/src/dom/type.js +51 -37
  34. package/src/dom/variable.js +1 -33
  35. package/src/index.js +1 -0
  36. package/src/utilities/customGrammar.js +1 -2
  37. package/src/utilities/json.js +38 -10
@@ -2,8 +2,11 @@
2
2
 
3
3
  import dom from "../../dom";
4
4
 
5
+ import { objectType } from "../type";
5
6
  import { domAssigned } from "../../dom";
6
7
 
8
+ import constructorVerifier from "../../verifier/constructor";
9
+
7
10
  export default domAssigned(class ConstructorDeclaration {
8
11
  constructor(fileContext, constructor) {
9
12
  this.fileContext = fileContext;
@@ -27,12 +30,25 @@ export default domAssigned(class ConstructorDeclaration {
27
30
 
28
31
  this.fileContext.trace(`Verifying the '${constructorDeclarationString}' constructor declaration...`);
29
32
 
30
- const constructorVerifiedWhenDeclared = this.constructor.verifyWhenDeclared(this.fileContext);
33
+ const term = this.constructor.getTerm(),
34
+ termVerified = this.verifyTerm(term);
35
+
36
+ if (termVerified) {
37
+ let type = this.constructor.getType();
38
+
39
+ const typeVerified = this.verifyType(type);
40
+
41
+ if (typeVerified) {
42
+ const typeName = type.getName();
43
+
44
+ type = this.fileContext.findTypeByTypeName(typeName);
45
+
46
+ term.setType(type);
31
47
 
32
- if (constructorVerifiedWhenDeclared) {
33
- this.fileContext.addConstructor(this.constructor);
48
+ this.fileContext.addConstructor(this.constructor);
34
49
 
35
- verified = true;
50
+ verified = true;
51
+ }
36
52
  }
37
53
 
38
54
  if (verified) {
@@ -42,6 +58,50 @@ export default domAssigned(class ConstructorDeclaration {
42
58
  return verified;
43
59
  }
44
60
 
61
+ verifyTerm(term) {
62
+ let termVerified;
63
+
64
+ const termString = term.getString(); ///
65
+
66
+ this.fileContext.trace(`Verifying the '${termString}' term...`);
67
+
68
+ const termNode = term.getNode();
69
+
70
+ termVerified = constructorVerifier.verifyTerm(termNode, this.fileContext);
71
+
72
+ if (termVerified) {
73
+ this.fileContext.debug(`...verified the '${termString}' term.`);
74
+ }
75
+
76
+ return termVerified;
77
+ }
78
+
79
+ verifyType(type) {
80
+ let typeVerified;
81
+
82
+ if (type === objectType) {
83
+ typeVerified = true;
84
+ } else {
85
+ const typeName = type.getName();
86
+
87
+ this.fileContext.trace(`Verifying the '${typeName}' type...`);
88
+
89
+ const typePresent = this.fileContext.isTypePresentByTypeName(typeName);
90
+
91
+ if (!typePresent) {
92
+ this.fileContext.debug(`The '${typeName}' type is not present.`);
93
+ } else {
94
+ typeVerified = true;
95
+ }
96
+
97
+ if (typeVerified) {
98
+ this.fileContext.debug(`...verified the '${typeName}' type.`);
99
+ }
100
+ }
101
+
102
+ return typeVerified;
103
+ }
104
+
45
105
  static name = "ConstructorDeclaration";
46
106
 
47
107
  static fromConstructorDeclarationNode(constructorDeclarationNode, fileContext) {
@@ -4,8 +4,10 @@ import dom from "../../dom";
4
4
 
5
5
  import { nodeQuery } from "../../utilities/query";
6
6
  import { domAssigned } from "../../dom";
7
+ import {objectType} from "../type";
7
8
 
8
- const metaTypeNodeQuery = nodeQuery("/metavariableDeclaration/metaType");
9
+ const termNodeQuery = nodeQuery("/metavariable/argument/term"),
10
+ metaTypeNodeQuery = nodeQuery("/metavariableDeclaration/metaType");
9
11
 
10
12
  export default domAssigned(class MetavariableDeclaration {
11
13
  constructor(fileContext, string, metavariable) {
@@ -33,9 +35,9 @@ export default domAssigned(class MetavariableDeclaration {
33
35
 
34
36
  this.fileContext.trace(`Verifying the '${metavariableDeclarationString}' metavariable declaration...`);
35
37
 
36
- const metavariableVerifiedWhenDeclared = this.metavariable.verifyWhenDeclared(this.fileContext);
38
+ const metavariableVerified = this.verifyMetavariable(this.metavariable);
37
39
 
38
- if (metavariableVerifiedWhenDeclared) {
40
+ if (metavariableVerified) {
39
41
  this.fileContext.addMetavariable(this.metavariable);
40
42
 
41
43
  verified = true;
@@ -48,6 +50,69 @@ export default domAssigned(class MetavariableDeclaration {
48
50
  return verified;
49
51
  }
50
52
 
53
+ verifyType(type) {
54
+ let typeVerified;
55
+
56
+ if (type === null) {
57
+ typeVerified = true;
58
+ } else {
59
+ if (type === objectType) {
60
+ typeVerified = true;
61
+ } else {
62
+ const typeName = type.getName();
63
+
64
+ this.fileContext.trace(`Verifying the '${typeName}' type...`);
65
+
66
+ const typePresent = this.fileContext.isTypePresentByTypeName(typeName);
67
+
68
+ if (!typePresent) {
69
+ this.fileContext.debug(`The '${typeName}' type is not present.`);
70
+ } else {
71
+ typeVerified = true;
72
+ }
73
+
74
+ if (typeVerified) {
75
+ this.fileContext.debug(`...verified the '${typeName}' type.`);
76
+ }
77
+ }
78
+ }
79
+
80
+ return typeVerified;
81
+ }
82
+
83
+ verifyMetavariable(metavariable) {
84
+ let metavariableVerified = false;
85
+
86
+ const metavariableString = metavariable.getString();
87
+
88
+ this.fileContext.trace(`Verifying the '${metavariableString}' metavariable when declared...`);
89
+
90
+ const metavariableNode = metavariable.getNode(), ///
91
+ termNode = termNodeQuery(metavariableNode);
92
+
93
+ if (termNode !== null) {
94
+ this.fileContext.debug(`A term was found in the '${metavariableString}' metavariable when a type should have been present.`);
95
+ } else {
96
+ const metavariableName = metavariable.getName(),
97
+ metavariablePresent = this.fileContext.isMetavariablePresentByMetavariableName(metavariableName);
98
+
99
+ if (metavariablePresent) {
100
+ this.fileContext.debug(`The '${metavariableName}' metavariable is already present.`);
101
+ } else {
102
+ const type = metavariable.getType(),
103
+ typeVerified = this.verifyType(type);
104
+
105
+ metavariableVerified = typeVerified; ///
106
+ }
107
+ }
108
+
109
+ if (metavariableVerified) {
110
+ this.fileContext.debug(`...verified the '${metavariableString}' metavariable when declared.`);
111
+ }
112
+
113
+ return metavariableVerified;
114
+ }
115
+
51
116
  static name = "MetavariableDeclaration";
52
117
 
53
118
  static fromMetavariableDeclarationNode(metavariableDeclarationNode, fileContext) {
@@ -27,9 +27,9 @@ export default domAssigned(class TypeDeclaration {
27
27
 
28
28
  this.fileContext.trace(`Verifying the '${typeDeclarationString}' type declaration...`);
29
29
 
30
- const typeVerifiedWhenDeclared = this.type.verifyWhenDeclared(this.fileContext);
30
+ const typeVerified = this.verifyType(this.type);
31
31
 
32
- if (typeVerifiedWhenDeclared) {
32
+ if (typeVerified) {
33
33
  this.fileContext.addType(this.type);
34
34
 
35
35
  verified = true;
@@ -42,6 +42,42 @@ export default domAssigned(class TypeDeclaration {
42
42
  return verified;
43
43
  }
44
44
 
45
+ verifyType(type) {
46
+ let typeVerified = false;
47
+
48
+ const typeName = type.getName();
49
+
50
+ this.fileContext.trace(`Verifying the '${typeName}' type...`);
51
+
52
+ const typePresent = this.fileContext.isTypePresentByTypeName(typeName);
53
+
54
+ if (typePresent) {
55
+ this.fileContext.debug(`The type '${typeName}' is not present.`);
56
+ } else {
57
+ let superType;
58
+
59
+ superType = type.getSuperType();
60
+
61
+ const superTypeName = superType.getName();
62
+
63
+ superType = this.fileContext.findTypeByTypeName(superTypeName);
64
+
65
+ if (superType === null) {
66
+ this.fileContext.debug(`The super-type '${superTypeName}' is not present.`);
67
+ } else {
68
+ type.setSuperType(superType);
69
+
70
+ typeVerified = true;
71
+ }
72
+ }
73
+
74
+ if (typeVerified) {
75
+ this.fileContext.debug(`...typeVerified the '${typeName}' type.`);
76
+ }
77
+
78
+ return typeVerified;
79
+ }
80
+
45
81
  static name = "TypeDeclaration";
46
82
 
47
83
  static fromTypeDeclarationNode(typeDeclarationNode, fileContext) {
@@ -3,6 +3,7 @@
3
3
  import dom from "../../dom";
4
4
 
5
5
  import { nodeQuery } from "../../utilities/query";
6
+ import { objectType } from "../type";
6
7
  import { domAssigned } from "../../dom";
7
8
  import { typeNameFromTypeNode } from "../../utilities/name";
8
9
 
@@ -28,18 +29,32 @@ export default domAssigned(class VariableDeclaration {
28
29
  }
29
30
 
30
31
  verify() {
31
- let verified;
32
+ let verified = false;
32
33
 
33
34
  const variableDeclarationString = this.string; ///
34
35
 
35
36
  this.fileContext.trace(`Verifying the '${variableDeclarationString}' variable declaration...`);
36
37
 
37
- const variableVerifiedWhenDeclared = this.variable.verifyWhenDeclared(this.fileContext);
38
+ const variableVerified = this.verifyVariable(this.variable);
38
39
 
39
- if (variableVerifiedWhenDeclared) {
40
- this.fileContext.addVariable(this.variable);
40
+ if (variableVerified) {
41
+ let type;
41
42
 
42
- verified = true;
43
+ type = this.variable.getType();
44
+
45
+ const typeVerified = this.verifyType(type);
46
+
47
+ if (typeVerified) {
48
+ const typeName = type.getName();
49
+
50
+ type = this.fileContext.findTypeByTypeName(typeName);
51
+
52
+ this.variable.setType(type);
53
+
54
+ this.fileContext.addVariable(this.variable);
55
+
56
+ verified = true;
57
+ }
43
58
  }
44
59
 
45
60
  if (verified) {
@@ -49,6 +64,55 @@ export default domAssigned(class VariableDeclaration {
49
64
  return verified;
50
65
  }
51
66
 
67
+ verifyType(type) {
68
+ let typeVerified = false;
69
+
70
+ if (type === objectType) {
71
+ typeVerified = true;
72
+ } else {
73
+ const typeName = type.getName();
74
+
75
+ this.fileContext.trace(`Verifying the '${typeName}' type...`);
76
+
77
+ const typePresent = this.fileContext.isTypePresentByTypeName(typeName);
78
+
79
+ if (!typePresent) {
80
+ this.fileContext.debug(`The '${typeName}' type is not present.`);
81
+ } else {
82
+ typeVerified = true;
83
+ }
84
+
85
+ if (typeVerified) {
86
+ this.fileContext.debug(`...verified the '${typeName}' type.`);
87
+ }
88
+ }
89
+
90
+ return typeVerified;
91
+ }
92
+
93
+ verifyVariable(variable) {
94
+ let variableVerified = false;
95
+
96
+ const variableString = variable.getString();
97
+
98
+ this.fileContext.trace(`Verifying the '${variableString}' variable...`);
99
+
100
+ const variableName = variable.getName(),
101
+ variablePresent = this.fileContext.isVariablePresentByVariableName(variableName);
102
+
103
+ if (variablePresent) {
104
+ this.fileContext.debug(`The '${variableName}' variable is already present.`);
105
+ } else {
106
+ variableVerified = true;
107
+ }
108
+
109
+ if ( variableVerified) {
110
+ this.fileContext.debug(`...verified the '${variableString}' variable.`);
111
+ }
112
+
113
+ return variableVerified;
114
+ }
115
+
52
116
  static name = "VariableDeclaration";
53
117
 
54
118
  static fromVariableDeclarationNode(variableDeclarationNode, fileContext) {
@@ -17,8 +17,7 @@ import { metavariableFromFrame, metavariableFromStatement } from "../utilities/v
17
17
  import { unifyMetavariable, unifyMetavariableIntrinsically } from "../utilities/unification";
18
18
  import { typeNameFromTypeNode, metavariableNameFromMetavariableNode } from "../utilities/name";
19
19
 
20
- const termNodeQuery = nodeQuery("/metavariable/argument/term"),
21
- metavariableNodeQuery = nodeQuery("/metavariableDeclaration/metavariable"),
20
+ const metavariableNodeQuery = nodeQuery("/metavariableDeclaration/metavariable"),
22
21
  frameMetavariableNodeQuery = nodeQuery("/frame/metavariable!"),
23
22
  labelMetavariableNodeQuery = nodeQuery("/label/metavariable"),
24
23
  referenceMetavariableNodeQuery = nodeQuery("/reference/metavariable"),
@@ -127,77 +126,6 @@ export default domAssigned(class Metavariable {
127
126
  return verified;
128
127
  }
129
128
 
130
- verifyType(fileContext) {
131
- let typeVerified;
132
-
133
- if (this.type === null) {
134
- typeVerified = true;
135
- } else {
136
- if (this.type === objectType) {
137
- typeVerified = true;
138
- } else {
139
- const typeName = this.type.getName();
140
-
141
- fileContext.trace(`Verifying the '${typeName}' type...`);
142
-
143
- const type = fileContext.findTypeByTypeName(typeName);
144
-
145
- if (type === null) {
146
- fileContext.debug(`The '${typeName}' type is missing.`);
147
- } else {
148
- this.type = type; ///
149
-
150
- typeVerified = true;
151
- }
152
-
153
- if (typeVerified) {
154
- fileContext.debug(`...verified the '${typeName}' type.`);
155
- }
156
- }
157
- }
158
-
159
- return typeVerified;
160
- }
161
-
162
- verifyWhenDeclared(fileContext) {
163
- let verifiedWhenDeclared = false;
164
-
165
- const metavariableString = this.string; ///
166
-
167
- fileContext.trace(`Verifying the '${metavariableString}' metavariable when declared...`);
168
-
169
- const metavariableNode = this.node, ///
170
- termNode = termNodeQuery(metavariableNode);
171
-
172
- if (termNode !== null) {
173
- fileContext.debug(`A term was found in the '${metavariableString}' metavariable when a type should have been present.`);
174
- } else {
175
- const metavariableName = this.name, ///
176
- metavariablePresent = fileContext.isMetavariablePresentByMetavariableName(metavariableName);
177
-
178
- if (metavariablePresent) {
179
- fileContext.debug(`The '${metavariableName}' metavariable has already been declared.`);
180
- } else {
181
- const variableName = this.name, ///
182
- variablePresent = fileContext.isVariablePresentByVariableName(variableName);
183
-
184
- if (variablePresent) {
185
- fileContext.debug(`A '${metavariableName}' variable has already been declared.`);
186
- } else {
187
- const typeVerified = this.verifyType(fileContext);
188
-
189
- verifiedWhenDeclared = typeVerified;
190
- }
191
- }
192
- }
193
-
194
- if (verifiedWhenDeclared) {
195
- fileContext.debug(`...verified the '${metavariableString}' metavariable when declared.`);
196
- }
197
-
198
- return verifiedWhenDeclared;
199
- }
200
-
201
129
  verifyGivenMetaType(metaType, context) {
202
130
  let verifiedGivenMetaType = false;
203
131
 
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  import dom from "../dom";
4
- import LocalContext from "../context/local";
5
4
 
6
5
  import { nodeQuery } from "../utilities/query";
7
6
  import { domAssigned } from "../dom";
8
7
  import { typeFromJSON, typeToTypeJSON } from "../utilities/json";
9
- import { propertyNameFromPropertyNode } from "../utilities/name";
10
8
 
11
- const propertyDeclarationTypeNodeQuery = nodeQuery("/propertyDeclaration/type");
9
+ const typeNodeQuery = nodeQuery("/property/type"),
10
+ propertyNodeQuery = nodeQuery("/propertyDeclaration/property"),
11
+ nameTerminalNodeQuery = nodeQuery("/property/@name");
12
12
 
13
13
  export default domAssigned(class Property {
14
14
  constructor(string, name, type) {
@@ -68,31 +68,30 @@ export default domAssigned(class Property {
68
68
  return property;
69
69
  }
70
70
 
71
- static fromPropertyDeclarationNode(propertyDeclarationNode, context) {
72
- let property = null;
73
-
74
- const propertyNode = propertyNodeQuery(propertyDeclarationNode);
75
-
76
- if (propertyNode !== null) {
77
- const node = propertyNode, ///
78
- propertyName = propertyNameFromPropertyNode(propertyDeclarationNode),
79
- string = context.nodeAsString(node),
80
- name = propertyName, ///
81
- type = null;
82
-
83
- property = new Property(string, node, name, type);
84
- }
71
+ static fromPropertyDeclarationNode(propertyDeclarationNode, fileContext) {
72
+ const propertyNode = propertyNodeQuery(propertyDeclarationNode),
73
+ node = propertyNode, ///
74
+ name = nameFromPropertyNode(propertyNode),
75
+ type = typeFromPropertyNode(propertyNode),
76
+ string = fileContext.nodeAsString(node),
77
+ property = new Property(string, name, type);
85
78
 
86
79
  return property;
87
80
  }
88
81
  });
89
82
 
90
- function typeFromPropertyDeclarationNode(propertyDeclarationNode, fileContext) {
83
+ function nameFromPropertyNode(propertyNode, fileContext) {
84
+ const nameTerminalNode = nameTerminalNodeQuery(propertyNode),
85
+ nameTerminalNodeContent = nameTerminalNode.getContent(),
86
+ name = nameTerminalNodeContent; ///
87
+
88
+ return name;
89
+ }
90
+
91
+ function typeFromPropertyNode(propertyNode, fileContext) {
91
92
  const { Type } = dom,
92
- propertyDeclarationTypeNode = propertyDeclarationTypeNodeQuery(propertyDeclarationNode),
93
- typeNode = propertyDeclarationTypeNode, ///
94
- context = LocalContext.fromFileContext(fileContext),
95
- type = Type.fromTypeNode(typeNode, context);
93
+ typeNode = typeNodeQuery(propertyNode),
94
+ type = Type.fromTypeNode(typeNode);
96
95
 
97
96
  return type;
98
97
  }
@@ -5,7 +5,6 @@ import { arrayUtilities } from "necessary";
5
5
  import dom from "../dom";
6
6
  import LocalContext from "../context/local";
7
7
  import verifyMixins from "../mixins/statement/verify";
8
- import combinatorVerifier from "../verifier/combinator";
9
8
  import StatementPartialContext from "../context/partial/statement";
10
9
 
11
10
  import { domAssigned } from "../dom";
@@ -128,23 +127,6 @@ export default domAssigned(class Statement {
128
127
  return verified;
129
128
  }
130
129
 
131
- verifyWhenDeclared(fileContext) {
132
- let verifiedWhenDeclared;
133
-
134
- const statementNode = this.node, ///
135
- statementString = this.string; ///
136
-
137
- fileContext.trace(`Verifying the '${statementString}' statement when declared...`);
138
-
139
- verifiedWhenDeclared = combinatorVerifier.verifyStatement(statementNode, fileContext);
140
-
141
- if (verifiedWhenDeclared) {
142
- fileContext.debug(`...verified the '${statementString}' statement when declared.`);
143
- }
144
-
145
- return verifiedWhenDeclared;
146
- }
147
-
148
130
  verifyGivenMetaType(metaType, assignments, stated, context) {
149
131
  let verifiedGivenMetaType = false;
150
132
 
package/src/dom/term.js CHANGED
@@ -5,9 +5,7 @@ import { arrayUtilities } from "necessary";
5
5
  import dom from "../dom";
6
6
  import LocalContext from "../context/local";
7
7
  import verifyMixins from "../mixins/term/verify";
8
- import constructorVerifier from "../verifier/constructor";
9
8
 
10
- import { objectType } from "./type";
11
9
  import { domAssigned } from "../dom";
12
10
  import { nodeQuery, nodesQuery } from "../utilities/query"
13
11
  import { termNodeFromTermString } from "../context/partial/term";
@@ -149,34 +147,6 @@ export default domAssigned(class Term {
149
147
  return verified;
150
148
  }
151
149
 
152
- verifyType(fileContext) {
153
- let typeVerified;
154
-
155
- if (this.type === objectType) {
156
- typeVerified = true;
157
- } else {
158
- const typeName = this.type.getName();
159
-
160
- fileContext.trace(`Verifying the '${typeName}' type...`);
161
-
162
- const type = fileContext.findTypeByTypeName(typeName);
163
-
164
- if (type === null) {
165
- fileContext.debug(`The '${typeName}' type is missing.`);
166
- } else {
167
- this.type = type; ///
168
-
169
- typeVerified = true;
170
- }
171
-
172
- if (typeVerified) {
173
- fileContext.debug(`...verified the '${typeName}' type.`);
174
- }
175
- }
176
-
177
- return typeVerified;
178
- }
179
-
180
150
  verifyGivenType(type, generalContext, specificContext) {
181
151
  let verifiedGivenType;
182
152
 
@@ -207,29 +177,6 @@ export default domAssigned(class Term {
207
177
  return verifiedGivenType;
208
178
  }
209
179
 
210
- verifyWhenDeclared(fileContext) {
211
- let verifiedWhenDeclared;
212
-
213
- const termString = this.string; ///
214
-
215
- fileContext.trace(`Verifying the '${termString}' term when declared...`);
216
-
217
- const termNode = this.node, ///
218
- termVerifiedAsConstructor = constructorVerifier.verifyTerm(termNode, fileContext);
219
-
220
- if (termVerifiedAsConstructor) {
221
- const typeVerified = this.verifyType(fileContext);
222
-
223
- verifiedWhenDeclared = typeVerified; ///
224
- }
225
-
226
- if (verifiedWhenDeclared) {
227
- fileContext.debug(`...verified the '${termString}' term when declared.`);
228
- }
229
-
230
- return verifiedWhenDeclared;
231
- }
232
-
233
180
  toJSON() {
234
181
  const typeJSON = typeToTypeJSON(this.type),
235
182
  string = this.string,