occam-verify-cli 1.0.787 → 1.0.796
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.
- package/lib/context/ephemeral.js +3 -8
- package/lib/context/file/nominal.js +5 -1
- package/lib/context/liminal.js +39 -16
- package/lib/context/proof.js +35 -40
- package/lib/context.js +15 -3
- package/lib/element/assumption/metaLevel.js +181 -0
- package/lib/element/assumption.js +21 -42
- package/lib/element/judgement.js +11 -13
- package/lib/element/metavariable.js +28 -25
- package/lib/element/parameter.js +5 -5
- package/lib/element/procedureCall.js +2 -2
- package/lib/element/proofAssertion/step.js +2 -2
- package/lib/element/reference.js +41 -30
- package/lib/element/substitution/frame.js +23 -18
- package/lib/element/substitution/reference.js +44 -22
- package/lib/element/substitution/statement.js +41 -16
- package/lib/element/substitution/term.js +22 -17
- package/lib/element/substitution.js +4 -4
- package/lib/element/topLevelMetaAssertion.js +9 -9
- package/lib/node/assumption/metaLevel.js +27 -0
- package/lib/node/assumption.js +5 -5
- package/lib/nonTerminalNodeMap.js +3 -1
- package/lib/preamble.js +2 -1
- package/lib/process/instantiate.js +8 -2
- package/lib/process/unify.js +15 -28
- package/lib/ruleNames.js +5 -1
- package/lib/utilities/context.js +9 -5
- package/lib/utilities/element.js +33 -18
- package/lib/utilities/json.js +33 -3
- package/lib/utilities/string.js +25 -14
- package/lib/utilities/unification.js +3 -3
- package/lib/utilities/validation.js +9 -14
- package/package.json +4 -4
- package/src/context/ephemeral.js +2 -10
- package/src/context/file/nominal.js +6 -0
- package/src/context/liminal.js +54 -16
- package/src/context/proof.js +41 -47
- package/src/context.js +22 -2
- package/src/element/assumption/metaLevel.js +263 -0
- package/src/element/assumption.js +31 -61
- package/src/element/judgement.js +13 -21
- package/src/element/metavariable.js +29 -28
- package/src/element/parameter.js +4 -4
- package/src/element/procedureCall.js +1 -1
- package/src/element/proofAssertion/step.js +1 -1
- package/src/element/reference.js +53 -36
- package/src/element/substitution/frame.js +25 -18
- package/src/element/substitution/reference.js +61 -25
- package/src/element/substitution/statement.js +57 -18
- package/src/element/substitution/term.js +25 -18
- package/src/element/substitution.js +3 -4
- package/src/element/topLevelMetaAssertion.js +15 -15
- package/src/node/assumption/metaLevel.js +23 -0
- package/src/node/assumption.js +8 -8
- package/src/nonTerminalNodeMap.js +3 -0
- package/src/preamble.js +1 -0
- package/src/process/instantiate.js +4 -0
- package/src/process/unify.js +18 -39
- package/src/ruleNames.js +1 -0
- package/src/utilities/context.js +10 -4
- package/src/utilities/element.js +44 -25
- package/src/utilities/json.js +40 -5
- package/src/utilities/string.js +34 -19
- package/src/utilities/unification.js +3 -3
- package/src/utilities/validation.js +10 -16
package/src/element/parameter.js
CHANGED
|
@@ -30,20 +30,20 @@ export default define(class Parameter extends Element {
|
|
|
30
30
|
return parameterNode;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
findPrimitive(substitutions) {
|
|
33
|
+
findPrimitive(substitutions, context) {
|
|
34
34
|
let primitive = null;
|
|
35
35
|
|
|
36
36
|
const parameter = this, ///
|
|
37
37
|
substitution = substitutions.find((substitution) => {
|
|
38
|
-
const
|
|
38
|
+
const substitutionComparesToParameter = substitution.compareParameter(parameter);
|
|
39
39
|
|
|
40
|
-
if (
|
|
40
|
+
if (substitutionComparesToParameter) {
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
43
|
}) || null;
|
|
44
44
|
|
|
45
45
|
if (substitution !== null) {
|
|
46
|
-
primitive = substitution.getPrimitive();
|
|
46
|
+
primitive = substitution.getPrimitive(context);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
return primitive;
|
|
@@ -38,7 +38,7 @@ export default define(class ProcedureCall extends Element {
|
|
|
38
38
|
findPrimitives(context) {
|
|
39
39
|
const substitutions = context.getSubstitutions(),
|
|
40
40
|
primitives = this.parameters.map((parameter) => {
|
|
41
|
-
const primitive = parameter.findPrimitive(substitutions);
|
|
41
|
+
const primitive = parameter.findPrimitive(substitutions, context);
|
|
42
42
|
|
|
43
43
|
return primitive;
|
|
44
44
|
});
|
|
@@ -137,7 +137,7 @@ export default define(class Step extends ProofAssertion {
|
|
|
137
137
|
|
|
138
138
|
context.trace(`Validating the '${stepString}' step's '${referenceString}' reference... `);
|
|
139
139
|
|
|
140
|
-
const reference = this.reference.validate();
|
|
140
|
+
const reference = this.reference.validate(context);
|
|
141
141
|
|
|
142
142
|
if (reference === null) {
|
|
143
143
|
referenceValidates = false;
|
package/src/element/reference.js
CHANGED
|
@@ -123,60 +123,79 @@ export default define(class Reference extends Element {
|
|
|
123
123
|
return topLevelMetaAssertionCompares;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
findValidReference(context) {
|
|
127
|
+
const referenceNode = this.getReferenceNode(),
|
|
128
|
+
reference = context.findReferenceByReferenceNode(referenceNode),
|
|
129
|
+
validReference = reference; ///
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
+
return validReference;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
validate(context) {
|
|
135
|
+
let reference = null;
|
|
136
|
+
|
|
137
|
+
const referenceString = this.getString(); ///
|
|
131
138
|
|
|
132
139
|
context.trace(`Validating the '${referenceString}' reference...`);
|
|
133
140
|
|
|
134
|
-
let validates;
|
|
141
|
+
let validates = false;
|
|
135
142
|
|
|
136
|
-
|
|
137
|
-
const metavariableValidates = this.validateMetavariable(context);
|
|
143
|
+
const validReference = this.findValidReference(context);
|
|
138
144
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
referenceMetaType = context.findMetaTypeByMetaTypeName(referenceMetaTypeName),
|
|
142
|
-
metaType = this.metavariable.getMetaType();
|
|
145
|
+
if (validReference) {
|
|
146
|
+
reference = validReference; ///
|
|
143
147
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
148
|
+
context.debug(`...the '${referenceString}' reference is already valid.`);
|
|
149
|
+
} else {
|
|
150
|
+
const context = this.getContext();
|
|
147
151
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
attempt((context) => {
|
|
153
|
+
const metavariableValidates = this.validateMetavariable(context);
|
|
154
|
+
|
|
155
|
+
if (metavariableValidates) {
|
|
156
|
+
const referenceMetaTypeName = REFERENCE_META_TYPE_NAME,
|
|
157
|
+
referenceMetaType = context.findMetaTypeByMetaTypeName(referenceMetaTypeName),
|
|
158
|
+
metaType = this.metavariable.getMetaType();
|
|
155
159
|
|
|
156
|
-
if (
|
|
157
|
-
|
|
160
|
+
if (metaType === null) {
|
|
161
|
+
const reference = this, ///
|
|
162
|
+
labelPresent = context.isLabelPresentByReference(reference);
|
|
163
|
+
|
|
164
|
+
if (labelPresent) {
|
|
165
|
+
validates = true;
|
|
166
|
+
} else {
|
|
167
|
+
context.debug(`There is no label for the '${referenceString}' reference.`);
|
|
168
|
+
}
|
|
158
169
|
} else {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
const metavariableMetaTypeEqualToReferenceMetaType = this.metavariable.isMetaTypeEqualTo(referenceMetaType);
|
|
171
|
+
|
|
172
|
+
if (metavariableMetaTypeEqualToReferenceMetaType) {
|
|
173
|
+
validates = true;
|
|
174
|
+
} else {
|
|
175
|
+
const metaTypeString = metaType.getString(),
|
|
176
|
+
metavariableString = this.metavariable.getString(),
|
|
177
|
+
referenceMetaTypeString = referenceMetaType.getString();
|
|
162
178
|
|
|
163
|
-
|
|
179
|
+
context.debug(`The '${referenceString}' reference's '${metavariableString}' metavariable's '${metaTypeString}' meta-type should be the '${referenceMetaTypeString}' meta-type.`);
|
|
180
|
+
}
|
|
164
181
|
}
|
|
165
182
|
}
|
|
166
|
-
}
|
|
167
183
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
184
|
+
if (validates) {
|
|
185
|
+
context.commit(this);
|
|
186
|
+
}
|
|
187
|
+
}, context);
|
|
188
|
+
}
|
|
172
189
|
|
|
173
190
|
if (validates) {
|
|
174
|
-
|
|
191
|
+
reference = this; ///
|
|
192
|
+
|
|
193
|
+
context.addReference(reference);
|
|
175
194
|
|
|
176
195
|
context.debug(`...validated the '${referenceString}' reference.`);
|
|
177
196
|
}
|
|
178
197
|
|
|
179
|
-
return
|
|
198
|
+
return reference;
|
|
180
199
|
}
|
|
181
200
|
|
|
182
201
|
validateMetavariable(context) {
|
|
@@ -338,5 +357,3 @@ export default define(class Reference extends Element {
|
|
|
338
357
|
return reference;
|
|
339
358
|
}
|
|
340
359
|
});
|
|
341
|
-
|
|
342
|
-
let counter = 0;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import Substitution from "../substitution";
|
|
4
4
|
|
|
5
5
|
import { define } from "../../elements";
|
|
6
|
-
import { descend, instantiate } from "../../utilities/context";
|
|
7
6
|
import { instantiateFrameSubstitution } from "../../process/instantiate";
|
|
7
|
+
import { attempt, descend, instantiate } from "../../utilities/context";
|
|
8
8
|
import { frameSubstitutionStringFromFrameAndMetavariable } from "../../utilities/string";
|
|
9
9
|
import { frameSubstitutionFromStatementNode, frameSubstitutionFromFrameSubstitutionNode } from "../../utilities/element";
|
|
10
10
|
|
|
@@ -78,34 +78,43 @@ export default define(class FrameSubstitution extends Substitution {
|
|
|
78
78
|
|
|
79
79
|
context.trace(`Validating the '${frameSubstitutionString}' frame substitution...`);
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
let validates = false;
|
|
82
|
+
|
|
83
|
+
const validSubstitution = this.findValidSubstitution(context);
|
|
82
84
|
|
|
83
85
|
if (validSubstitution) {
|
|
84
86
|
frameSubstitution = validSubstitution; ///
|
|
85
87
|
|
|
86
88
|
context.debug(`...the '${frameSubstitutionString}' frame substitution is already valid.`);
|
|
87
89
|
} else {
|
|
88
|
-
|
|
90
|
+
const context = this.getContext(),
|
|
91
|
+
specificContext = context; ///
|
|
89
92
|
|
|
90
|
-
|
|
93
|
+
attempt((specificContext) => {
|
|
94
|
+
const targetFrameValidates = this.validateTargetFrame(generalContext, specificContext);
|
|
91
95
|
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
if (targetFrameValidates) {
|
|
97
|
+
const replacementFrameValidates = this.validateReplacementFrame(generalContext, specificContext);
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
if (replacementFrameValidates) {
|
|
100
|
+
validates = true;
|
|
101
|
+
}
|
|
97
102
|
}
|
|
98
|
-
}
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
if (validates) {
|
|
105
|
+
specificContext.commit(this);
|
|
106
|
+
}
|
|
107
|
+
}, specificContext);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (validates) {
|
|
111
|
+
const substitution = this; ///
|
|
102
112
|
|
|
103
|
-
|
|
113
|
+
frameSubstitution = substitution; ///
|
|
104
114
|
|
|
105
|
-
|
|
115
|
+
context.addSubstitution(substitution);
|
|
106
116
|
|
|
107
|
-
|
|
108
|
-
}
|
|
117
|
+
context.debug(`...validated the '${frameSubstitutionString}' frame substitution.`);
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
return frameSubstitution;
|
|
@@ -146,7 +155,7 @@ export default define(class FrameSubstitution extends Substitution {
|
|
|
146
155
|
validateReplacementFrame(generalContext, specificContext) {
|
|
147
156
|
let replacementFrameValidates = false;
|
|
148
157
|
|
|
149
|
-
const context =
|
|
158
|
+
const context = specificContext, ///
|
|
150
159
|
replacementFrameString = this.replacementFrame.getString(),
|
|
151
160
|
frameSubstitutionString = this.getString(); ///
|
|
152
161
|
|
|
@@ -184,8 +193,6 @@ export default define(class FrameSubstitution extends Substitution {
|
|
|
184
193
|
targetFrame = targetFrameFromFrameSubstitutionNode(frameSubstitutionNode, context),
|
|
185
194
|
replacementFrame = replacementFrameFromFrameSubstitutionNode(frameSubstitutionNode, context);
|
|
186
195
|
|
|
187
|
-
context = null;
|
|
188
|
-
|
|
189
196
|
frameSubstitutionn = new FrameSubstitution(context, string, node, targetFrame, replacementFrame);
|
|
190
197
|
}, context);
|
|
191
198
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import Substitution from "../substitution";
|
|
4
4
|
|
|
5
5
|
import { define } from "../../elements";
|
|
6
|
-
import { instantiate } from "../../utilities/context";
|
|
6
|
+
import { attempt, instantiate } from "../../utilities/context";
|
|
7
7
|
import { instantiateReferenceSubstitution } from "../../process/instantiate";
|
|
8
8
|
import { referenceSubstitutionFromReferenceSubstitutionNode } from "../../utilities/element";
|
|
9
9
|
import { referenceSubstitutionStringFromReferenceAndMetavariable } from "../../utilities/string";
|
|
@@ -70,6 +70,23 @@ export default define(class ReferenceSubstitution extends Substitution {
|
|
|
70
70
|
return comparesToParameter;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
compareSubstitution(substitution) {
|
|
74
|
+
let substitutionCompares = false;
|
|
75
|
+
|
|
76
|
+
const substitutionReferenceSubstitution = (substitution instanceof ReferenceSubstitution);
|
|
77
|
+
|
|
78
|
+
if (substitutionReferenceSubstitution) {
|
|
79
|
+
const substitutionNode = substitution.getNode(),
|
|
80
|
+
substitutionNodeMatches = this.matchNode(substitutionNode);
|
|
81
|
+
|
|
82
|
+
if (substitutionNodeMatches) {
|
|
83
|
+
substitutionCompares = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return substitutionCompares;
|
|
88
|
+
}
|
|
89
|
+
|
|
73
90
|
validate(generalContext, specificContext) {
|
|
74
91
|
let referenceSubstitution = null;
|
|
75
92
|
|
|
@@ -78,34 +95,43 @@ export default define(class ReferenceSubstitution extends Substitution {
|
|
|
78
95
|
|
|
79
96
|
context.trace(`Validating the '${referenceSubstitutionString}' reference substitution...`);
|
|
80
97
|
|
|
81
|
-
|
|
98
|
+
let validates = false;
|
|
99
|
+
|
|
100
|
+
const validSubstitution = this.findValidSubstitution(context);
|
|
82
101
|
|
|
83
102
|
if (validSubstitution) {
|
|
84
103
|
referenceSubstitution = validSubstitution; ///
|
|
85
104
|
|
|
86
105
|
context.debug(`...the '${referenceSubstitutionString}' reference substitution is already valid.`);
|
|
87
106
|
} else {
|
|
88
|
-
|
|
107
|
+
const context = this.getContext(),
|
|
108
|
+
specificContext = context; ///
|
|
89
109
|
|
|
90
|
-
|
|
110
|
+
attempt((specificContext) => {
|
|
111
|
+
const targetReferenceValidates = this.validateTargetReference(generalContext, specificContext);
|
|
91
112
|
|
|
92
|
-
|
|
93
|
-
|
|
113
|
+
if (targetReferenceValidates) {
|
|
114
|
+
const replacementReferenceValidates = this.validateReplacementReference(generalContext, specificContext);
|
|
94
115
|
|
|
95
|
-
|
|
96
|
-
|
|
116
|
+
if (replacementReferenceValidates) {
|
|
117
|
+
validates = true;
|
|
118
|
+
}
|
|
97
119
|
}
|
|
98
|
-
}
|
|
99
120
|
|
|
100
|
-
|
|
101
|
-
|
|
121
|
+
if (validates) {
|
|
122
|
+
specificContext.commit(this);
|
|
123
|
+
}
|
|
124
|
+
}, specificContext);
|
|
125
|
+
}
|
|
102
126
|
|
|
103
|
-
|
|
127
|
+
if (validates) {
|
|
128
|
+
const substitution = this; ///
|
|
104
129
|
|
|
105
|
-
|
|
130
|
+
referenceSubstitution = substitution; ///
|
|
106
131
|
|
|
107
|
-
|
|
108
|
-
|
|
132
|
+
context.addSubstitution(substitution);
|
|
133
|
+
|
|
134
|
+
context.debug(`...validated the '${referenceSubstitutionString}' reference substitution.`);
|
|
109
135
|
}
|
|
110
136
|
|
|
111
137
|
return referenceSubstitution;
|
|
@@ -114,17 +140,15 @@ export default define(class ReferenceSubstitution extends Substitution {
|
|
|
114
140
|
validateTargetReference(generalContext, specificContext) {
|
|
115
141
|
let targetReferenceValidates = false;
|
|
116
142
|
|
|
117
|
-
const context =
|
|
143
|
+
const context = generalContext, ///
|
|
118
144
|
targetReferenceString = this.targetReference.getString(),
|
|
119
145
|
referenceSubstitutionString = this.getString(); ///
|
|
120
146
|
|
|
121
147
|
context.trace(`Validating the '${referenceSubstitutionString}' reference substitution's '${targetReferenceString}' target reference...`);
|
|
122
148
|
|
|
123
|
-
const targetReference = this.targetReference.validate();
|
|
149
|
+
const targetReference = this.targetReference.validate(context);
|
|
124
150
|
|
|
125
151
|
if (targetReference !== null) {
|
|
126
|
-
context.addReference(targetReference);
|
|
127
|
-
|
|
128
152
|
targetReferenceValidates = true;
|
|
129
153
|
}
|
|
130
154
|
|
|
@@ -138,17 +162,15 @@ export default define(class ReferenceSubstitution extends Substitution {
|
|
|
138
162
|
validateReplacementReference(generalContext, specificContext) {
|
|
139
163
|
let replacementReferenceValidates = false;
|
|
140
164
|
|
|
141
|
-
const context =
|
|
165
|
+
const context = specificContext, ///
|
|
142
166
|
replacementReferenceString = this.replacementReference.getString(),
|
|
143
167
|
referenceSubstitutionString = this.getString(); ///
|
|
144
168
|
|
|
145
169
|
context.trace(`Validating the '${referenceSubstitutionString}' reference substitution's '${replacementReferenceString}' replacement reference...`);
|
|
146
170
|
|
|
147
|
-
const replacementReference = this.replacementReference.validate();
|
|
171
|
+
const replacementReference = this.replacementReference.validate(context);
|
|
148
172
|
|
|
149
173
|
if (replacementReference !== null) {
|
|
150
|
-
context.addReference(replacementReference);
|
|
151
|
-
|
|
152
174
|
replacementReferenceValidates = true;
|
|
153
175
|
}
|
|
154
176
|
|
|
@@ -174,8 +196,6 @@ export default define(class ReferenceSubstitution extends Substitution {
|
|
|
174
196
|
targetReference = targetReferenceFromReferenceSubstitutionNode(referenceSubstitutionNode, context),
|
|
175
197
|
replacementReference = replacementReferenceFromReferenceSubstitutionNode(referenceSubstitutionNode, context);
|
|
176
198
|
|
|
177
|
-
context = null;
|
|
178
|
-
|
|
179
199
|
referenceSubstitutionn = new ReferenceSubstitution(context, string, node, targetReference, replacementReference);
|
|
180
200
|
}, context);
|
|
181
201
|
}
|
|
@@ -196,6 +216,22 @@ export default define(class ReferenceSubstitution extends Substitution {
|
|
|
196
216
|
|
|
197
217
|
return referenceSubstitution;
|
|
198
218
|
}
|
|
219
|
+
|
|
220
|
+
static fromAssumptionAndMetaLevelAssumption(assumption, metaLevelAssumption, context) {
|
|
221
|
+
let referenceSubstitution;
|
|
222
|
+
|
|
223
|
+
instantiate((context) => {
|
|
224
|
+
const reference = metaLevelAssumption.getReference(),
|
|
225
|
+
metavariable = assumption.getMetavariable(),
|
|
226
|
+
referenceSubstitutionString = referenceSubstitutionStringFromReferenceAndMetavariable(reference, metavariable),
|
|
227
|
+
string = referenceSubstitutionString, ///
|
|
228
|
+
referenceSubstitutionNode = instantiateReferenceSubstitution(string, context);
|
|
229
|
+
|
|
230
|
+
referenceSubstitution = referenceSubstitutionFromReferenceSubstitutionNode(referenceSubstitutionNode, context);
|
|
231
|
+
}, context);
|
|
232
|
+
|
|
233
|
+
return referenceSubstitution;
|
|
234
|
+
}
|
|
199
235
|
});
|
|
200
236
|
|
|
201
237
|
function targetReferenceFromReferenceSubstitutionNode(referenceSubstitutionNode, context) {
|
|
@@ -6,7 +6,7 @@ import { define } from "../../elements";
|
|
|
6
6
|
import { unifySubstitution } from "../../process/unify";
|
|
7
7
|
import { stripBracketsFromStatement } from "../../utilities/brackets";
|
|
8
8
|
import { instantiateStatementSubstitution } from "../../process/instantiate";
|
|
9
|
-
import { join, descend, reconcile, instantiate } from "../../utilities/context";
|
|
9
|
+
import { join, attempt, descend, reconcile, instantiate } from "../../utilities/context";
|
|
10
10
|
import { statementSubstitutionFromStatementSubstitutionNode } from "../../utilities/element";
|
|
11
11
|
import { statementSubstitutionStringFromStatementAndMetavariable, statementSubstitutionStringFromStatementMetavariableAndSubstitution } from "../../utilities/string";
|
|
12
12
|
|
|
@@ -113,39 +113,80 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
113
113
|
|
|
114
114
|
context.trace(`Validating the '${statementSubstitutionString}' statement substitution...`);
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
let validates = false;
|
|
117
|
+
|
|
118
|
+
const validSubstitution = this.findValidSubstitution(context);
|
|
117
119
|
|
|
118
120
|
if (validSubstitution) {
|
|
119
121
|
statementSubstitution = validSubstitution; ///
|
|
120
122
|
|
|
121
123
|
context.debug(`...the '${statementSubstitutionString}' statement substitution is already valid.`);
|
|
122
124
|
} else {
|
|
123
|
-
|
|
125
|
+
const context = this.getContext(),
|
|
126
|
+
specificContext = context; ///
|
|
127
|
+
|
|
128
|
+
attempt((specificContext) => {
|
|
129
|
+
const targetStatementValidates = this.validateTargetStatement(generalContext, specificContext);
|
|
130
|
+
|
|
131
|
+
if (targetStatementValidates) {
|
|
132
|
+
const replacementStatementValidates = this.validateReplacementStatement(generalContext, specificContext);
|
|
124
133
|
|
|
125
|
-
|
|
134
|
+
if (replacementStatementValidates) {
|
|
135
|
+
const substitutionValidates = this.validateSubstitution(generalContext, specificContext);
|
|
126
136
|
|
|
127
|
-
|
|
128
|
-
|
|
137
|
+
if (substitutionValidates) {
|
|
138
|
+
validates = true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
129
142
|
|
|
130
|
-
if (
|
|
131
|
-
|
|
143
|
+
if (validates) {
|
|
144
|
+
specificContext.commit(this);
|
|
132
145
|
}
|
|
133
|
-
}
|
|
146
|
+
}, specificContext);
|
|
147
|
+
}
|
|
134
148
|
|
|
135
|
-
|
|
136
|
-
|
|
149
|
+
if (validates) {
|
|
150
|
+
const substitution = this; ///
|
|
137
151
|
|
|
138
|
-
|
|
152
|
+
statementSubstitution = substitution; ///
|
|
139
153
|
|
|
140
|
-
|
|
154
|
+
context.addSubstitution(substitution);
|
|
141
155
|
|
|
142
|
-
|
|
143
|
-
}
|
|
156
|
+
context.debug(`...validated the '${statementSubstitutionString}' statement substitution.`);
|
|
144
157
|
}
|
|
145
158
|
|
|
146
159
|
return statementSubstitution;
|
|
147
160
|
}
|
|
148
161
|
|
|
162
|
+
validateSubstitution(generalContext, specificContext) {
|
|
163
|
+
let substitutionValidates = true;
|
|
164
|
+
|
|
165
|
+
if (this.substitution !== null) {
|
|
166
|
+
const context = specificContext, ///
|
|
167
|
+
substitutionString = this.substitution.getString(),
|
|
168
|
+
statementSubstitutionString = this.getString();
|
|
169
|
+
|
|
170
|
+
context.trace(`Validating the '${statementSubstitutionString}' statement substitution's '${substitutionString}' substitution...`);
|
|
171
|
+
|
|
172
|
+
specificContext = generalContext; ///
|
|
173
|
+
|
|
174
|
+
const substitution = this.substitution.validate(generalContext, specificContext);
|
|
175
|
+
|
|
176
|
+
if (substitution !== null) {
|
|
177
|
+
this.substitution = substitution;
|
|
178
|
+
|
|
179
|
+
substitutionValidates = true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (substitutionValidates) {
|
|
183
|
+
context.debug(`...validatewd the '${statementSubstitutionString}' statement substitution's '${substitutionString}' substitution.`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return substitutionValidates;
|
|
188
|
+
}
|
|
189
|
+
|
|
149
190
|
validateTargetStatement(generalContext, specificContext) {
|
|
150
191
|
let targetStatementValidates = false;
|
|
151
192
|
|
|
@@ -179,7 +220,7 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
179
220
|
validateReplacementStatement(generalContext, specificContext) {
|
|
180
221
|
let replacementStatementValidates = false;
|
|
181
222
|
|
|
182
|
-
const context =
|
|
223
|
+
const context = specificContext, ///
|
|
183
224
|
replacementStatementString = this.replacementStatement.getString(),
|
|
184
225
|
statementSubstitutionString = this.getString(); ///
|
|
185
226
|
|
|
@@ -353,8 +394,6 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
353
394
|
targetStatement = targetStatementFromStatementSubstitutionNode(statementSubstitutionNode, context),
|
|
354
395
|
replacementStatement = replacementStatementFromStatementSubstitutionNode(statementSubstitutionNode, context);
|
|
355
396
|
|
|
356
|
-
context = null;
|
|
357
|
-
|
|
358
397
|
statementSubstitutionn = new StatementSubstitution(context, string, node, targetStatement, replacementStatement);
|
|
359
398
|
}, context);
|
|
360
399
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import Substitution from "../substitution";
|
|
4
4
|
|
|
5
5
|
import { define } from "../../elements";
|
|
6
|
-
import { instantiate } from "../../utilities/context";
|
|
6
|
+
import { attempt, instantiate } from "../../utilities/context";
|
|
7
7
|
import { stripBracketsFromTerm } from "../../utilities/brackets";
|
|
8
8
|
import { instantiateTermSubstitution } from "../../process/instantiate";
|
|
9
9
|
import { termSubstitutionStringFromTermAndVariable } from "../../utilities/string";
|
|
@@ -81,34 +81,43 @@ export default define(class TermSubstitution extends Substitution {
|
|
|
81
81
|
|
|
82
82
|
context.trace(`Validating the '${termSubstitutionString}' term substitution...`);
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
let validates = false;
|
|
85
|
+
|
|
86
|
+
const validSubstitution = this.findValidSubstitution(context);
|
|
85
87
|
|
|
86
88
|
if (validSubstitution) {
|
|
87
89
|
termSubstitution = validSubstitution; ///
|
|
88
90
|
|
|
89
91
|
context.debug(`...the '${termSubstitutionString}' term substitution is already valid.`);
|
|
90
92
|
} else {
|
|
91
|
-
|
|
93
|
+
const context = this.getContext(),
|
|
94
|
+
specificContext = context; ///
|
|
92
95
|
|
|
93
|
-
|
|
96
|
+
attempt((specificContext) => {
|
|
97
|
+
const targetTermValidates = this.validateTargetTerm(generalContext, specificContext);
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
if (targetTermValidates) {
|
|
100
|
+
const replacementTermValidates = this.validateReplacementTerm(generalContext, specificContext);
|
|
97
101
|
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
if (replacementTermValidates) {
|
|
103
|
+
validates = true;
|
|
104
|
+
}
|
|
100
105
|
}
|
|
101
|
-
}
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
if (validates) {
|
|
108
|
+
specificContext.commit(this);
|
|
109
|
+
}
|
|
110
|
+
}, specificContext);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (validates) {
|
|
114
|
+
const substitution = this; ///
|
|
105
115
|
|
|
106
|
-
|
|
116
|
+
termSubstitution = substitution; ///
|
|
107
117
|
|
|
108
|
-
|
|
118
|
+
context.addSubstitution(substitution);
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
}
|
|
120
|
+
context.debug(`...validated the '${termSubstitutionString}' term substitution.`);
|
|
112
121
|
}
|
|
113
122
|
|
|
114
123
|
return termSubstitution;
|
|
@@ -151,7 +160,7 @@ export default define(class TermSubstitution extends Substitution {
|
|
|
151
160
|
validateReplacementTerm(generalContext, specificContext) {
|
|
152
161
|
let replacementTermValidates = false;
|
|
153
162
|
|
|
154
|
-
const context =
|
|
163
|
+
const context = specificContext, ///
|
|
155
164
|
replacementTermString = this.replacementTerm.getString(),
|
|
156
165
|
termSubstitutionString = this.getString(); ///
|
|
157
166
|
|
|
@@ -191,8 +200,6 @@ export default define(class TermSubstitution extends Substitution {
|
|
|
191
200
|
targetTerm = targetTermFromTermSubstitutionNode(termSubstitutionNode, context),
|
|
192
201
|
replacementTerm = replacementTermFromTermSubstitutionNode(termSubstitutionNode, context);
|
|
193
202
|
|
|
194
|
-
context = null;
|
|
195
|
-
|
|
196
203
|
termSubstitutionn = new TermSubstitution(context, string, node, targetTerm, replacementTerm);
|
|
197
204
|
}, context);
|
|
198
205
|
}
|
|
@@ -6,9 +6,8 @@ import { primitiveUtilities } from "occam-furtle";
|
|
|
6
6
|
const { primitiveFromNode } =primitiveUtilities;
|
|
7
7
|
|
|
8
8
|
export default class Substitution extends Element {
|
|
9
|
-
getPrimitive() {
|
|
10
|
-
const
|
|
11
|
-
replacementNode = this.getReplacementNode(),
|
|
9
|
+
getPrimitive(context) {
|
|
10
|
+
const replacementNode = this.getReplacementNode(),
|
|
12
11
|
node = replacementNode, ///
|
|
13
12
|
primitive = primitiveFromNode(node, context);
|
|
14
13
|
|
|
@@ -30,7 +29,7 @@ export default class Substitution extends Element {
|
|
|
30
29
|
return substitutionNodeMatches;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
findValidSubstitution(context) {
|
|
34
33
|
const substitutionNode = this.getSubstitutionNode(),
|
|
35
34
|
substitution = context.findSubstitutionBySubstitutionNode(substitutionNode),
|
|
36
35
|
validSubstitution = substitution; ///
|