occam-nominal 1.0.334 → 1.0.340

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 (75) hide show
  1. package/lib/context.js +5 -1
  2. package/lib/element/assertion/contained.js +4 -4
  3. package/lib/element/assertion/defined.js +3 -3
  4. package/lib/element/assertion/subproof.js +6 -6
  5. package/lib/element/assertion/type.js +3 -3
  6. package/lib/element/assumption.js +134 -111
  7. package/lib/element/combinator/bracketed.js +2 -2
  8. package/lib/element/constraint.js +114 -102
  9. package/lib/element/constructor/bracketed.js +3 -3
  10. package/lib/element/deduction.js +2 -2
  11. package/lib/element/equality.js +3 -3
  12. package/lib/element/frame.js +3 -3
  13. package/lib/element/goal.js +67 -57
  14. package/lib/element/hypothesis.js +2 -2
  15. package/lib/element/judgement.js +15 -16
  16. package/lib/element/label.js +25 -22
  17. package/lib/element/metaType.js +2 -2
  18. package/lib/element/metavariable.js +54 -45
  19. package/lib/element/parameter.js +2 -2
  20. package/lib/element/procedureCall.js +2 -2
  21. package/lib/element/procedureReference.js +2 -2
  22. package/lib/element/proofAssertion/step.js +7 -7
  23. package/lib/element/proofAssertion/supposition.js +2 -2
  24. package/lib/element/proofAssertion.js +2 -2
  25. package/lib/element/reference.js +27 -24
  26. package/lib/element/schema.js +165 -154
  27. package/lib/element/signature.js +2 -2
  28. package/lib/element/statement.js +7 -5
  29. package/lib/element/substitution/reference.js +22 -29
  30. package/lib/element/substitution/statement.js +5 -5
  31. package/lib/element/term.js +2 -2
  32. package/lib/element/typePrefix.js +2 -2
  33. package/lib/element/variable.js +2 -2
  34. package/lib/process/unification.js +41 -47
  35. package/lib/process/unify.js +10 -10
  36. package/lib/process/validate.js +6 -6
  37. package/lib/process/validation.js +13 -13
  38. package/package.json +9 -9
  39. package/src/context.js +6 -0
  40. package/src/element/assertion/contained.js +3 -3
  41. package/src/element/assertion/defined.js +2 -2
  42. package/src/element/assertion/subproof.js +5 -5
  43. package/src/element/assertion/type.js +2 -2
  44. package/src/element/assumption.js +158 -132
  45. package/src/element/combinator/bracketed.js +1 -1
  46. package/src/element/constraint.js +134 -125
  47. package/src/element/constructor/bracketed.js +2 -2
  48. package/src/element/deduction.js +1 -1
  49. package/src/element/equality.js +2 -2
  50. package/src/element/frame.js +2 -2
  51. package/src/element/goal.js +82 -74
  52. package/src/element/hypothesis.js +2 -2
  53. package/src/element/judgement.js +20 -22
  54. package/src/element/label.js +26 -25
  55. package/src/element/metaType.js +2 -2
  56. package/src/element/metavariable.js +70 -53
  57. package/src/element/parameter.js +2 -2
  58. package/src/element/procedureCall.js +2 -2
  59. package/src/element/procedureReference.js +2 -2
  60. package/src/element/proofAssertion/step.js +6 -6
  61. package/src/element/proofAssertion/supposition.js +1 -1
  62. package/src/element/proofAssertion.js +1 -1
  63. package/src/element/reference.js +28 -27
  64. package/src/element/schema.js +193 -195
  65. package/src/element/signature.js +2 -2
  66. package/src/element/statement.js +9 -5
  67. package/src/element/substitution/reference.js +22 -35
  68. package/src/element/substitution/statement.js +4 -4
  69. package/src/element/term.js +1 -1
  70. package/src/element/typePrefix.js +2 -2
  71. package/src/element/variable.js +1 -1
  72. package/src/process/unification.js +44 -59
  73. package/src/process/unify.js +9 -9
  74. package/src/process/validate.js +5 -5
  75. package/src/process/validation.js +12 -12
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
 
