occam-verify-cli 1.0.768 → 1.0.781

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 (108) hide show
  1. package/lib/context/file/nominal.js +11 -11
  2. package/lib/context/illative.js +28 -0
  3. package/lib/context/nested.js +31 -0
  4. package/lib/context/proof.js +242 -0
  5. package/lib/context/thetic.js +28 -0
  6. package/lib/context.js +19 -21
  7. package/lib/element/assertion/contained.js +32 -24
  8. package/lib/element/assertion/defined.js +47 -40
  9. package/lib/element/assertion/property.js +18 -13
  10. package/lib/element/assertion/satisfies.js +12 -9
  11. package/lib/element/assertion/subproof.js +28 -26
  12. package/lib/element/assertion/type.js +14 -12
  13. package/lib/element/assumption.js +40 -50
  14. package/lib/element/combinator/bracketed.js +3 -3
  15. package/lib/element/combinator.js +20 -20
  16. package/lib/element/conclusion.js +33 -29
  17. package/lib/element/constructor.js +19 -18
  18. package/lib/element/deduction.js +33 -29
  19. package/lib/element/equality.js +13 -15
  20. package/lib/element/equivalence.js +59 -52
  21. package/lib/element/equivalences.js +4 -2
  22. package/lib/element/frame.js +74 -53
  23. package/lib/element/hypothesis.js +7 -5
  24. package/lib/element/judgement.js +41 -74
  25. package/lib/element/label.js +22 -22
  26. package/lib/element/metavariable.js +31 -11
  27. package/lib/element/proofAssertion/premise.js +48 -35
  28. package/lib/element/proofAssertion/step.js +77 -22
  29. package/lib/element/proofAssertion/supposition.js +48 -34
  30. package/lib/element/proofAssertion.js +1 -14
  31. package/lib/element/reference.js +80 -53
  32. package/lib/element/signature.js +44 -3
  33. package/lib/element/statement.js +28 -29
  34. package/lib/element/subproof.js +2 -2
  35. package/lib/element/substitution/frame.js +24 -19
  36. package/lib/element/substitution/metaLevel.js +31 -27
  37. package/lib/element/substitution/reference.js +11 -10
  38. package/lib/element/substitution/statement.js +30 -23
  39. package/lib/element/substitution/term.js +11 -10
  40. package/lib/element/term.js +24 -20
  41. package/lib/element/topLevelMetaAssertion.js +2 -2
  42. package/lib/element/variable.js +6 -2
  43. package/lib/process/assign.js +10 -4
  44. package/lib/process/unify.js +8 -8
  45. package/lib/process/validate.js +10 -8
  46. package/lib/utilities/context.js +68 -23
  47. package/lib/utilities/element.js +55 -27
  48. package/lib/utilities/json.js +8 -8
  49. package/lib/utilities/string.js +12 -1
  50. package/lib/utilities/unification.js +14 -12
  51. package/lib/utilities/validation.js +55 -40
  52. package/package.json +4 -4
  53. package/src/context/file/nominal.js +14 -16
  54. package/src/context/illative.js +17 -0
  55. package/src/context/nested.js +21 -0
  56. package/src/context/{scoped.js → proof.js} +65 -51
  57. package/src/context/thetic.js +17 -0
  58. package/src/context.js +30 -36
  59. package/src/element/assertion/contained.js +44 -31
  60. package/src/element/assertion/defined.js +55 -46
  61. package/src/element/assertion/property.js +23 -15
  62. package/src/element/assertion/satisfies.js +15 -10
  63. package/src/element/assertion/subproof.js +34 -31
  64. package/src/element/assertion/type.js +18 -13
  65. package/src/element/assumption.js +40 -69
  66. package/src/element/combinator/bracketed.js +2 -2
  67. package/src/element/combinator.js +23 -29
  68. package/src/element/conclusion.js +37 -40
  69. package/src/element/constructor.js +29 -34
  70. package/src/element/deduction.js +36 -39
  71. package/src/element/equality.js +16 -18
  72. package/src/element/equivalence.js +76 -67
  73. package/src/element/equivalences.js +5 -2
  74. package/src/element/frame.js +96 -65
  75. package/src/element/hypothesis.js +7 -6
  76. package/src/element/judgement.js +45 -45
  77. package/src/element/label.js +25 -31
  78. package/src/element/metavariable.js +48 -21
  79. package/src/element/proofAssertion/premise.js +63 -49
  80. package/src/element/proofAssertion/step.js +47 -26
  81. package/src/element/proofAssertion/supposition.js +64 -50
  82. package/src/element/proofAssertion.js +0 -22
  83. package/src/element/reference.js +119 -80
  84. package/src/element/signature.js +5 -2
  85. package/src/element/statement.js +30 -35
  86. package/src/element/subproof.js +1 -1
  87. package/src/element/substitution/frame.js +27 -26
  88. package/src/element/substitution/metaLevel.js +38 -42
  89. package/src/element/substitution/reference.js +13 -14
  90. package/src/element/substitution/statement.js +35 -33
  91. package/src/element/substitution/term.js +13 -14
  92. package/src/element/term.js +42 -34
  93. package/src/element/topLevelMetaAssertion.js +1 -1
  94. package/src/element/variable.js +8 -1
  95. package/src/process/assign.js +9 -3
  96. package/src/process/unify.js +7 -7
  97. package/src/process/validate.js +9 -8
  98. package/src/utilities/context.js +82 -31
  99. package/src/utilities/element.js +68 -31
  100. package/src/utilities/json.js +13 -13
  101. package/src/utilities/string.js +16 -2
  102. package/src/utilities/unification.js +18 -16
  103. package/src/utilities/validation.js +73 -53
  104. package/lib/context/scoped.js +0 -232
  105. package/lib/utilities/statement.js +0 -78
  106. package/lib/utilities/term.js +0 -17
  107. package/src/utilities/statement.js +0 -74
  108. package/src/utilities/term.js +0 -10
