occam-verify-cli 1.0.457 → 1.0.473
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/constants.js +13 -1
- package/lib/context/ephemeral.js +270 -0
- package/lib/context/file.js +102 -66
- package/lib/context/liminal.js +120 -0
- package/lib/context/literal.js +92 -0
- package/lib/context/nominal.js +15 -1
- package/lib/context/release.js +66 -7
- package/lib/context/scoped.js +48 -40
- package/lib/context/synthetic.js +133 -0
- package/lib/element/assertion/contained.js +66 -66
- package/lib/element/assertion/defined.js +32 -32
- package/lib/element/assertion/property.js +39 -39
- package/lib/element/assertion/satisfies.js +22 -22
- package/lib/element/assumption.js +5 -8
- package/lib/element/conclusion.js +14 -13
- package/lib/element/constructor.js +2 -2
- package/lib/element/deduction.js +14 -13
- package/lib/element/derivation.js +3 -3
- package/lib/element/equality.js +5 -5
- package/lib/element/equivalence.js +112 -107
- package/lib/element/equivalences.js +24 -10
- package/lib/element/error.js +3 -3
- package/lib/element/frame.js +38 -21
- package/lib/element/hypothesis.js +2 -2
- package/lib/element/judgement.js +6 -5
- package/lib/element/metaType.js +1 -2
- package/lib/element/metavariable.js +46 -35
- package/lib/element/parameter.js +13 -5
- package/lib/element/procedureCall.js +16 -16
- package/lib/element/proof.js +14 -13
- package/lib/element/proofAssertion/premise.js +41 -30
- package/lib/element/proofAssertion/step.js +39 -35
- package/lib/element/proofAssertion/supposition.js +43 -32
- package/lib/element/proofAssertion.js +19 -5
- package/lib/element/propertyRelation.js +2 -2
- package/lib/element/reference.js +50 -9
- package/lib/element/rule.js +26 -28
- package/lib/element/section.js +2 -2
- package/lib/element/signature.js +9 -6
- package/lib/element/statement.js +44 -31
- package/lib/element/subproof.js +18 -17
- package/lib/element/substitution/frame.js +83 -46
- package/lib/element/substitution/reference.js +101 -19
- package/lib/element/substitution/statement.js +122 -75
- package/lib/element/substitution/term.js +93 -57
- package/lib/element/substitution.js +20 -69
- package/lib/element/substitutions.js +49 -34
- package/lib/element/term.js +30 -21
- package/lib/element/topLevelAssertion/axiom.js +8 -6
- package/lib/element/topLevelAssertion/conjecture.js +4 -4
- package/lib/element/topLevelAssertion/lemma.js +4 -4
- package/lib/element/topLevelAssertion/theorem.js +2 -2
- package/lib/element/topLevelAssertion.js +30 -23
- package/lib/element/topLevelMetaAssertion/metaLemma.js +2 -2
- package/lib/element/topLevelMetaAssertion/metatheorem.js +2 -2
- package/lib/element/topLevelMetaAssertion.js +16 -12
- package/lib/element/variable.js +30 -22
- package/lib/index.js +3 -3
- package/lib/main.js +3 -3
- package/lib/node/frame.js +2 -2
- package/lib/node/metavariable.js +4 -4
- package/lib/node/parameter.js +28 -7
- package/lib/node/substitution/frame.js +9 -31
- package/lib/node/substitution/reference.js +137 -0
- package/lib/node/substitution/statement.js +9 -31
- package/lib/node/substitution/term.js +9 -23
- package/lib/nonTerminalNodeMap.js +3 -2
- package/lib/process/instantiate.js +2 -14
- package/lib/process/unify.js +5 -5
- package/lib/tokenTypes.js +22 -0
- package/lib/utilities/context.js +54 -19
- package/lib/utilities/element.js +161 -336
- package/lib/utilities/instance.js +4 -4
- package/lib/utilities/string.js +18 -4
- package/lib/utilities/unification.js +24 -18
- package/lib/utilities/validation.js +31 -31
- package/package.json +2 -2
- package/src/constants.js +12 -0
- package/src/context/{transient.js → ephemeral.js} +15 -112
- package/src/context/file.js +66 -67
- package/src/context/liminal.js +67 -0
- package/src/context/{fragment.js → literal.js} +17 -4
- package/src/context/nominal.js +12 -0
- package/src/context/release.js +44 -6
- package/src/context/scoped.js +41 -31
- package/src/context/synthetic.js +60 -0
- package/src/element/assertion/contained.js +49 -47
- package/src/element/assertion/defined.js +29 -27
- package/src/element/assertion/property.js +35 -35
- package/src/element/assertion/satisfies.js +19 -18
- package/src/element/assumption.js +4 -10
- package/src/element/conclusion.js +16 -19
- package/src/element/constructor.js +1 -1
- package/src/element/deduction.js +16 -21
- package/src/element/derivation.js +2 -2
- package/src/element/equality.js +4 -4
- package/src/element/equivalence.js +115 -135
- package/src/element/equivalences.js +9 -7
- package/src/element/error.js +4 -2
- package/src/element/frame.js +50 -23
- package/src/element/hypothesis.js +1 -1
- package/src/element/judgement.js +9 -4
- package/src/element/metaType.js +0 -1
- package/src/element/metavariable.js +54 -53
- package/src/element/parameter.js +10 -5
- package/src/element/procedureCall.js +20 -18
- package/src/element/proof.js +14 -16
- package/src/element/proofAssertion/premise.js +46 -42
- package/src/element/proofAssertion/step.js +45 -40
- package/src/element/proofAssertion/supposition.js +56 -45
- package/src/element/proofAssertion.js +23 -5
- package/src/element/propertyRelation.js +1 -1
- package/src/element/reference.js +64 -16
- package/src/element/rule.js +31 -37
- package/src/element/section.js +1 -1
- package/src/element/signature.js +8 -8
- package/src/element/statement.js +51 -40
- package/src/element/subproof.js +16 -18
- package/src/element/substitution/frame.js +99 -42
- package/src/element/substitution/reference.js +120 -20
- package/src/element/substitution/statement.js +160 -89
- package/src/element/substitution/term.js +104 -63
- package/src/element/substitution.js +16 -58
- package/src/element/substitutions.js +43 -41
- package/src/element/term.js +37 -32
- package/src/element/topLevelAssertion/axiom.js +8 -6
- package/src/element/topLevelAssertion/conjecture.js +1 -2
- package/src/element/topLevelAssertion/lemma.js +2 -3
- package/src/element/topLevelAssertion/theorem.js +1 -1
- package/src/element/topLevelAssertion.js +31 -27
- package/src/element/topLevelMetaAssertion/metaLemma.js +1 -2
- package/src/element/topLevelMetaAssertion/metatheorem.js +1 -2
- package/src/element/topLevelMetaAssertion.js +15 -13
- package/src/element/variable.js +30 -31
- package/src/index.js +2 -1
- package/src/main.js +2 -1
- package/src/node/frame.js +1 -1
- package/src/node/metavariable.js +3 -3
- package/src/node/parameter.js +32 -5
- package/src/node/substitution/frame.js +6 -32
- package/src/node/substitution/reference.js +38 -0
- package/src/node/substitution/statement.js +6 -32
- package/src/node/substitution/term.js +6 -22
- package/src/nonTerminalNodeMap.js +3 -0
- package/src/process/instantiate.js +0 -8
- package/src/process/unify.js +4 -4
- package/src/tokenTypes.js +4 -0
- package/src/utilities/context.js +43 -17
- package/src/utilities/element.js +187 -401
- package/src/utilities/instance.js +3 -3
- package/src/utilities/string.js +21 -5
- package/src/utilities/unification.js +26 -23
- package/src/utilities/validation.js +47 -47
- package/lib/context/fragment.js +0 -77
- package/lib/context/transient.js +0 -371
- package/lib/log.js +0 -150
- package/lib/utilities/fragment.js +0 -23
- package/lib/utilities/node.js +0 -71
- package/src/log.js +0 -118
- package/src/utilities/fragment.js +0 -11
- package/src/utilities/node.js +0 -85
|
@@ -4,103 +4,190 @@ import elements from "../../elements";
|
|
|
4
4
|
import Substitution from "../substitution";
|
|
5
5
|
|
|
6
6
|
import { define } from "../../elements";
|
|
7
|
-
import {
|
|
7
|
+
import { literally } from "../../utilities/context";
|
|
8
8
|
import { unifySubstitution } from "../../process/unify";
|
|
9
9
|
import { stripBracketsFromStatement } from "../../utilities/brackets";
|
|
10
10
|
import { instantiateStatementSubstitution } from "../../process/instantiate";
|
|
11
11
|
import { statementSubstitutionFromStatementSubstitutionNode } from "../../utilities/element";
|
|
12
|
-
import {
|
|
12
|
+
import { statementToStatementJSON, metavariableToMetavariableJSON } from "../../utilities/json";
|
|
13
13
|
import { statementSubstitutionStringFromStatementAndMetavariable, statementSubstitutionStringFromStatementMetavariableAndSubstitution } from "../../utilities/string";
|
|
14
14
|
|
|
15
15
|
export default define(class StatementSubstitution extends Substitution {
|
|
16
|
-
constructor(context, string, node, resolved,
|
|
16
|
+
constructor(context, string, node, resolved, substitution, targetStatement, replacementStatement) {
|
|
17
17
|
super(context, string, node);
|
|
18
18
|
|
|
19
19
|
this.resolved = resolved;
|
|
20
|
-
this.statement = statement;
|
|
21
|
-
this.metavariable = metavariable;
|
|
22
20
|
this.substitution = substitution;
|
|
21
|
+
this.targetStatement = targetStatement;
|
|
22
|
+
this.replacementStatement = replacementStatement;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
isResolved() {
|
|
26
26
|
return this.resolved;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
return this.
|
|
29
|
+
getSubstitution() {
|
|
30
|
+
return this.substitution;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
return this.
|
|
33
|
+
getTargetStatement() {
|
|
34
|
+
return this.targetStatement;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
return this.
|
|
37
|
+
getReplacementStatement() {
|
|
38
|
+
return this.replacementStatement;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getTargetNode() {
|
|
42
|
+
const targetStatementNode = this.targetStatement.getNode(),
|
|
43
|
+
targetNode = targetStatementNode; ///
|
|
44
|
+
|
|
45
|
+
return targetNode;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
getReplacementNode() {
|
|
42
|
-
const
|
|
43
|
-
replacementNode =
|
|
49
|
+
const replacementStatementNode = this.replacementStatement.getNode(),
|
|
50
|
+
replacementNode = replacementStatementNode; ///
|
|
44
51
|
|
|
45
52
|
return replacementNode;
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
this.
|
|
55
|
+
isSimple() {
|
|
56
|
+
const simple = (this.substitution === null);
|
|
57
|
+
|
|
58
|
+
return simple;
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
compareStatement(statement, context) {
|
|
62
|
+
statement = stripBracketsFromStatement(statement, context); ///
|
|
63
|
+
|
|
64
|
+
const replacementStatementEqualToStatement = this.replacementStatement.isEqualTo(statement),
|
|
65
|
+
comparesToStatement = replacementStatementEqualToStatement; ///
|
|
66
|
+
|
|
67
|
+
return comparesToStatement;
|
|
54
68
|
}
|
|
55
69
|
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
compareParameter(parameter) {
|
|
71
|
+
const targetStatementComparesToParameter = this.targetStatement.compareParameter(parameter),
|
|
72
|
+
comparesToParameter = targetStatementComparesToParameter; ///
|
|
73
|
+
|
|
74
|
+
return comparesToParameter;
|
|
58
75
|
}
|
|
59
76
|
|
|
60
|
-
|
|
77
|
+
compareSubstitution(substitution) {
|
|
78
|
+
let comparesToSubstitution = false;
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
80
|
+
if (false) {
|
|
81
|
+
///
|
|
82
|
+
} else if ((this.substitution === null) && (substitution === null)){
|
|
83
|
+
comparesToSubstitution = true;
|
|
84
|
+
} else if ((this.substitution !== null) && (substitution !== null)){
|
|
85
|
+
const substitutionEqualToSubstituion = this.substitution.isEqualTo(substitution);
|
|
64
86
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} else {
|
|
68
|
-
if (substitution === null) {
|
|
69
|
-
substitutionEqualToSubstitution = false;
|
|
70
|
-
} else {
|
|
71
|
-
substitutionEqualToSubstitution = this.substitution.isEqualTo(substitution);
|
|
87
|
+
if (substitutionEqualToSubstituion) {
|
|
88
|
+
comparesToSubstitution = true;
|
|
72
89
|
}
|
|
73
90
|
}
|
|
74
91
|
|
|
75
|
-
return
|
|
92
|
+
return comparesToSubstitution;
|
|
76
93
|
}
|
|
77
94
|
|
|
78
|
-
|
|
79
|
-
|
|
95
|
+
validate(context) {
|
|
96
|
+
let validates = false;
|
|
80
97
|
|
|
81
|
-
const
|
|
82
|
-
comparesToStatement = statementEqualToStatement; ///
|
|
98
|
+
const statementSubstitutionString = this.getString(); ///
|
|
83
99
|
|
|
84
|
-
|
|
100
|
+
context.trace(`Validating the '${statementSubstitutionString}' statement substitution...`);
|
|
101
|
+
|
|
102
|
+
const targetStatementValidates = this.validateTargetStatement(context);
|
|
103
|
+
|
|
104
|
+
if (targetStatementValidates) {
|
|
105
|
+
const replacementStatementValidates = this.validateReplacementStatement(context);
|
|
106
|
+
|
|
107
|
+
if (replacementStatementValidates) {
|
|
108
|
+
validates = true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (validates) {
|
|
113
|
+
const substititoin = this; ///
|
|
114
|
+
|
|
115
|
+
context.addSubstitution(substititoin);
|
|
116
|
+
|
|
117
|
+
context.debug(`...validated the '${statementSubstitutionString}' statement substitution.`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return validates;
|
|
85
121
|
}
|
|
86
122
|
|
|
87
|
-
|
|
88
|
-
|
|
123
|
+
validateTargetStatement(context) {
|
|
124
|
+
let targetStatementValidates = false;
|
|
89
125
|
|
|
90
|
-
|
|
126
|
+
const targetStatementString = this.targetStatement.getString(),
|
|
127
|
+
statementSubstitutionString = this.getString(); ///
|
|
128
|
+
|
|
129
|
+
context.trace(`Validating the '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement...`);
|
|
130
|
+
|
|
131
|
+
const targetStatementSingular = this.targetStatement.isSingular();
|
|
132
|
+
|
|
133
|
+
if (targetStatementSingular) {
|
|
134
|
+
const stated = true,
|
|
135
|
+
assignments = null;
|
|
136
|
+
|
|
137
|
+
targetStatementValidates = this.targetStatement.validate(assignments, stated, context);
|
|
138
|
+
} else {
|
|
139
|
+
context.debug(`The '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement is not singular.`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (targetStatementValidates) {
|
|
143
|
+
context.debug(`...validated the '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement...`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return targetStatementValidates;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
validateReplacementStatement(context) {
|
|
150
|
+
let replacementStatementValidates;
|
|
151
|
+
|
|
152
|
+
const replacementStatementString = this.replacementStatement.getString(),
|
|
153
|
+
statementSubstitutionString = this.getString(); ///
|
|
154
|
+
|
|
155
|
+
context.trace(`Validating the '${statementSubstitutionString}' statement subtitution's '${replacementStatementString}' replacement statement...`);
|
|
156
|
+
|
|
157
|
+
const stated = true,
|
|
158
|
+
assignments = null;
|
|
159
|
+
|
|
160
|
+
replacementStatementValidates = this.replacementStatement.validate(assignments, stated, context);
|
|
161
|
+
|
|
162
|
+
if (replacementStatementValidates) {
|
|
163
|
+
context.debug(`...validated the '${statementSubstitutionString}' statement subtitution's '${replacementStatementString}' replacement statement...`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return replacementStatementValidates;
|
|
91
167
|
}
|
|
92
168
|
|
|
93
169
|
unifyStatement(statement, context) {
|
|
94
|
-
let
|
|
170
|
+
let statementUnifies = false;
|
|
95
171
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
172
|
+
const statementString = statement.getString(),
|
|
173
|
+
statementSubstitutionString = this.getString();
|
|
174
|
+
|
|
175
|
+
context.trace(`Unifying the '${statementString}' statement with the '${statementSubstitutionString}' statement substiution's statement...`);
|
|
176
|
+
|
|
177
|
+
const specificContext = context; ///
|
|
99
178
|
|
|
100
179
|
context = this.getContext();
|
|
101
180
|
|
|
102
|
-
const generalContext = context
|
|
103
|
-
|
|
181
|
+
const generalContext = context; ///
|
|
182
|
+
|
|
183
|
+
context = specificContext; ///
|
|
184
|
+
|
|
185
|
+
const { Substitutions } = elements,
|
|
186
|
+
substitutions = Substitutions.fromNothing(context);
|
|
187
|
+
|
|
188
|
+
statementUnifies = this.replacementStatement.unifyStatement(statement, substitutions, generalContext, specificContext);
|
|
189
|
+
|
|
190
|
+
let substitution = null;
|
|
104
191
|
|
|
105
192
|
if (statementUnifies) {
|
|
106
193
|
const substitutionsNonTrivialLength = substitutions.getNonTrivialLength();
|
|
@@ -109,9 +196,15 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
109
196
|
const firstSubstitution = substitutions.getFirstSubstitution();
|
|
110
197
|
|
|
111
198
|
substitution = firstSubstitution; ///
|
|
199
|
+
} else {
|
|
200
|
+
statementUnifies = false;
|
|
112
201
|
}
|
|
113
202
|
}
|
|
114
203
|
|
|
204
|
+
if (statementUnifies) {
|
|
205
|
+
context.trace(`...unified the '${statementString}' statement with the '${statementSubstitutionString}' statement substiution's statement.`);
|
|
206
|
+
}
|
|
207
|
+
|
|
115
208
|
return substitution;
|
|
116
209
|
}
|
|
117
210
|
|
|
@@ -142,41 +235,28 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
142
235
|
}
|
|
143
236
|
|
|
144
237
|
resolve(substitutions, context) {
|
|
145
|
-
|
|
238
|
+
context = this.getContext();
|
|
239
|
+
|
|
240
|
+
const substitutionString = this.getString(); ///
|
|
146
241
|
|
|
147
242
|
context.trace(`Resolving the ${substitutionString} substitution...`);
|
|
148
243
|
|
|
149
|
-
substitutions.snapshot();
|
|
244
|
+
substitutions.snapshot(context);
|
|
150
245
|
|
|
151
246
|
const metavariable = this.getMetavariable(),
|
|
152
|
-
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable)
|
|
153
|
-
|
|
154
|
-
if (simpleSubstitution !== null) {
|
|
155
|
-
let context;
|
|
156
|
-
|
|
157
|
-
context = this.getContext();
|
|
247
|
+
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable),
|
|
248
|
+
substitution = simpleSubstitution.unifyStatement(this.replacementStatement, context);
|
|
158
249
|
|
|
159
|
-
|
|
250
|
+
if (substitution !== null) {
|
|
251
|
+
const substitutionUnifies = this.unifySubstitution(substitution, substitutions, context);
|
|
160
252
|
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const simpleContext = context; ///
|
|
165
|
-
|
|
166
|
-
context = substitution.getContext();
|
|
167
|
-
|
|
168
|
-
context.merge(simpleContext);
|
|
169
|
-
|
|
170
|
-
const substitutionUnifies = this.unifySubstitution(substitution, substitutions, context);
|
|
171
|
-
|
|
172
|
-
if (substitutionUnifies) {
|
|
173
|
-
this.resolved = true;
|
|
174
|
-
}
|
|
253
|
+
if (substitutionUnifies) {
|
|
254
|
+
this.resolved = true;
|
|
175
255
|
}
|
|
176
256
|
}
|
|
177
257
|
|
|
178
258
|
this.resolved ?
|
|
179
|
-
substitutions.continue() :
|
|
259
|
+
substitutions.continue(context) :
|
|
180
260
|
substitutions.rollback(context);
|
|
181
261
|
|
|
182
262
|
if (this.resolved) {
|
|
@@ -185,11 +265,11 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
185
265
|
}
|
|
186
266
|
|
|
187
267
|
toJSON() {
|
|
188
|
-
const metavariableJSON = metavariableToMetavariableJSON(this.
|
|
189
|
-
statementJSON = statementToStatementJSON(this.
|
|
268
|
+
const metavariableJSON = metavariableToMetavariableJSON(this.targetStatement),
|
|
269
|
+
statementJSON = statementToStatementJSON(this.replacementStatement),
|
|
190
270
|
metavariable = metavariableJSON, ///
|
|
191
271
|
statement = statementJSON, ///
|
|
192
|
-
string = this.
|
|
272
|
+
string = this.getString(), ///
|
|
193
273
|
json = {
|
|
194
274
|
string,
|
|
195
275
|
statement,
|
|
@@ -202,45 +282,36 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
202
282
|
static name = "StatementSubstitution";
|
|
203
283
|
|
|
204
284
|
static fromJSON(json, context) {
|
|
205
|
-
|
|
206
|
-
statementSubstitutionNode = instantiateStatementSubstitution(string, context),
|
|
207
|
-
node = statementSubstitutionNode,
|
|
208
|
-
resolved = true,
|
|
209
|
-
statement = statementFromJSON(json, context),
|
|
210
|
-
metavariable = metavariableFromJSON(json, context),
|
|
211
|
-
substitution = null, ///
|
|
212
|
-
statementSubstitution = new StatementSubstitution(context, string, node, resolved, statement, metavariable, substitution);
|
|
213
|
-
|
|
214
|
-
return statementSubstitution;
|
|
285
|
+
///
|
|
215
286
|
}
|
|
216
287
|
|
|
217
288
|
static fromStatementAndMetavariable(statement, metavariable, context) {
|
|
218
289
|
statement = stripBracketsFromStatement(statement, context); ///
|
|
219
290
|
|
|
220
|
-
|
|
291
|
+
return literally((context) => {
|
|
221
292
|
const statementSubstitutionString = statementSubstitutionStringFromStatementAndMetavariable(statement, metavariable, context),
|
|
222
293
|
string = statementSubstitutionString, ///
|
|
223
294
|
statementSubstitutionNode = instantiateStatementSubstitution(string, context),
|
|
224
|
-
statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, context)
|
|
295
|
+
statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, context);
|
|
296
|
+
|
|
297
|
+
statementSubstitution.validate(context);
|
|
225
298
|
|
|
226
299
|
return statementSubstitution;
|
|
227
300
|
}, context);
|
|
228
|
-
|
|
229
|
-
return statementSubstitution;
|
|
230
301
|
}
|
|
231
302
|
|
|
232
303
|
static fromStatementMetavariableAndSubstitution(statement, metavariable, substitution, context) {
|
|
233
304
|
statement = stripBracketsFromStatement(statement, context); ///
|
|
234
305
|
|
|
235
|
-
|
|
306
|
+
return literally((context) => {
|
|
236
307
|
const statementSubstitutionString = statementSubstitutionStringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution),
|
|
237
308
|
string = statementSubstitutionString, ///
|
|
238
309
|
statementSubstitutionNode = instantiateStatementSubstitution(string, context),
|
|
239
|
-
statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, context)
|
|
310
|
+
statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, substitution, context);
|
|
311
|
+
|
|
312
|
+
statementSubstitution.validate(context);
|
|
240
313
|
|
|
241
314
|
return statementSubstitution;
|
|
242
315
|
}, context);
|
|
243
|
-
|
|
244
|
-
return statementSubstitution;
|
|
245
316
|
}
|
|
246
317
|
});
|
|
@@ -3,97 +3,139 @@
|
|
|
3
3
|
import Substitution from "../substitution";
|
|
4
4
|
|
|
5
5
|
import { define } from "../../elements";
|
|
6
|
+
import { literally } from "../../utilities/context";
|
|
6
7
|
import { stripBracketsFromTerm } from "../../utilities/brackets";
|
|
7
8
|
import { instantiateTermSubstitution } from "../../process/instantiate";
|
|
9
|
+
import { termSubstitutionStringFromTermAndVariable } from "../../utilities/string";
|
|
8
10
|
import { termSubstitutionFromStatementNode, termSubstitutionFromTermSubstitutionNode } from "../../utilities/element";
|
|
9
11
|
|
|
10
12
|
export default define(class TermSubstitution extends Substitution {
|
|
11
|
-
constructor(context, string, node,
|
|
13
|
+
constructor(context, string, node, targetTerm, replacementTerm) {
|
|
12
14
|
super(context, string, node);
|
|
13
15
|
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
+
this.targetTerm = targetTerm;
|
|
17
|
+
this.replacementTerm = replacementTerm;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
return this.
|
|
20
|
+
getTargetTerm() {
|
|
21
|
+
return this.targetTerm;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
return this.
|
|
24
|
+
getReplacementTerm() {
|
|
25
|
+
return this.replacementTerm;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getTargetNode() {
|
|
29
|
+
const targetTermNode = this.targetTerm.getNode(),
|
|
30
|
+
tergetNode = targetTermNode; ///
|
|
31
|
+
|
|
32
|
+
return tergetNode;
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
getReplacementNode() {
|
|
27
|
-
const
|
|
28
|
-
replacementNode =
|
|
36
|
+
const replacementTermNode = this.replacementTerm.getNode(),
|
|
37
|
+
replacementNode = replacementTermNode; ///
|
|
29
38
|
|
|
30
39
|
return replacementNode;
|
|
31
40
|
}
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
isTrivial() {
|
|
43
|
+
const targetTermEqualToReplacementTerm = this.targetTerm.isEqualTo(this.replacementTerm),
|
|
44
|
+
trivial = targetTermEqualToReplacementTerm; ///
|
|
45
|
+
|
|
46
|
+
return trivial;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
compareTerm(term, context) {
|
|
34
50
|
term = stripBracketsFromTerm(term, context); ///
|
|
35
51
|
|
|
36
|
-
const
|
|
52
|
+
const termEqualToReplacementTerm = this.replacementTerm.isEqualTo(term),
|
|
53
|
+
comparedToTerm = termEqualToReplacementTerm; ///
|
|
37
54
|
|
|
38
|
-
return
|
|
55
|
+
return comparedToTerm;
|
|
39
56
|
}
|
|
40
57
|
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
compareParameter(parameter) {
|
|
59
|
+
const targetTermComparesToParameter = this.targetTerm.compareParameter(parameter),
|
|
60
|
+
comparesToParameter = targetTermComparesToParameter; ///
|
|
61
|
+
|
|
62
|
+
return comparesToParameter;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
validate(context) {
|
|
66
|
+
let validates = false;
|
|
67
|
+
|
|
68
|
+
const termSubstitutionString = this.getString(); ///
|
|
69
|
+
|
|
70
|
+
context.trace(`Validating the '${termSubstitutionString}' term substitution...`);
|
|
71
|
+
|
|
72
|
+
const targetTermValidates = this.validateTargetTerm(context);
|
|
43
73
|
|
|
44
|
-
|
|
74
|
+
if (targetTermValidates) {
|
|
75
|
+
const replacementTermValidates = this.validateReplacementTerm(context);
|
|
45
76
|
|
|
46
|
-
|
|
47
|
-
|
|
77
|
+
if (replacementTermValidates) {
|
|
78
|
+
validates = true;
|
|
79
|
+
}
|
|
48
80
|
}
|
|
49
81
|
|
|
50
|
-
|
|
51
|
-
|
|
82
|
+
if (validates) {
|
|
83
|
+
const substititoin = this; ///
|
|
84
|
+
|
|
85
|
+
context.addSubstitution(substititoin);
|
|
52
86
|
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
context.debug(`...validated the '${termSubstitutionString}' term substitution.`);
|
|
88
|
+
}
|
|
55
89
|
|
|
56
|
-
|
|
90
|
+
return validates;
|
|
91
|
+
}
|
|
57
92
|
|
|
58
|
-
|
|
93
|
+
validateTargetTerm(context) {
|
|
94
|
+
let targetTermValidates = false;
|
|
59
95
|
|
|
60
|
-
const
|
|
96
|
+
const targetTermString = this.targetTerm.getString(),
|
|
97
|
+
termSubstitutionString = this.getString(); ///
|
|
61
98
|
|
|
62
|
-
|
|
63
|
-
if (this.variable !== null) {
|
|
64
|
-
const variableIdentifier = this.variable.getIdentifier(),
|
|
65
|
-
variablePresent = context.isVariablePresentByVariableIdentifier(variableIdentifier);
|
|
99
|
+
context.trace(`Validating the '${termSubstitutionString}' term subtitution's '${targetTermString}' target term...`);
|
|
66
100
|
|
|
67
|
-
|
|
68
|
-
const termNode = this.term.getNode(),
|
|
69
|
-
variableIdentifier = termNode.getVariableIdentifier(),
|
|
70
|
-
termVariableIdentifier = variableIdentifier, ///
|
|
71
|
-
termVariablePresent = context.isVariablePresentByVariableIdentifier(termVariableIdentifier);
|
|
101
|
+
const targetTermSingular = this.targetTerm.isSingular();
|
|
72
102
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
context.debug(`The '${termSubstitutionString}' term substitution's specific term's variable is not present.`);
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
context.debug(`The '${termSubstitutionString}' term substitution's general term is not singular.`);
|
|
83
|
-
}
|
|
103
|
+
if (targetTermSingular) {
|
|
104
|
+
targetTermValidates = this.targetTerm.validate(context, () => {
|
|
105
|
+
const verifiesAhead = true;
|
|
106
|
+
|
|
107
|
+
return verifiesAhead;
|
|
108
|
+
});
|
|
84
109
|
} else {
|
|
85
|
-
context.debug(`The '${termSubstitutionString}' term
|
|
110
|
+
context.debug(`The '${termSubstitutionString}' term subtitution's '${targetTermString}' target term is not singular.`);
|
|
86
111
|
}
|
|
87
112
|
|
|
88
|
-
if (
|
|
89
|
-
|
|
113
|
+
if (targetTermValidates) {
|
|
114
|
+
context.debug(`...validated the '${termSubstitutionString}' term subtitution's '${targetTermString}' target term...`);
|
|
115
|
+
}
|
|
90
116
|
|
|
91
|
-
|
|
117
|
+
return targetTermValidates;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
validateReplacementTerm(context) {
|
|
121
|
+
let replacementTermValidates;
|
|
92
122
|
|
|
93
|
-
|
|
123
|
+
const replacementTermString = this.replacementTerm.getString(),
|
|
124
|
+
termSubstitutionString = this.getString(); ///
|
|
125
|
+
|
|
126
|
+
context.trace(`Validating the '${termSubstitutionString}' term subtitution's '${replacementTermString}' replacement term...`);
|
|
127
|
+
|
|
128
|
+
replacementTermValidates = this.replacementTerm.validate(context, () => {
|
|
129
|
+
const validatesAhead = true;
|
|
130
|
+
|
|
131
|
+
return validatesAhead;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (replacementTermValidates) {
|
|
135
|
+
context.debug(`...validated the '${termSubstitutionString}' term subtitution's '${replacementTermString}' replacement term...`);
|
|
94
136
|
}
|
|
95
137
|
|
|
96
|
-
return
|
|
138
|
+
return replacementTermValidates;
|
|
97
139
|
}
|
|
98
140
|
|
|
99
141
|
static name = "TermSubstitution";
|
|
@@ -105,19 +147,18 @@ export default define(class TermSubstitution extends Substitution {
|
|
|
105
147
|
return termSubstitution;
|
|
106
148
|
}
|
|
107
149
|
|
|
108
|
-
static
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
150
|
+
static fromTermAndVariable(term, variable, context) {
|
|
151
|
+
term = stripBracketsFromTerm(term, context); ///
|
|
152
|
+
|
|
153
|
+
return literally((context) => {
|
|
154
|
+
const termSubstitutionString = termSubstitutionStringFromTermAndVariable(term, variable),
|
|
155
|
+
string = termSubstitutionString, ///
|
|
156
|
+
termSubstitutionNode = instantiateTermSubstitution(string, context),
|
|
157
|
+
termSubstitution = termSubstitutionFromTermSubstitutionNode(termSubstitutionNode, context);
|
|
112
158
|
|
|
113
|
-
|
|
159
|
+
termSubstitution.validate(context);
|
|
160
|
+
|
|
161
|
+
return termSubstitution;
|
|
162
|
+
}, context);
|
|
114
163
|
}
|
|
115
164
|
});
|
|
116
|
-
|
|
117
|
-
function stringFromTermAndVariable(term, variable) {
|
|
118
|
-
const termString = term.getString(),
|
|
119
|
-
variableString = variable.getString(),
|
|
120
|
-
string = `[${termString} for ${variableString}]`;
|
|
121
|
-
|
|
122
|
-
return string;
|
|
123
|
-
}
|