3
- import { Element, breakPointUtilities } from "occam-languages";
3
+ import { Element, breakPointUtilities, continuationUtilities } from "occam-languages";
4
4
 
5
5
  import { define } from "../elements";
6
+ import { all, exists } from "../utilities/continuation";
6
7
  import { unifyStatement } from "../process/unify";
7
8
  import { instantiateConstraint } from "../process/instantiate";
8
9
  import { stripBracketsFromStatement } from "../utilities/brackets";
@@ -10,7 +11,8 @@ import { constraintFromConstraintNode } from "../utilities/element";
10
11
  import { constraintStringFromReferenceAndStatement } from "../utilities/string";
11
12
  import { ablate, attempt, descend, reconcile, serialise, unserialise, instantiate } from "../utilities/context";
12
13
 
13
- const { breakPointFromJSON, breakPointToBreakPointJSON } = breakPointUtilities;
14
+ const { some } = continuationUtilities,
15
+ { breakPointFromJSON, breakPointToBreakPointJSON } = breakPointUtilities;
14
16
 
15
17
  export default define(class Constraint extends Element {
16
18
  constructor(context, string, node, breakPoint, reference, statement) {
@@ -61,123 +63,124 @@ export default define(class Constraint extends Element {
61
63
  return validConstraint;
62
64
  }
63
65
 
64
- async validate(context) {
65
- let constraint = null;
66
-
66
+ validate(context, continuation) {
67
67
  const constraintString = this.getString(); ///
68
68
 
69
69
  context.trace(`Validating the '${constraintString}' constraint...`);
70
70
 
71
- let validates = false;
72
-
73
71
  const validConstraint = this.findValidConstraint(context);
74
72
 
75
73
  if (validConstraint !== null) {
76
- validates = true;
77
-
78
- constraint = validConstraint; ///
74
+ const constraint = validConstraint; ///
79
75
 
80
76
  context.debug(`...the '${constraintString}' constraint is already valid.`);
81
- } else {
82
- const temporaryContext = context; ///
83
77
 
78
+ return continuation(constraint);
79
+ } else {
84
80
  context = this.getContext();
85
81
 
86
82
  attempt((context) => {
87
- const statementValidates = this.validateStatement(context);
83
+ const validateStatement = this.validateStatement.bind(this),
84
+ validateReference = this.validateReference.bind(this);
88
85
 
89
- if (statementValidates) {
90
- const referenceValidates = this.validateReference(context);
91
-
92
- if (referenceValidates) {
93
- const stated = context.isStated();
86
+ return all([
87
+ validateStatement,
88
+ validateReference
89
+ ], context, (validates) => {
90
+ if (!validates) {
91
+ const constraint = null;
94
92
 
95
- let validatesWhenStated = false,
96
- validatesWhenDerived = false;
93
+ return continuation(constraint);
94
+ }
97
95
 
98
- if (stated) {
99
- validatesWhenStated = this.validateWhenStated(context);
100
- } else {
101
- validatesWhenDerived = this.validateWhenDerived(context);
102
- }
96
+ const validateWhenStated = this.validateWhenStated.bind(this),
97
+ validateWhenDerived = this.validateWhenDerived.bind(this);
103
98
 
104
- if (validatesWhenStated || validatesWhenDerived) {
105
- validates = true;
106
- }
107
- }
108
- }
99
+ return exists([
100
+ validateWhenStated,
101
+ validateWhenDerived
102
+ ], context, (validates) => {
103
+ let constraint = null;
109
104
 
110
- if (validates) {
111
- this.commit(context);
112
- }
113
- }, context);
105
+ if (validates) {
106
+ constraint = this; ///
114
107
 
115
- context = temporaryContext; ///
108
+ context.addConstraint(constraint);
109
+ }
116
110
 
117
- if (validates) {
118
- constraint = this; ///
111
+ if (validates) {
112
+ this.commit(context);
113
+ }
119
114
 
120
- context.addConstraint(constraint);
121
- }
122
- }
115
+ if (validates) {
116
+ context.debug(`...validated the '${constraintString}' constraint.`);
117
+ }
123
118
 
124
- if (validates) {
125
- context.debug(`...validated the '${constraintString}' constraint.`);
119
+ return continuation(constraint);
120
+ });
121
+ });
122
+ }, context);
126
123
  }
127
-
128
- return constraint;
129
124
  }
130
125
 
131
- validateReference(context) {
126
+ validateReference(context, continuation) {
132
127
  let referenceValidates = false;
133
128
 
134
129
  const constraintString = this.getString(); ///
135
130
 
136
131
  context.trace(`Validating the '${constraintString}' constraint's reference...`);
137
132
 
138
- const reference = this.reference.validate(context);
139
-
140
- if (reference !== null) {
141
- const metavariable = this.reference.getMetavariable(),
142
- metavariableDeclared = metavariable.isDeclared();
133
+ this.reference.validate(context, (reference) => {
134
+ if (reference !== null) {
135
+ const metavariable = this.reference.getMetavariable(),
136
+ metavariableDeclared = metavariable.isDeclared();
143
137
 
144
- if (metavariableDeclared) {
145
- this.reference = reference;
138
+ if (metavariableDeclared) {
139
+ this.reference = reference;
146
140
 
147
- referenceValidates = true;
141
+ referenceValidates = true;
142
+ }
148
143
  }
149
- }
150
144
 
151
- if (referenceValidates) {
152
- context.debug(`...validated the '${constraintString}' constraint's reference.`);
153
- }
145
+ if (referenceValidates) {
146
+ context.debug(`...validated the '${constraintString}' constraint's reference.`);
147
+ }
154
148
 
155
- return referenceValidates;
149
+ return continuation(referenceValidates);
150
+ });
156
151
  }
157
152
 
158
- async validateStatement(context) {
159
- let statementValidates = false;
160
-
153
+ validateStatement(context, continuation) {
161
154
  const constraintString = this.getString(); ///
162
155
 
163
156
  context.trace(`Validating the '${constraintString}' constraint's statement...`);
164
157
 
165
- descend(async (context) => {
166
- const statement = this.statement.validate(context);
158
+ descend((context) => {
159
+ this.statement.validate(context, (statement) => {
160
+ let statementValidates = false;
167
161
 
168
- if (statement !== null) {
169
- statementValidates = true;
170
- }
171
- }, context);
162
+ if (statement !== null) {
163
+ statementValidates = true;
164
+ }
172
165
 
173
- if (statementValidates) {
174
- context.debug(`...validated the '${constraintString}' constraint's statement.`);
175
- }
166
+ if (statementValidates) {
167
+ context.debug(`...validated the '${constraintString}' constraint's statement.`);
168
+ }
176
169
 
177
- return statementValidates;
170
+ return continuation(statementValidates);
171
+ });
172
+ }, context);
178
173
  }
179
174
 
180
- validateWhenStated(context) {
175
+ validateWhenStated(context, continuation) {
176
+ const stated = context.isStated();
177
+
178
+ if (!stated) {
179
+ const validatesWhenStated = false;
180
+
181
+ return continuation(validatesWhenStated);
182
+ }
183
+
181
184
  let validatesWhenStated;
182
185
 
183
186
  const constraintString = this.getString(); ///
@@ -190,10 +193,18 @@ export default define(class Constraint extends Element {
190
193
  context.debug(`...validated the '${constraintString}' stated constraint.`);
191
194
  }
192
195
 
193
- return validatesWhenStated;
196
+ return continuation(validatesWhenStated);
194
197
  }
195
198
 
196
- validateWhenDerived(context) {
199
+ validateWhenDerived(context, continuation) {
200
+ const stated = context.isStated();
201
+
202
+ if (stated) {
203
+ const validatesWhenDerived = false;
204
+
205
+ return continuation(validatesWhenDerived);
206
+ }
207
+
197
208
  let validatesWhenDerived;
198
209
 
199
210
  const constraintString = this.getString(); ///
@@ -206,36 +217,34 @@ export default define(class Constraint extends Element {
206
217
  context.debug(`...validated the '${constraintString}' derived constraint.`);
207
218
  }
208
219
 
209
- return validatesWhenDerived;
220
+ return continuation(validatesWhenDerived);
210
221
  }
211
222
 
212
- unifyReference(reference, generalContext, specificContext) {
213
- let referenceUnifies;
223
+ unifyReference(reference, generalContext, specificContext, continuation) {
224
+ if (reference === null) {
225
+ const referenceUnifies = true; ///
214
226
 
215
- if (reference !== null) {
216
- const context = specificContext, ///
217
- referenceString = reference.getString(),
218
- constraintString = this.getString(); ///
227
+ return continuation(referenceUnifies);
228
+ }
219
229
 
220
- context.trace(`Unifying the '${referenceString}' reference with the '${constraintString}' constraint's reference...`);
230
+ const context = specificContext, ///
231
+ referenceString = reference.getString(),
232
+ constraintString = this.getString(); ///
221
233
 
222
- const metavariable = this.getMetavariable();
234
+ context.trace(`Unifying the '${referenceString}' reference with the '${constraintString}' constraint's reference...`);
223
235
 
224
- referenceUnifies = metavariable.unifyReference(reference, generalContext, specificContext);
236
+ const metavariable = this.getMetavariable();
225
237
 
238
+ return metavariable.unifyReference(reference, generalContext, specificContext, (referenceUnifies) => {
226
239
  if (referenceUnifies) {
227
240
  context.debug(`..unified the '${referenceString}' with the '${constraintString}' constraint's reference.`);
228
241
  }
229
- } else {
230
- referenceUnifies = true; ///
231
- }
232
242
 
233
- return referenceUnifies;
243
+ return continuation(referenceUnifies);
244
+ });
234
245
  }
235
246
 
236
- async unifyStatement(statement, generalContext, specificContext) {
237
- let statementUnifies;
238
-
247
+ unifyStatement(statement, generalContext, specificContext, continuation) {
239
248
  const context = specificContext, ///
240
249
  statementString = statement.getString(),
241
250
  constraintString = this.getString(); ///
@@ -245,18 +254,16 @@ export default define(class Constraint extends Element {
245
254
  const generalStatement = this.statement, ///
246
255
  specificStatement = stripBracketsFromStatement(statement, context); ///
247
256
 
248
- statementUnifies = unifyStatement(generalStatement, specificStatement, generalContext, specificContext);
249
-
250
- if (statementUnifies) {
251
- context.debug(`...unified the '${statementString}' statement with the '${constraintString}' constraint's statement.`);
252
- }
257
+ return unifyStatement(generalStatement, specificStatement, generalContext, specificContext, (statementUnifies) => {
258
+ if (statementUnifies) {
259
+ context.debug(`...unified the '${statementString}' statement with the '${constraintString}' constraint's statement.`);
260
+ }
253
261
 
254
- return statementUnifies;
262
+ return continuation(statementUnifies);
263
+ });
255
264
  }
256
265
 
257
- async unifyAssumption(assumption, context) {
258
- let assumptionUnifies = false;
259
-
266
+ unifyAssumption(assumption, context, continuation) {
260
267
  const assumptionString = assumption.getString(), ///
261
268
  constraintString = this.getString();
262
269
 
@@ -265,40 +272,42 @@ export default define(class Constraint extends Element {
265
272
  const constraintContext = this.getContext(), ///
266
273
  generalContext = constraintContext; ///
267
274
 
268
- reconcile(async (context) => {
275
+ reconcile((context) => {
269
276
  const reference = assumption.getReference(),
270
- specificContext = context, ///
271
- referneceUnifies = this.unifyReference(reference, generalContext, specificContext);
272
-
273
- if (referneceUnifies) {
274
- const statement = assumption.getStatement(),
275
- statementUnified = this.unifyStatement(statement, generalContext, specificContext);
277
+ specificContext = context; ///
276
278
 
277
- if (statementUnified) {
278
- context.commit();
279
+ return this.unifyReference(reference, generalContext, specificContext, (referneceUnifies) => {
280
+ if (!referneceUnifies) {
281
+ const assumptionUnifies = false;
279
282
 
280
- assumptionUnifies = true;
283
+ return continuation(assumptionUnifies);
281
284
  }
282
- }
283
- }, context);
284
285
 
285
- if (assumptionUnifies) {
286
- context.debug(`...unified the '${assumptionString}' assumption with the '${constraintString}' constraint...`);
287
- }
286
+ const statement = assumption.getStatement();
288
287
 
289
- return assumptionUnifies;
290
- }
288
+ return this.unifyStatement(statement, generalContext, specificContext, (statementUnifies) => {
289
+ let assumptionUnifies = false;
291
290
 
292
- unifyAssumptions(assumptions, context) {
293
- const assumptionsUnify = assumptions.some((assumption) => {
294
- const assumptionUnifies = this.unifyAssumption(assumption, context);
291
+ if (statementUnifies) {
292
+ context.commit();
295
293
 
296
- if (assumptionUnifies) {
297
- return true;
298
- }
299
- });
294
+ assumptionUnifies = true;
295
+ }
296
+
297
+ if (assumptionUnifies) {
298
+ context.debug(`...unified the '${assumptionString}' assumption with the '${constraintString}' constraint...`);
299
+ }
300
+
301
+ return continuation(assumptionUnifies);
302
+ });
303
+ });
304
+ }, context);
305
+ }
300
306
 
301
- return assumptionsUnify;
307
+ unifyAssumptions(assumptions, context, continuation) {
308
+ some(assumptions, (assumption, continuation) => {
309
+ this.unifyAssumption(assumption, context, continuation);
310
+ }, continuation);
302
311
  }
303
312
 
304
313
  toJSON() {
@@ -18,7 +18,7 @@ export default define(class BracketedConstructor extends Constructor {
18
18
 
19
19
  context.trace(`Unifying the '${termString}' term with the bracketed constructor...`);
20
20
 
21
- super.unifyTerm(term, context, (termUnifies) => {
21
+ return super.unifyTerm(term, context, (termUnifies) => {
22
22
  if (!termUnifies) {
23
23
  return continuation(termUnifies);
24
24
  }
@@ -36,7 +36,7 @@ export default define(class BracketedConstructor extends Constructor {
36
36
  const bracketlessTermNode = singularTermNode, ///
37
37
  bracketlessTerm = termFromTermNode(bracketlessTermNode, context);
38
38
 
39
- bracketlessTerm.validate(context, (bracketlessTerm, context) => {
39
+ return bracketlessTerm.validate(context, (bracketlessTerm, context) => {
40
40
  if (bracketlessTerm === null) {
41
41
  const termUnifies = false;
42
42
 
@@ -49,7 +49,7 @@ export default define(class Deduction extends Element {
49
49
 
50
50
  declare((context) => {
51
51
  elide((context) => {
52
- this.validate(context, (validates) => {
52
+ return this.validate(context, (validates) => {
53
53
  let verifies = false;
54
54
 
55
55
  if (validates) {
@@ -172,14 +172,14 @@ export default define(class Equality extends Element {
172
172
 
173
173
  context.trace(`Validating the '${equalityString}' equality's terms...`);
174
174
 
175
- this.leftTerm.validate(context, (leftTerm, context) => {
175
+ return this.leftTerm.validate(context, (leftTerm, context) => {
176
176
  if (leftTerm === null) {
177
177
  const termsValidate = false;
178
178
 
179
179
  return continuation(termsValidate);
180
180
  }
181
181
 
182
- this.rightTerm.validate(context, (rightTerm, context) => {
182
+ return this.rightTerm.validate(context, (rightTerm, context) => {
183
183
  if (rightTerm === null) {
184
184
  const termsValidate = false;
185
185
 
@@ -197,7 +197,7 @@ export default define(class Frame extends Element {
197
197
 
198
198
  context.trace(`Validating the '${frameString}' frame's '${assumptionString}' assumption.`);
199
199
 
200
- assumption.validate(context, (assumption) => {
200
+ return assumption.validate(context, (assumption) => {
201
201
  let assumptionValidates = false;
202
202
 
203
203
  if (assumption !== null) {
@@ -253,7 +253,7 @@ export default define(class Frame extends Element {
253
253
 
254
254
  context.trace(`Validating the '${frameString}' frame's metavariable...`);
255
255
 
256
- this.metavariable.validate(context, (metavariable) => {
256
+ return this.metavariable.validate(context, (metavariable) => {
257
257
  let metavariableValidates = false;
258
258
 
259
259
  if (metavariable !== null) {