occam-verify-cli 1.0.900 → 1.0.905

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/context/file/nominal.js +7 -4
  2. package/lib/context/mnemic.js +56 -26
  3. package/lib/context/synoptic.js +30 -14
  4. package/lib/context.js +31 -14
  5. package/lib/element/assertion/property.js +26 -25
  6. package/lib/element/assertion/satisfies.js +6 -1
  7. package/lib/element/assertion/type.js +7 -7
  8. package/lib/element/declaration/complexType.js +5 -3
  9. package/lib/element/declaration/property.js +17 -10
  10. package/lib/element/declaration/simpleType.js +11 -20
  11. package/lib/element/equality.js +3 -3
  12. package/lib/element/signature.js +40 -50
  13. package/lib/element/topLevelAssertion/axiom.js +9 -4
  14. package/lib/element/type.js +11 -14
  15. package/lib/utilities/assignment.js +3 -3
  16. package/lib/utilities/element.js +2 -2
  17. package/lib/utilities/json.js +23 -1
  18. package/lib/utilities/synoptic.js +12 -1
  19. package/package.json +1 -1
  20. package/src/context/file/nominal.js +8 -4
  21. package/src/context/mnemic.js +85 -31
  22. package/src/context/synoptic.js +40 -16
  23. package/src/context.js +44 -16
  24. package/src/element/assertion/property.js +38 -36
  25. package/src/element/assertion/satisfies.js +8 -0
  26. package/src/element/assertion/type.js +6 -6
  27. package/src/element/declaration/complexType.js +10 -2
  28. package/src/element/declaration/property.js +20 -11
  29. package/src/element/declaration/simpleType.js +16 -28
  30. package/src/element/equality.js +2 -2
  31. package/src/element/signature.js +53 -75
  32. package/src/element/topLevelAssertion/axiom.js +11 -4
  33. package/src/element/type.js +15 -19
  34. package/src/utilities/assignment.js +2 -2
  35. package/src/utilities/element.js +1 -1
  36. package/src/utilities/json.js +28 -2
  37. package/src/utilities/synoptic.js +10 -0