@@ -3,8 +3,8 @@
3
3
  import { Element } from "occam-languages";
4
4
 
5
5
  import { define } from "../elements";
6
+ import { descend, instantiate } from "../utilities/context";
6
7
  import { instantiateAssumption } from "../process/instantiate";
7
- import { instantiate, reconcile } from "../utilities/context";
8
8
 
9
9
  export default define(class Assumption extends Element {
10
10
  constructor(context, string, node, reference, statement) {
@@ -31,6 +31,8 @@ export default define(class Assumption extends Element {
31
31
 
32
32
  getMetavariable() { return this.reference.getMetavariable(); }
33
33
 
34
+ getTopLevelMetaAssertion() { return this.reference.getTopLevelMetaAssertion(); }
35
+
34
36
  matchAssumptionNode(assumptionNode) {
35
37
  const node = assumptionNode, ///
36
38
  nodeMatches = this.matchNode(node),
@@ -39,28 +41,21 @@ export default define(class Assumption extends Element {
39
41
  return assumptionNodeMatches;
40
42
  }
41
43
 
42
- compareSubstitution(substitution, context) {
43
- let comparesToSubstituion = false;
44
+ compareMetaLevelSubstitution(metaLevelSubstitution, context) {
45
+ let comparesToMetaLevelSubstitution = false;
44
46
 
45
47
  const assumptionString = this.getString(), ///
46
- substitutionString = substitution.getString();
47
-
48
- context.trace(`Comparing the '${assumptionString}' assumption to the '${substitutionString}' substitution...`);
48
+ metaLevelSubstitutionString = metaLevelSubstitution.getString();
49
49
 
50
- const statement = substitution.getStatement(),
51
- metavariableName = substitution.getMetavariableName(),
52
- statementEqualToStatement = this.statement.isEqualTo(statement),
53
- referenceMetavariableComparesToMetavariable = this.reference.compareMetavariableName(metavariableName);
50
+ context.trace(`Comparing the '${assumptionString}' assumption to the '${metaLevelSubstitutionString}' meta-level substitution...`);
54
51
 
55
- if (statementEqualToStatement && referenceMetavariableComparesToMetavariable) {
56
- comparesToSubstituion = true;
57
- }
52
+ debugger
58
53
 
59
- if (comparesToSubstituion) {
60
- context.debug(`...compared the '${substitutionString}' assumption to the '${assumptionString}' substitution.`);
54
+ if (comparesToMetaLevelSubstitution) {
55
+ context.debug(`...compared the '${assumptionString}' assumption to the '${metaLevelSubstitutionString}' meta-level substitution.`);
61
56
  }
62
57
 
63
- return comparesToSubstituion;
58
+ return comparesToMetaLevelSubstitution;
64
59
  }
65
60
 
66
61
  findValidAssumption(context) {
@@ -71,7 +66,7 @@ export default define(class Assumption extends Element {
71
66
  return validAssumption;
72
67
  }
73
68
 
74
- validate(stated, context) {
69
+ validate(context) {
75
70
  let assumption = null;
76
71
 
77
72
  const assumptionString = this.getString(); ///
@@ -87,12 +82,14 @@ export default define(class Assumption extends Element {
87
82
  } else {
88
83
  let validates = false;
89
84
 
90
- const statementValidates = this.validateStatement(stated, context);
85
+ const statementValidates = this.validateStatement(context);
91
86
 
92
87
  if (statementValidates) {
93
- const referenceValidates = this.validateReference(stated, context);
88
+ const referenceValidates = this.validateReference(context);
94
89
 
95
90
  if (referenceValidates) {
91
+ const stated = context.isStated();
92
+
96
93
  let validatesWhenStated = false,
97
94
  validatesWhenDerived = false;
98
95
 
@@ -120,11 +117,11 @@ export default define(class Assumption extends Element {
120
117
  return assumption;
121
118
  }
122
119
 
123
- validateReference(stated, context) {
120
+ validateReference(context) {
124
121
  let referenceValidates = false;
125
122
 
126
- const assumptionString = this.getString(), ///
127
- referenceString = this.reference.getString();
123
+ const referenceString = this.reference.getString(),
124
+ assumptionString = this.getString(); ///
128
125
 
129
126
  context.trace(`Validating the '${assumptionString}' assumption's '${referenceString}' reference...`);
130
127
 
@@ -137,7 +134,7 @@ export default define(class Assumption extends Element {
137
134
  if (metavariablePresent) {
138
135
  referenceValidates = true;
139
136
  } else {
140
- const topLevelMetaAssertions = context.findTopLevelMetaAssertionsByReference(this.reference, context),
137
+ const topLevelMetaAssertions = context.findTopLevelMetaAssertionsByReference(this.reference),
141
138
  topLevelMetaAssertionsCompare = topLevelMetaAssertions.some((topLevelMetaAssertion) => {
142
139
  const topLevelMetaAssertionUnifies = this.unifyTopLevelMetaAssertion(topLevelMetaAssertion, context);
143
140
 
@@ -153,13 +150,13 @@ export default define(class Assumption extends Element {
153
150
  }
154
151
 
155
152
  if (referenceValidates) {
156
- context.debug(`...validated the '${assumptionString}' assumption's '${referenceString}' statement.`);
153
+ context.debug(`...validated the '${assumptionString}' assumption's '${referenceString}' reference.`);
157
154
  }
158
155
 
159
156
  return referenceValidates;
160
157
  }
161
158
 
162
- validateStatement(stated, context) {
159
+ validateStatement(context) {
163
160
  let statementValidates = false;
164
161
 
165
162
  const assumptionString = this.getString(), ///
@@ -167,13 +164,13 @@ export default define(class Assumption extends Element {
167
164
 
168
165
  context.trace(`Validating the '${assumptionString}' assumption's '${statementString}' statement...`);
169
166
 
170
- stated = true; ///
171
-
172
- const statement = this.statement.validate(stated, context);
167
+ descend((context) => {
168
+ const statement = this.statement.validate(context);
173
169
 
174
- if (statement !== null) {
175
- statementValidates = true;
176
- }
170
+ if (statement !== null) {
171
+ statementValidates = true;
172
+ }
173
+ }, context);
177
174
 
178
175
  if (statementValidates) {
179
176
  context.debug(`...validated the '${assumptionString}' assumption's '${statementString}' statement.`);
@@ -199,13 +196,18 @@ export default define(class Assumption extends Element {
199
196
  }
200
197
 
201
198
  validateWhenDerived(context) {
202
- let validatesWhenDerived;
199
+ let validatesWhenDerived = false;
203
200
 
204
201
  const assumptionString = this.getString(); ///
205
202
 
206
203
  context.trace(`Validating the '${assumptionString}' derived assumption...`);
204
+ const topLevelMetaAssertion = this.getTopLevelMetaAssertion();
207
205
 
208
- validatesWhenDerived = true;
206
+ if (topLevelMetaAssertion !== null) {
207
+ validatesWhenDerived = true;
208
+ } else {
209
+ context.debug(`The '${assumptionString}' asumption did not unify a top level meta-assumption.`);
210
+ }
209
211
 
210
212
  if (validatesWhenDerived) {
211
213
  context.debug(`...validated the '${assumptionString}' derived assumption.`);
@@ -214,50 +216,19 @@ export default define(class Assumption extends Element {
214
216
  return validatesWhenDerived;
215
217
  }
216
218
 
217
- unifyLabel(label, generalContext, specificContext) {
218
- let labelUnifiesWithReference;
219
-
220
- const context = generalContext, ///
221
- labelString = label.getString(),
222
- assumptionString = this.getString(); //;/
223
-
224
- context.trace(`Unifying the '${labelString}' label with the '${assumptionString}' assumption...`);
225
-
226
- const labelUnifies = this.reference.unifyLabel(label, context);
227
-
228
- labelUnifiesWithReference = labelUnifies; ///
229
-
230
- if (labelUnifiesWithReference) {
231
- context.debug(`...unified the '${labelString}' label with the '${assumptionString}' assumption.`);
232
- }
233
-
234
- return labelUnifiesWithReference;
235
- }
236
-
237
219
  unifyTopLevelMetaAssertion(topLevelMetaAssertion, context) {
238
- let topLevelMetaAssertionUnifies = false;
220
+ let topLevelMetaAssertionUnifies;
239
221
 
240
222
  const assumptionString = this.getString(), ///
241
223
  topLevelMetaAssertionString = topLevelMetaAssertion.getString();
242
224
 
243
225
  context.trace(`Unifying the '${topLevelMetaAssertionString}' top level meta-assertion with the '${assumptionString}' assumption...`);
244
226
 
245
- const generalContext = context; ///
246
-
247
- context = topLevelMetaAssertion.getContext(); ///
227
+ topLevelMetaAssertionUnifies = this.reference.unifyTopLevelMetaAssertion(topLevelMetaAssertion, context);
248
228
 
249
- const specificContext = context; ///
250
-
251
- reconcile((specificContext) => {
252
- const label = topLevelMetaAssertion.getLabel(),
253
- labelUnifies = this.unifyLabel(label, generalContext, specificContext);
254
-
255
- if (labelUnifies) {
256
- topLevelMetaAssertionUnifies = this.statement.unifyTopLevelMetaAssertion(topLevelMetaAssertion, generalContext, specificContext);
257
-
258
- specificContext.commit(context);
259
- }
260
- }, specificContext);
229
+ if (topLevelMetaAssertionUnifies) {
230
+ topLevelMetaAssertionUnifies = this.statement.unifyTopLevelMetaAssertion(topLevelMetaAssertion, context);
231
+ }
261
232
 
262
233
  if (topLevelMetaAssertionUnifies) {
263
234
  context.trace(`...unified the '${topLevelMetaAssertionString}' top level meta-assertion with the '${assumptionString}' assumption...`);
@@ -12,14 +12,14 @@ export default define(class BracketedCombinator extends Combinator {
12
12
  return bracketedCombinatorNode;
13
13
  }
14
14
 
15
- unifyStatement(statement, stated, context) {
15
+ unifyStatement(statement, context) {
16
16
  let statementUnifies;
17
17
 
18
18
  const statementString = statement.getString();
19
19
 
20
20
  context.trace(`Unifying the '${statementString}' statement with the bracketed combinator...`);
21
21
 
22
- statementUnifies = super.unifyStatement(statement, stated, context);
22
+ statementUnifies = super.unifyStatement(statement, context);
23
23
 
24
24
  if (statementUnifies) {
25
25
  context.debug(`...unified the '${statementString}' statement with the bracketed combinator.`);
@@ -3,12 +3,11 @@
3
3
  import { Element } from "occam-languages";
4
4
 
5
5
  import { define } from "../elements";
6
- import { attempt, instantiate } from "../utilities/context";
7
6
  import { instantiateCombinator } from "../process/instantiate";
8
7
  import { statementFromCombinatorNode } from "../utilities/element";
9
8
  import { unifyStatementWithCombinator } from "../process/unify";
10
9
  import { validateStatementAsCombinator } from "../process/validate";
11
- import { ephemeralContextFromJSON, ephemeralContextToEphemeralContextJSON } from "../utilities/json";
10
+ import { attempt, serialise, unserialise, instantiate } from "../utilities/context";
12
11
 
13
12
  export default define(class Combinator extends Element {
14
13
  constructor(context, string, node, statement) {
@@ -73,7 +72,7 @@ export default define(class Combinator extends Element {
73
72
  return statementValidates;
74
73
  }
75
74
 
76
- unifyStatement(statement, stated, context) {
75
+ unifyStatement(statement, context) {
77
76
  let statementUnifies;
78
77
 
79
78
  const statementString = statement.getString(),
@@ -90,7 +89,7 @@ export default define(class Combinator extends Element {
90
89
  context = specifiContext; ///
91
90
 
92
91
  const combinator = this, ///
93
- statementUnifiesWithCombinator = unifyStatementWithCombinator(statement, combinator, stated, generalContext, specifiContext);
92
+ statementUnifiesWithCombinator = unifyStatementWithCombinator(statement, combinator, generalContext, specifiContext);
94
93
 
95
94
  statementUnifies = statementUnifiesWithCombinator; ///
96
95
 
@@ -102,40 +101,35 @@ export default define(class Combinator extends Element {
102
101
  }
103
102
 
104
103
  toJSON() {
105
- let context;
104
+ const context = this.getContext();
106
105
 
107
- context = this.getContext();
108
-
109
- const ephemeralContext = context, ///
110
- ephemeralContextJSON = ephemeralContextToEphemeralContextJSON(ephemeralContext),
111
- contextJSON = ephemeralContextJSON; ///
112
-
113
- context = contextJSON; ///
106
+ return serialise((context) => {
107
+ const string = this.getString(),
108
+ json = {
109
+ context,
110
+ string
111
+ };
114
112
 
115
- const string = this.getString(),
116
- json = {
117
- context,
118
- string
119
- };
120
-
121
- return json;
113
+ return json;
114
+ }, context);
122
115
  }
123
116
 
124
117
  static name = "Combinator";
125
118
 
126
119
  static fromJSON(json, context) {
127
- const ephemeralContext = ephemeralContextFromJSON(json, context);
120
+ let combinator;
128
121
 
129
- context = ephemeralContext; ///
122
+ unserialise((json, context) => {
123
+ instantiate((context) => {
124
+ const { string } = json,
125
+ combinatorNode = instantiateCombinator(string, context),
126
+ node = combinatorNode, ///
127
+ statement = statementFromCombinatorNode(combinatorNode, context);
130
128
 
131
- return instantiate((context) => {
132
- const { string } = json,
133
- combinatorNode = instantiateCombinator(string, context),
134
- node = combinatorNode, ///
135
- statement = statementFromCombinatorNode(combinatorNode, context),
136
- combinator = new Combinator(context, string, node, statement);
129
+ combinator = new Combinator(context, string, node, statement);
130
+ }, context);
131
+ }, json, context);
137
132
 
138
- return combinator;
139
- }, context);
133
+ return combinator;
140
134
  }
141
135
  });
@@ -3,11 +3,10 @@
3
3
  import { Element } from "occam-languages";
4
4
 
5
5
  import { define } from "../elements";
6
- import { attempt, instantiate } from "../utilities/context";
7
6
  import { instantiateConclusion } from "../process/instantiate";
8
- import { ephemeralContextFromJSON, ephemeralContextToEphemeralContextJSON } from "../utilities/json";
7
+ import { declare, attempt, descend, serialise, unserialise, instantiate } from "../utilities/context";
9
8
 
10
- export default define(class Conclusion extends Element {
9
+ export default define(class Conclusion extends Element {
11
10
  constructor(context, string, node, statement) {
12
11
  super(context, string, node);
13
12
 
@@ -58,14 +57,16 @@ export default define(class Conclusion extends Element {
58
57
 
59
58
  context.trace(`Validating the '${conclusionString}' conclusion...`);
60
59
 
61
- attempt((context) => {
62
- const statementValidates = this.validateStatement(context);
60
+ declare((context) => {
61
+ attempt((context) => {
62
+ const statementValidates = this.validateStatement(context);
63
63
 
64
- if (statementValidates) {
65
- context.commit(this);
64
+ if (statementValidates) {
65
+ context.commit(this);
66
66
 
67
- validates = true;
68
- }
67
+ validates = true;
68
+ }
69
+ }, context);
69
70
  }, context);
70
71
 
71
72
  if (validates) {
@@ -76,19 +77,20 @@ export default define(class Conclusion extends Element {
76
77
  }
77
78
 
78
79
  validateStatement(context) {
79
- let statementValidates;
80
+ let statementValidates = false;
80
81
 
81
82
  const statementString = this.statement.getString(),
82
83
  conclusionString = this.getString(); ///
83
84
 
84
85
  context.trace(`Validating the '${conclusionString}' conclusion's '${statementString}' statement...`);
85
86
 
86
- const stated = true,
87
- statement = this.statement.validate(stated, context);
87
+ descend((context) => {
88
+ const statement = this.statement.validate(context);
88
89
 
89
- if (statement !== null) {
90
- statementValidates = true;
91
- }
90
+ if (statement !== null) {
91
+ statementValidates = true;
92
+ }
93
+ }, context);
92
94
 
93
95
  if (statementValidates) {
94
96
  context.trace(`...validated the '${conclusionString}' conclusion's '${statementString}' statement.`);
@@ -123,41 +125,36 @@ export default define(class Conclusion extends Element {
123
125
  }
124
126
 
125
127
  toJSON() {
126
- let context;
127
-
128
- context = this.getContext();
129
-
130
- const ephemeralContext = context, ///
131
- ephemeralContextJSON = ephemeralContextToEphemeralContextJSON(ephemeralContext),
132
- contextJSON = ephemeralContextJSON; ///
133
-
134
- context = contextJSON; ///
128
+ const context = this.getContext();
135
129
 
136
- const string = this.getString(),
137
- json = {
138
- context,
139
- string
140
- };
130
+ return serialise((context) => {
131
+ const string = this.getString(),
132
+ json = {
133
+ context,
134
+ string
135
+ };
141
136
 
142
- return json;
137
+ return json;
138
+ }, context);
143
139
  }
144
140
 
145
141
  static name = "Conclusion";
146
142
 
147
143
  static fromJSON(json, context) {
148
- const ephemeralContext = ephemeralContextFromJSON(json, context);
144
+ let conclusion;
149
145
 
150
- context = ephemeralContext; ///
146
+ unserialise((json, context) => {
147
+ instantiate((context) => {
148
+ const { string } = json,
149
+ conclusionNode = instantiateConclusion(string, context),
150
+ node = conclusionNode, ///
151
+ statement = statementFromConclusionNode(conclusionNode, context);
151
152
 
152
- return instantiate((context) => {
153
- const { string } = json,
154
- conclusionNode = instantiateConclusion(string, context),
155
- node = conclusionNode, ///
156
- statement = statementFromConclusionNode(conclusionNode, context),
157
- conclusion = new Conclusion(context, string, node, statement);
153
+ conclusion = new Conclusion(context, string, node, statement);
154
+ }, context);
155
+ }, json, context);
158
156
 
159
- return conclusion;
160
- }, context);
157
+ return conclusion;
161
158
  }
162
159
  });
163
160
 
@@ -3,12 +3,12 @@
3
3
  import { Element } from "occam-languages";
4
4
 
5
5
  import { define } from "../elements";
6
- import { attempt, instantiate } from "../utilities/context";
7
6
  import { instantiateConstructor } from "../process/instantiate";
8
7
  import { termFromConstructorNode } from "../utilities/element";
9
8
  import { unifyTermWithConstructor } from "../process/unify";
10
9
  import { validateTermAsConstructor } from "../process/validate";
11
- import { typeFromJSON, typeToTypeJSON, ephemeralContextFromJSON, ephemeralContextToEphemeralContextJSON } from "../utilities/json";
10
+ import { typeFromJSON, typeToTypeJSON } from "../utilities/json";
11
+ import { attempt, serialise, unserialise, instantiate } from "../utilities/context";
12
12
 
13
13
  export default define(class Constructor extends Element {
14
14
  constructor(context, string, node, term, type) {
@@ -143,45 +143,40 @@ export default define(class Constructor extends Element {
143
143
  }
144
144
 
145
145
  toJSON() {
146
- let context;
147
-
148
- context = this.getContext();
149
-
150
- const ephemeralContext = context, ///
151
- ephemeralContextJSON = ephemeralContextToEphemeralContextJSON(ephemeralContext),
152
- contextJSON = ephemeralContextJSON; ///
153
-
154
- context = contextJSON; ///
155
-
156
- const includeType = false,
157
- typeJSON = typeToTypeJSON(this.type),
158
- string = this.getString(includeType),
159
- type = typeJSON, ///
160
- json = {
161
- context,
162
- string,
163
- type
164
- };
165
-
166
- return json;
146
+ const context = this.getContext();
147
+
148
+ return serialise((context) => {
149
+ const includeType = false,
150
+ typeJSON = typeToTypeJSON(this.type),
151
+ string = this.getString(includeType),
152
+ type = typeJSON, ///
153
+ json = {
154
+ context,
155
+ string,
156
+ type
157
+ };
158
+
159
+ return json;
160
+ }, context);
167
161
  }
168
162
 
169
163
  static name = "Constructor";
170
164
 
171
165
  static fromJSON(json, context) {
172
- const ephemeralContext = ephemeralContextFromJSON(json, context);
166
+ let constructor;
173
167
 
174
- context = ephemeralContext; ///
168
+ unserialise((json, context) => {
169
+ instantiate((context) => {
170
+ const { string } = json,
171
+ constructorNode = instantiateConstructor(string, context),
172
+ node = constructorNode, ///
173
+ term = termFromConstructorNode(constructorNode, context),
174
+ type = typeFromJSON(json, context);
175
175
 
176
- return instantiate((context) => {
177
- const { string } = json,
178
- constructorNode = instantiateConstructor(string, context),
179
- node = constructorNode, ///
180
- term = termFromConstructorNode(constructorNode, context),
181
- type = typeFromJSON(json, context),
182
- constructor = new Constructor(context, string, node, term, type);
176
+ constructor = new Constructor(context, string, node, term, type);
177
+ }, context);
178
+ }, json, context);
183
179
 
184
- return constructor;
185
- }, context);
180
+ return constructor;
186
181
  }
187
182
  });
@@ -3,9 +3,8 @@
3
3
  import { Element } from "occam-languages";
4
4
 
5
5
  import { define } from "../elements";
6
- import { attempt, instantiate } from "../utilities/context";
7
6
  import { instantiateDeduction } from "../process/instantiate";
8
- import { ephemeralContextFromJSON, ephemeralContextToEphemeralContextJSON } from "../utilities/json";
7
+ import { declare, attempt, descend, serialise, unserialise, instantiate } from "../utilities/context";
9
8
 
10
9
  export default define(class Deduction extends Element {
11
10
  constructor(context, string, node, statement) {
@@ -58,14 +57,16 @@ export default define(class Deduction extends Element {
58
57
 
59
58
  context.trace(`Validating the '${deductionString}' deduction...`);
60
59
 
61
- attempt((context) => {
62
- const statementValidates = this.validateStatement(context);
60
+ declare((context) => {
61
+ attempt((context) => {
62
+ const statementValidates = this.validateStatement(context);
63
63
 
64
- if (statementValidates) {
65
- context.commit(this);
64
+ if (statementValidates) {
65
+ context.commit(this);
66
66
 
67
- validates = true;
68
- }
67
+ validates = true;
68
+ }
69
+ }, context);
69
70
  }, context);
70
71
 
71
72
  if (validates) {
@@ -76,19 +77,20 @@ export default define(class Deduction extends Element {
76
77
  }
77
78
 
78
79
  validateStatement(context) {
79
- let statementValidates;
80
+ let statementValidates = false;
80
81
 
81
82
  const statementString = this.statement.getString(),
82
83
  deductionnString = this.getString(); ///
83
84
 
84
85
  context.trace(`Validating the '${deductionnString}' deductionn's '${statementString}' statement...`);
85
86
 
86
- const stated = true,
87
- statement = this.statement.validate(stated, context);
87
+ descend((context) => {
88
+ const statement = this.statement.validate(context);
88
89
 
89
- if (statement !== null) {
90
- statementValidates = true;
91
- }
90
+ if (statement !== null) {
91
+ statementValidates = true;
92
+ }
93
+ }, context);
92
94
 
93
95
  if (statementValidates) {
94
96
  context.trace(`...validated the '${deductionnString}' deductionn's '${statementString}' statement.`);
@@ -148,41 +150,36 @@ export default define(class Deduction extends Element {
148
150
  }
149
151
 
150
152
  toJSON() {
151
- let context;
152
-
153
- context = this.getContext();
154
-
155
- const ephemeralContext = context, ///
156
- ephemeralContextJSON = ephemeralContextToEphemeralContextJSON(ephemeralContext),
157
- contextJSON = ephemeralContextJSON; ///
158
-
159
- context = contextJSON; ///
153
+ const context = this.getContext();
160
154
 
161
- const string = this.getString(),
162
- json = {
163
- context,
164
- string
165
- };
155
+ return serialise((context) => {
156
+ const string = this.getString(),
157
+ json = {
158
+ context,
159
+ string
160
+ };
166
161
 
167
- return json;
162
+ return json;
163
+ }, context);
168
164
  }
169
165
 
170
166
  static name = "Deduction";
171
167
 
172
168
  static fromJSON(json, context) {
173
- const ephemeralContext = ephemeralContextFromJSON(json, context);
169
+ let deduction;
174
170
 
175
- context = ephemeralContext; ///
171
+ unserialise((json, context) => {
172
+ instantiate((context) => {
173
+ const { string } = json,
174
+ deductionNode = instantiateDeduction(string, context),
175
+ node = deductionNode, ///
176
+ statement = statementFromDeductionNode(deductionNode, context);
176
177
 
177
- return instantiate((context) => {
178
- const { string } = json,
179
- deductionNode = instantiateDeduction(string, context),
180
- node = deductionNode, ///
181
- statement = statementFromDeductionNode(deductionNode, context),
182
- deduction = new Deduction(context, string, node, statement);
178
+ deduction = new Deduction(context, string, node, statement);
179
+ }, context);
180
+ }, json, context);
183
181
 
184
- return deduction;
185
- }, context);
182
+ return deduction;
186
183
  }
187
184
  });
188
185