@@ -77,10 +77,18 @@ export default define(class ComplexTypeDeclaration extends Declaration {
77
77
  const propertyDeclarationsVerify = await this.verifyPropertyDeclaratisons(context);
78
78
 
79
79
  if (propertyDeclarationsVerify) {
80
- const properties = this.getProperties();
80
+ const properties = this.getProperties(),
81
+ typePrefix = context.getTypePrefix(),
82
+ prefixName = (typePrefix !== null) ?
83
+ typePrefix.getPrefixName() :
84
+ null;
85
+
86
+ this.type.setProvisional(this.provisional);
81
87
 
82
88
  this.type.setProperties(properties);
83
89
 
90
+ this.type.setPrefixName(prefixName);
91
+
84
92
  context.addType(this.type);
85
93
 
86
94
  verifies = true;
@@ -231,7 +239,7 @@ export default define(class ComplexTypeDeclaration extends Declaration {
231
239
  const properties = this.getProperties();
232
240
 
233
241
  propertyDeclarationsVerify = await asyncEvery(this.propertyDeclarations, async (propertyDeclaration) => {
234
- const propertyVerifes = await propertyDeclaration.verify(properties, context);
242
+ const propertyVerifes = await propertyDeclaration.verify(properties, this.type, context);
235
243
 
236
244
  if (propertyVerifes) {
237
245
  return true;
@@ -20,7 +20,7 @@ export default define(class PropertyDeclaration extends Declaration {
20
20
  return this.type;
21
21
  }
22
22
 
23
- async verify(properties, context) {
23
+ async verify(properties, type, context) {
24
24
  let verifies = false;
25
25
 
26
26
  await this.break(context);
@@ -30,7 +30,7 @@ export default define(class PropertyDeclaration extends Declaration {
30
30
  context.trace(`Verifying the '${propertyDeclarationString}' property declaration...`);
31
31
 
32
32
  if (this.property !== null) {
33
- const typeVerifies = this.verifyType(context);
33
+ const typeVerifies = this.verifyType(type, context);
34
34
 
35
35
  if (typeVerifies) {
36
36
  const propertyVerifies = this.verifyProperty(properties, context);
@@ -52,27 +52,36 @@ export default define(class PropertyDeclaration extends Declaration {
52
52
  return verifies;
53
53
  }
54
54
 
55
- verifyType(context) {
55
+ verifyType(type, context) {
56
56
  let typeVerifies = false;
57
57
 
58
- const typeString = this.type.getString(),
59
- propertyDeclarationString = this.getString(); ///
58
+ const propertyDeclarationString = this.getString(); ///
60
59
 
61
- context.trace(`Verifying the '${propertyDeclarationString}' property declaration's '${typeString}' type...`);
60
+ context.trace(`Verifying the '${propertyDeclarationString}' property declaration's type...`);
62
61
 
63
- const typeName = this.type.getName(),
64
- type = context.findTypeByTypeName(typeName);
62
+ const nominalTypeName = this.type.getNominalTypeName(),
63
+ comparesToNominalTypeName = type.compareNominalTypeName(nominalTypeName);
65
64
 
66
- if (type !== null) {
65
+ if (comparesToNominalTypeName) {
67
66
  this.type = type;
68
67
 
69
68
  typeVerifies = true;
70
69
  } else {
71
- context.debug(`The '${typeString}' type is not present.`);
70
+ const type = context.findTypeByTypeName(nominalTypeName);
71
+
72
+ if (type !== null) {
73
+ this.type = type;
74
+
75
+ typeVerifies = true;
76
+ } else {
77
+ const typeString = this.type.getString();
78
+
79
+ context.debug(`The '${typeString}' type is not present.`);
80
+ }
72
81
  }
73
82
 
74
83
  if (typeVerifies) {
75
- context.debug(`...verified the '${propertyDeclarationString}' property declaration's '${typeString}' type`);
84
+ context.debug(`...verified the '${propertyDeclarationString}' property declaration's type`);
76
85
  }
77
86
 
78
87
  return typeVerifies;
@@ -33,6 +33,12 @@ export default define(class SimpleTypeDeclaration extends Declaration {
33
33
  return simpleTypeDeclarationNode;
34
34
  }
35
35
 
36
+ getProperties() {
37
+ const properties = [];
38
+
39
+ return properties;
40
+ }
41
+
36
42
  async verify(context) {
37
43
  let verifies = false;
38
44
 
@@ -51,20 +57,21 @@ export default define(class SimpleTypeDeclaration extends Declaration {
51
57
  const typePrefixVerifies = this.verifyTypePrefix(context);
52
58
 
53
59
  if (typePrefixVerifies) {
54
- const propertiesVerifies = this.verifyProperties(context);
60
+ const properties = this.getProperties(),
61
+ typePrefix = context.getTypePrefix(),
62
+ prefixName = (typePrefix !== null) ?
63
+ typePrefix.getPrefixName() :
64
+ null;
55
65
 
56
- if (propertiesVerifies) {
57
- const typePrefix = context.getTypePrefix(),
58
- prefixName = typePrefix.getPrefixName();
66
+ this.type.setProvisional(this.provisional);
59
67
 
60
- this.type.setProvisional(this.provisional);
68
+ this.type.setProperties(properties);
61
69
 
62
- this.type.setPrefixName(prefixName);
70
+ this.type.setPrefixName(prefixName);
63
71
 
64
- context.addType(this.type);
72
+ context.addType(this.type);
65
73
 
66
- verifies = true;
67
- }
74
+ verifies = true;
68
75
  }
69
76
  }
70
77
  }
@@ -197,24 +204,5 @@ export default define(class SimpleTypeDeclaration extends Declaration {
197
204
  return typePrefixVerifies;
198
205
  }
199
206
 
200
- verifyProperties(context) {
201
- let propertiesVerify = true; ///
202
-
203
- const typeString = this.type.getString(),
204
- simpleTypeDeclarationString = this.getString(); ///
205
-
206
- context.trace(`Verifying the '${simpleTypeDeclarationString}' simple type declaration's '${typeString}' type's properties...`);
207
-
208
- const properties = [];
209
-
210
- this.type.setProperties(properties);
211
-
212
- if (propertiesVerify) {
213
- context.debug(`...verified the '${simpleTypeDeclarationString}' simple type declaration's '${typeString}' type's properties.`);
214
- }
215
-
216
- return propertiesVerify;
217
- }
218
-
219
207
  static name = "SimpleTypeDeclaration";
220
208
  });
@@ -183,9 +183,9 @@ export default define(class Equality extends Element {
183
183
 
184
184
  const leftTermType = leftTerm.getType(),
185
185
  rightTermType = rightTerm.getType(),
186
- leftTermTypeComparableToRightTermType = leftTermType.isComparableTo(rightTermType);
186
+ leftTermTypeEqualToSubTypeOrSuperTypeOfRightTermType = leftTermType.isEqualToSubTypeOrSuperTypeOf(rightTermType);
187
187
 
188
- if (leftTermTypeComparableToRightTermType) {
188
+ if (leftTermTypeEqualToSubTypeOrSuperTypeOfRightTermType) {
189
189
  validatesForwards = true;
190
190
  }
191
191
 
@@ -6,9 +6,9 @@ import { arrayUtilities } from "necessary";
6
6
  import elements from "../elements";
7
7
 
8
8
  import { define } from "../elements";
9
- import { instantiate } from "../utilities/context";
10
9
  import { instantiateSignature } from "../process/instantiate";
11
10
  import { termsFromSignatureNode } from "../utilities/element";
11
+ import { attempt, serialise, unserialise, instantiate } from "../utilities/context";
12
12
 
13
13
  const { match, compare, correlate } = arrayUtilities;
14
14
 
@@ -37,11 +37,17 @@ export default define(class Signature extends Element {
37
37
 
38
38
  context.trace(`Verifying the '${signatureString}' signature...`);
39
39
 
40
- const signature = this.validate(context);
40
+ attempt((context) => {
41
+ const termsValidate = this.validateTerms(context);
41
42
 
42
- if (signature !== null) {
43
- verifies = true;
44
- }
43
+ if (termsValidate !== null) {
44
+ verifies = true;
45
+ }
46
+
47
+ if (verifies) {
48
+ this.commit(context);
49
+ }
50
+ }, context);
45
51
 
46
52
  if (verifies) {
47
53
  context.debug(`...verified the '${signatureString}' signature.`);
@@ -50,71 +56,33 @@ export default define(class Signature extends Element {
50
56
  return verifies;
51
57
  }
52
58
 
53
- validate(context) {
54
- let signature = null;
59
+ validateTerms(context) {
60
+ let termsValidate;
55
61
 
56
62
  const signatureString = this.getString(); ///
57
63
 
58
- context.trace(`Validating the '${signatureString}' signature...`);
59
-
60
- const terms = [],
61
- termsValidate = this.validateTerms(terms, context);
62
-
63
- if (termsValidate) {
64
- this.terms = terms;
65
-
66
- signature = this; ///
67
- }
68
-
69
- if (signature) {
70
- context.debug(`...validated the '${signatureString}' signature.`);
71
- }
72
-
73
- return signature
74
- }
64
+ context.trace(`Validating the '${signatureString}' signature's terms...`);
75
65
 
76
- validateTerm(term, terms, context) {
77
- let termValidates = false;
66
+ const terms = [];
78
67
 
79
- const termString = term.getString(),
80
- signatureString = this.getString(); ///
68
+ termsValidate = this.terms.every((term) => {
69
+ term = term.validate(context, (term) => { ///
70
+ const validatesForwards = true;
81
71
 
82
- context.trace(`Validating the '${signatureString}' signature's '${termString}' term...`);
72
+ return validatesForwards;
73
+ });
83
74
 
84
- term = term.validate(context, (term) => { ///
85
- const validatesForwards = true;
75
+ if (term !== null) {
76
+ terms.push(term);
86
77
 
87
- return validatesForwards;
78
+ return true;
79
+ }
88
80
  });
89
81
 
90
- if (term !== null) {
91
- terms.push(term);
92
-
93
- termValidates = true;
94
- }
95
-
96
- if (termValidates) {
97
- context.debug(`...validated the '${signatureString}' signature's '${termString}' term.`);
82
+ if (termsValidate) {
83
+ this.terms = terms;
98
84
  }
99
85
 
100
- return termValidates
101
- }
102
-
103
- validateTerms(terms, context) {
104
- let termsValidate;
105
-
106
- const signatureString = this.getString(); ///
107
-
108
- context.trace(`Validating the '${signatureString}' signature's terms...`);
109
-
110
- termsValidate = terms.every((term) => {
111
- const termValidates = this.validateTerm(term, terms, context);
112
-
113
- if (termValidates) {
114
- return true;
115
- }
116
- })
117
-
118
86
  if (termsValidate){
119
87
  context.debug(`...validated the '${signatureString}' signature's terms.`);
120
88
  }
@@ -219,25 +187,35 @@ export default define(class Signature extends Element {
219
187
  static name = "Signature";
220
188
 
221
189
  toJSON() {
222
- const string = this.getString(),
223
- lineIndex = this.getLineIndex(),
224
- json = {
225
- string,
226
- lineIndex
227
- };
228
-
229
- return json;
190
+ const context = this.getContext();
191
+
192
+ return serialise((context) => {
193
+ const string = this.getString(),
194
+ lineIndex = this.getLineIndex(),
195
+ json = {
196
+ context,
197
+ string,
198
+ lineIndex
199
+ };
200
+
201
+ return json;
202
+ }, context);
230
203
  }
231
204
 
232
205
  static fromJSON(json, context) {
233
- return instantiate((context) => {
234
- const { string, lineIndex } = json,
235
- signatureNode = instantiateSignature(string, context),
236
- node = signatureNode, ///
237
- terms = termsFromSignatureNode(signatureNode, context),
238
- signature = new Signature(context, string, node, lineIndex, terms);
239
-
240
- return signature;
241
- }, context);
206
+ let signature;
207
+
208
+ unserialise((json, context) => {
209
+ instantiate((context) => {
210
+ const { string, lineIndex } = json,
211
+ signatureNode = instantiateSignature(string, context),
212
+ node = signatureNode, ///
213
+ terms = termsFromSignatureNode(signatureNode, context);
214
+
215
+ signature = new Signature(context, string, node, lineIndex, terms);
216
+ }, context);
217
+ }, json, context);
218
+
219
+ return signature;
242
220
  }
243
221
  });
@@ -58,7 +58,7 @@ export default define(class Axiom extends TopLevelAssertion {
58
58
 
59
59
  context.trace(`Verifying the '${axiomString}' axiom...`);
60
60
 
61
- const signatureVerifies = this.verifySignature();
61
+ const signatureVerifies = this.verifySignature(context);
62
62
 
63
63
  if (signatureVerifies) {
64
64
  verifies = await super.verify(context);
@@ -75,16 +75,23 @@ export default define(class Axiom extends TopLevelAssertion {
75
75
  return verifies;
76
76
  }
77
77
 
78
- verifySignature() {
78
+ verifySignature(context) {
79
79
  let signatureVerifies;
80
80
 
81
81
  const satisfiable = this.isSatisfiable();
82
82
 
83
83
  if (satisfiable) {
84
- const context = this.getContext(),
85
- signature = this.getSignature();
84
+ const axiomString = this.getString(); ///
85
+
86
+ context.trace(`Verifying the '${axiomString}' axiom's signature...`);
87
+
88
+ const signature = this.getSignature();
86
89
 
87
90
  signatureVerifies = signature.verify(context);
91
+
92
+ if (signatureVerifies) {
93
+ context.trace(`...verified the '${axiomString}' axiom's signature.`);
94
+ }
88
95
  } else {
89
96
  signatureVerifies = true
90
97
  }
@@ -210,15 +210,6 @@ export default define(class Type extends Element {
210
210
  return superTypeOf;
211
211
  }
212
212
 
213
- isComparableTo(type) {
214
- const equalTo = this.isEqualTo(type),
215
- subTypeOf = this.isSubTypeOf(type),
216
- superTypeOf = this.isSuperTypeOf(type),
217
- comparableTo = (equalTo || subTypeOf || superTypeOf);
218
-
219
- return comparableTo;
220
- }
221
-
222
213
  isEqualToOrSubTypeOf(type) {
223
214
  const equalTo = this.isEqualTo(type),
224
215
  subTypeOf = this.isSubTypeOf(type),
@@ -235,6 +226,15 @@ export default define(class Type extends Element {
235
226
  return equalToOrSuperTypeOf;
236
227
  }
237
228
 
229
+ isEqualToSubTypeOrSuperTypeOf(type) {
230
+ const equalTo = this.isEqualTo(type),
231
+ subTypeOf = this.isSubTypeOf(type),
232
+ superTypeOf = this.isSuperTypeOf(type),
233
+ equalToSubTypeOrSuperTypeOf = (equalTo || subTypeOf || superTypeOf);
234
+
235
+ return equalToSubTypeOrSuperTypeOf;
236
+ }
237
+
238
238
  compareTypeName(typeName) {
239
239
  const nameTypeName = (this.name === typeName),
240
240
  comparesToTypeName = nameTypeName; ///
@@ -259,22 +259,18 @@ export default define(class Type extends Element {
259
259
  compareNominalTypeName(nominalTypeName) {
260
260
  let comparesToNominalTypeName = false;
261
261
 
262
- if (!comparesToNominalTypeName) {
263
- const nominalTypeNameName = (this.name === nominalTypeName);
262
+ const nameNominalTypeName = (this.name === nominalTypeName);
264
263
 
265
- if (nominalTypeNameName) {
266
- comparesToNominalTypeName = true;
267
- }
268
- }
269
-
270
- if (!comparesToNominalTypeName) {
264
+ if (nameNominalTypeName) {
265
+ comparesToNominalTypeName = true;
266
+ } else {
271
267
  const prefixed = this.isPrefixed();
272
268
 
273
269
  if (prefixed) {
274
270
  const prefixedName = this.getPrefixedName(),
275
- nominalTypeNamePrefixedName = (nominalTypeName === prefixedName);
271
+ prefixedNameNominalTypeName = (prefixedName === nominalTypeName);
276
272
 
277
- if (nominalTypeNamePrefixedName) {
273
+ if (prefixedNameNominalTypeName) {
278
274
  comparesToNominalTypeName = true;
279
275
  }
280
276
  }
@@ -11,9 +11,9 @@ export function variableAssignmentFromTermAndType(term, type, context) {
11
11
 
12
12
  if (termSingular) {
13
13
  const termType = term.getType(),
14
- termTypeEqualToType = termType.isEqualTo(type);
14
+ termTypeSuperTypeOfType = termType.isSuperTypeOf(type);
15
15
 
16
- if (!termTypeEqualToType) {
16
+ if (termTypeSuperTypeOfType) {
17
17
  const variableNode = term.getVariableNode(),
18
18
  variable = variableFromVariableNode(variableNode, context);
19
19
 
@@ -1166,7 +1166,7 @@ export function frameFromJudgementNode(judgementNode, context) {
1166
1166
  }
1167
1167
 
1168
1168
  export function termsFromSignatureNode(signatureNode, context) {
1169
- const termNodes = signatureNode.getAssumptionNodes(),
1169
+ const termNodes = signatureNode.getTermNodes(),
1170
1170
  terms = termsFromTermNodes(termNodes, context);
1171
1171
 
1172
1172
  return terms;
@@ -518,11 +518,11 @@ export function referencesFromJSON(json, context) {
518
518
  let { references } = json;
519
519
 
520
520
  const { Reference } = elements,
521
- referencesJSON = references; ///
521
+ referencesJSON = references; ///
522
522
 
523
523
  references = referencesJSON.map((referenceJSON) => {
524
524
  const json = referenceJSON, ///
525
- reference = Reference.fromJSON(json, context);
525
+ reference = Reference.fromJSON(json, context);
526
526
 
527
527
  return reference;
528
528
  });
@@ -530,6 +530,22 @@ export function referencesFromJSON(json, context) {
530
530
  return references;
531
531
  }
532
532
 
533
+ export function signaturesFromJSON(json, context) {
534
+ let { signatures } = json;
535
+
536
+ const { Signature } = elements,
537
+ signaturesJSON = signatures; ///
538
+
539
+ signatures = signaturesJSON.map((signatureJSON) => {
540
+ const json = signatureJSON, ///
541
+ signature = Signature.fromJSON(json, context);
542
+
543
+ return signature;
544
+ });
545
+
546
+ return signatures;
547
+ }
548
+
533
549
  export function conjecturesFromJSON(json, context) {
534
550
  let { conjectures } = json;
535
551
 
@@ -1072,6 +1088,16 @@ export function statementsToStatementsJSON(statements) {
1072
1088
  return statementsJSON;
1073
1089
  }
1074
1090
 
1091
+ export function signaturesToSignaturesJSON(signatures) {
1092
+ const signaturesJSON = signatures.map((signature) => {
1093
+ const signatureJSON = signature.toJSON();
1094
+
1095
+ return signatureJSON;
1096
+ });
1097
+
1098
+ return signaturesJSON;
1099
+ }
1100
+
1075
1101
  export function assertionsToAssertionsJSON(assertions) {
1076
1102
  const assertionsJSON = assertions.map((assertion) => {
1077
1103
  const assertionJSON = assertion.toJSON();
@@ -74,6 +74,16 @@ export function compressStatements(statements) {
74
74
  });
75
75
  }
76
76
 
77
+ export function compressSignatures(signatures) {
78
+ compress(signatures, (signatureA, signatureB) => {
79
+ const signatureAEqualToSignatureB = signatureA.isEqualTo(signatureB);
80
+
81
+ if (!signatureAEqualToSignatureB) {
82
+ return true;
83
+ }
84
+ });
85
+ }
86
+
77
87
  export function compressReferences(references) {
78
88
  compress(references, (referenceA, referenceB) => {
79
89
  const referenceAEqualToReferenceB = referenceA.isEqualTo(referenceB);