occam-verify-cli 1.0.388 → 1.0.396
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/action/verify.js +3 -3
- package/lib/context/file.js +8 -7
- package/lib/context/local.js +23 -57
- package/lib/context/temporary.js +705 -0
- package/lib/mixins/statement/verify.js +38 -16
- package/lib/mixins/step/unify.js +3 -3
- package/lib/node/substitution/frame.js +23 -1
- package/lib/node/substitution/term.js +23 -1
- package/lib/ontology/assertion/contained.js +77 -35
- package/lib/ontology/assertion/defined.js +76 -34
- package/lib/ontology/assertion/property.js +71 -29
- package/lib/ontology/assertion/satisfies.js +70 -22
- package/lib/ontology/assertion/subproof.js +95 -41
- package/lib/ontology/assertion/type.js +74 -18
- package/lib/ontology/assertion.js +66 -0
- package/lib/ontology/axiom.js +8 -11
- package/lib/ontology/combinator/bracketed.js +17 -3
- package/lib/ontology/combinator.js +17 -3
- package/lib/ontology/conclusion.js +38 -9
- package/lib/ontology/constructor/bracketed.js +17 -3
- package/lib/ontology/constructor.js +17 -3
- package/lib/ontology/declaration.js +27 -2
- package/lib/ontology/deduction.js +38 -9
- package/lib/ontology/frame.js +50 -13
- package/lib/ontology/hypothesis.js +11 -11
- package/lib/ontology/judgement.js +1 -1
- package/lib/ontology/label.js +5 -6
- package/lib/ontology/metavariable.js +11 -12
- package/lib/ontology/premise.js +47 -17
- package/lib/ontology/procedureCall.js +15 -15
- package/lib/ontology/procedureReference.js +1 -1
- package/lib/ontology/proof.js +2 -2
- package/lib/ontology/reference.js +4 -5
- package/lib/ontology/rule.js +68 -69
- package/lib/ontology/section.js +2 -2
- package/lib/ontology/signature.js +2 -2
- package/lib/ontology/statement.js +9 -1
- package/lib/ontology/step.js +37 -24
- package/lib/ontology/subproof.js +11 -11
- package/lib/ontology/substitution/frame.js +69 -21
- package/lib/ontology/substitution/reference.js +24 -9
- package/lib/ontology/substitution/statement.js +99 -79
- package/lib/ontology/substitution/term.js +89 -29
- package/lib/ontology/substitution.js +37 -30
- package/lib/ontology/supposition.js +56 -25
- package/lib/ontology/term.js +4 -3
- package/lib/ontology/topLevelAssertion.js +15 -15
- package/lib/ontology/topLevelMetaAssertion.js +2 -2
- package/lib/ontology/variable.js +42 -14
- package/lib/substitutions.js +25 -25
- package/lib/unifier/intrinsicLevel.js +14 -7
- package/lib/unifier/metaLevel.js +25 -17
- package/lib/utilities/brackets.js +4 -21
- package/lib/utilities/context.js +6 -6
- package/lib/utilities/json.js +24 -1
- package/lib/utilities/metavariable.js +18 -0
- package/lib/utilities/substitutions.js +3 -3
- package/lib/utilities/unification.js +10 -16
- package/lib/utilities/variable.js +30 -0
- package/package.json +2 -2
- package/src/action/verify.js +2 -2
- package/src/context/file.js +8 -7
- package/src/context/local.js +13 -61
- package/src/context/temporary.js +394 -0
- package/src/mixins/statement/verify.js +60 -23
- package/src/mixins/step/unify.js +2 -2
- package/src/node/substitution/frame.js +26 -0
- package/src/node/substitution/term.js +26 -0
- package/src/ontology/assertion/contained.js +12 -23
- package/src/ontology/assertion/defined.js +12 -23
- package/src/ontology/assertion/property.js +7 -20
- package/src/ontology/assertion/satisfies.js +7 -16
- package/src/ontology/assertion/subproof.js +36 -42
- package/src/ontology/assertion/type.js +10 -11
- package/src/ontology/assertion.js +23 -0
- package/src/ontology/axiom.js +7 -16
- package/src/ontology/combinator/bracketed.js +2 -0
- package/src/ontology/combinator.js +2 -0
- package/src/ontology/conclusion.js +51 -10
- package/src/ontology/constructor/bracketed.js +2 -0
- package/src/ontology/constructor.js +2 -0
- package/src/ontology/declaration.js +34 -1
- package/src/ontology/deduction.js +51 -10
- package/src/ontology/frame.js +58 -21
- package/src/ontology/hypothesis.js +8 -8
- package/src/ontology/judgement.js +1 -1
- package/src/ontology/label.js +2 -7
- package/src/ontology/metavariable.js +12 -15
- package/src/ontology/premise.js +64 -21
- package/src/ontology/procedureCall.js +14 -14
- package/src/ontology/procedureReference.js +2 -2
- package/src/ontology/proof.js +1 -1
- package/src/ontology/reference.js +1 -6
- package/src/ontology/rule.js +76 -80
- package/src/ontology/section.js +1 -1
- package/src/ontology/signature.js +1 -1
- package/src/ontology/statement.js +6 -0
- package/src/ontology/step.js +43 -26
- package/src/ontology/subproof.js +8 -8
- package/src/ontology/substitution/frame.js +72 -26
- package/src/ontology/substitution/reference.js +8 -6
- package/src/ontology/substitution/statement.js +93 -77
- package/src/ontology/substitution/term.js +108 -42
- package/src/ontology/substitution.js +27 -22
- package/src/ontology/supposition.js +70 -24
- package/src/ontology/term.js +5 -5
- package/src/ontology/topLevelAssertion.js +14 -16
- package/src/ontology/topLevelMetaAssertion.js +1 -1
- package/src/ontology/variable.js +64 -17
- package/src/substitutions.js +25 -25
- package/src/unifier/intrinsicLevel.js +18 -8
- package/src/unifier/metaLevel.js +35 -21
- package/src/utilities/brackets.js +3 -29
- package/src/utilities/context.js +5 -5
- package/src/utilities/json.js +28 -0
- package/src/utilities/metavariable.js +13 -0
- package/src/utilities/substitutions.js +2 -4
- package/src/utilities/unification.js +8 -24
- package/src/utilities/variable.js +22 -0
|
@@ -94,6 +94,8 @@ export default define(class Statement {
|
|
|
94
94
|
return frameContained;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
matchStatementNode(statementNode) { return this.node.match(statementNode); }
|
|
98
|
+
|
|
97
99
|
verify(assignments, stated, context) {
|
|
98
100
|
let verifies;
|
|
99
101
|
|
|
@@ -111,6 +113,10 @@ export default define(class Statement {
|
|
|
111
113
|
});
|
|
112
114
|
|
|
113
115
|
if (verifies) {
|
|
116
|
+
const statement = this; ///
|
|
117
|
+
|
|
118
|
+
context.addStatement(statement);
|
|
119
|
+
|
|
114
120
|
context.debug(`...verified the '${statementString}' statement.`, this.node);
|
|
115
121
|
}
|
|
116
122
|
|
package/src/ontology/step.js
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
import ontology from "../ontology";
|
|
4
4
|
import unifyMixins from "../mixins/step/unify";
|
|
5
5
|
import Substitutions from "../substitutions";
|
|
6
|
+
import TemporaryContext from "../context/temporary";
|
|
6
7
|
import equationalUnifier from "../unifier/equantional";
|
|
7
8
|
|
|
8
9
|
import { define } from "../ontology";
|
|
9
10
|
import { propertyAssertionFromStatement } from "../utilities/context";
|
|
10
11
|
|
|
11
12
|
export default define(class Step {
|
|
12
|
-
constructor(node, string, statement, reference, satisfiesAssertion) {
|
|
13
|
+
constructor(context, node, string, statement, reference, satisfiesAssertion) {
|
|
14
|
+
this.context = context;
|
|
13
15
|
this.node = node;
|
|
14
16
|
this.string = string;
|
|
15
17
|
this.statement = statement;
|
|
@@ -17,6 +19,10 @@ export default define(class Step {
|
|
|
17
19
|
this.satisfiesAssertion = satisfiesAssertion;
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
getContext() {
|
|
23
|
+
return this.context;
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
getNode() {
|
|
21
27
|
return this.node;
|
|
22
28
|
}
|
|
@@ -74,31 +80,13 @@ export default define(class Step {
|
|
|
74
80
|
return termAndPropertyRelationMatch;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
unify(substitutions, context) {
|
|
78
|
-
let unifies;
|
|
79
|
-
|
|
80
|
-
const stepString = this.string; ///
|
|
81
|
-
|
|
82
|
-
context.trace(`Unifying the '${stepString}' step...`, this.node);
|
|
83
|
-
|
|
84
|
-
unifies = unifyMixins.some((unifyMixin) => {
|
|
85
|
-
const unifies = unifyMixin(this.statement, this.reference, this.satisfiesAssertion, substitutions, context);
|
|
86
|
-
|
|
87
|
-
if (unifies) {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
if (unifies) {
|
|
93
|
-
context.debug(`...unified the '${stepString}' step.`, this.node);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return unifies;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
83
|
verify(substitutions, assignments, context) {
|
|
100
84
|
let verifies = false;
|
|
101
85
|
|
|
86
|
+
const temporaryContext = TemporaryContext.fromNothing(context);
|
|
87
|
+
|
|
88
|
+
context = temporaryContext; ///
|
|
89
|
+
|
|
102
90
|
const stepString = this.string; ///
|
|
103
91
|
|
|
104
92
|
context.trace(`Verifying the '${stepString}' step...`, this.node);
|
|
@@ -136,12 +124,38 @@ export default define(class Step {
|
|
|
136
124
|
}
|
|
137
125
|
|
|
138
126
|
if (verifies) {
|
|
127
|
+
this.context = context;
|
|
128
|
+
|
|
139
129
|
context.debug(`...verified the '${stepString}' step.`, this.node);
|
|
140
130
|
}
|
|
141
131
|
|
|
142
132
|
return verifies;
|
|
143
133
|
}
|
|
144
134
|
|
|
135
|
+
unify(substitutions, context) {
|
|
136
|
+
let unifies;
|
|
137
|
+
|
|
138
|
+
context = this.context;
|
|
139
|
+
|
|
140
|
+
const stepString = this.string; ///
|
|
141
|
+
|
|
142
|
+
context.trace(`Unifying the '${stepString}' step...`, this.node);
|
|
143
|
+
|
|
144
|
+
unifies = unifyMixins.some((unifyMixin) => {
|
|
145
|
+
const unifies = unifyMixin(this.statement, this.reference, this.satisfiesAssertion, substitutions, context);
|
|
146
|
+
|
|
147
|
+
if (unifies) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
if (unifies) {
|
|
153
|
+
context.debug(`...unified the '${stepString}' step.`, this.node);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return unifies;
|
|
157
|
+
}
|
|
158
|
+
|
|
145
159
|
equateWithStatement(statement, context) {
|
|
146
160
|
let statementEquates;
|
|
147
161
|
|
|
@@ -196,7 +210,7 @@ export default define(class Step {
|
|
|
196
210
|
node = null,
|
|
197
211
|
reference = null,
|
|
198
212
|
satisfiesAssertion = null,
|
|
199
|
-
step = new Step(node, string, statement, reference, satisfiesAssertion);
|
|
213
|
+
step = new Step(context, node, string, statement, reference, satisfiesAssertion);
|
|
200
214
|
|
|
201
215
|
return step;
|
|
202
216
|
}
|
|
@@ -213,9 +227,12 @@ export default define(class Step {
|
|
|
213
227
|
string = context.nodeAsString(node),
|
|
214
228
|
statement = Statement.fromStepNode(stepNode, context),
|
|
215
229
|
reference = Reference.fromStepNode(stepNode, context),
|
|
216
|
-
satisfiesAssertion = SatisfiesAssertion.fromStepNode(stepNode, context)
|
|
230
|
+
satisfiesAssertion = SatisfiesAssertion.fromStepNode(stepNode, context),
|
|
231
|
+
temporaryContext = null;
|
|
232
|
+
|
|
233
|
+
context = temporaryContext; ///
|
|
217
234
|
|
|
218
|
-
step = new Step(node, string, statement, reference, satisfiesAssertion)
|
|
235
|
+
step = new Step(context, node, string, statement, reference, satisfiesAssertion)
|
|
219
236
|
}
|
|
220
237
|
|
|
221
238
|
return step;
|
package/src/ontology/subproof.js
CHANGED
|
@@ -8,21 +8,21 @@ import { define } from "../ontology";
|
|
|
8
8
|
import { subproofStringFromSubproofNode } from "../utilities/subproof";
|
|
9
9
|
|
|
10
10
|
export default define(class Subproof {
|
|
11
|
-
constructor(
|
|
12
|
-
this.node = node;
|
|
11
|
+
constructor(string, node, suppositions, subDerivation) {
|
|
13
12
|
this.string = string;
|
|
13
|
+
this.node = node;
|
|
14
14
|
this.suppositions = suppositions;
|
|
15
15
|
this.subDerivation = subDerivation;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
getNode() {
|
|
19
|
-
return this.node;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
18
|
getString() {
|
|
23
19
|
return this.string;
|
|
24
20
|
}
|
|
25
21
|
|
|
22
|
+
getNode() {
|
|
23
|
+
return this.node;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
26
|
getSuppositions() {
|
|
27
27
|
return this.suppositions;
|
|
28
28
|
}
|
|
@@ -66,7 +66,7 @@ export default define(class Subproof {
|
|
|
66
66
|
verify(substitutions, assignments, context) {
|
|
67
67
|
let subproofVerifies = false;
|
|
68
68
|
|
|
69
|
-
const localContext = LocalContext.
|
|
69
|
+
const localContext = LocalContext.fromNothing(context); ///
|
|
70
70
|
|
|
71
71
|
context = localContext; ///
|
|
72
72
|
|
|
@@ -146,7 +146,7 @@ export default define(class Subproof {
|
|
|
146
146
|
node = subproofNode, ///
|
|
147
147
|
string = subproofString; ///
|
|
148
148
|
|
|
149
|
-
subproof = new Subproof(
|
|
149
|
+
subproof = new Subproof(string, node, suppositions, subDerivation);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
return subproof;
|
|
@@ -7,8 +7,8 @@ import FrameSubstitutionPartialContext from "../../context/partial/substitution/
|
|
|
7
7
|
import { define } from "../../ontology";
|
|
8
8
|
|
|
9
9
|
export default define(class FrameSubstitution extends Substitution {
|
|
10
|
-
constructor(string, node, tokens, frame, metavariable) {
|
|
11
|
-
super(string, node, tokens);
|
|
10
|
+
constructor(context, string, node, tokens, frame, metavariable) {
|
|
11
|
+
super(context, string, node, tokens);
|
|
12
12
|
|
|
13
13
|
this.frame = frame;
|
|
14
14
|
this.metavariable = metavariable;
|
|
@@ -22,12 +22,6 @@ export default define(class FrameSubstitution extends Substitution {
|
|
|
22
22
|
return this.metavariable;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
isFrameEqualTo(frame) { return this.frame.isEqualTo(frame); }
|
|
26
|
-
|
|
27
|
-
isMetavariableEqualTo(metavariable) { return this.metavariable.isEqualTo(metavariable); }
|
|
28
|
-
|
|
29
|
-
matchParameter(parameter) { return this.metavariable.matchParameter(parameter); }
|
|
30
|
-
|
|
31
25
|
getReplacementNode() {
|
|
32
26
|
const frameNode = this.frame.getNode(),
|
|
33
27
|
replacementNode = frameNode; ///
|
|
@@ -35,28 +29,80 @@ export default define(class FrameSubstitution extends Substitution {
|
|
|
35
29
|
return replacementNode;
|
|
36
30
|
}
|
|
37
31
|
|
|
38
|
-
|
|
32
|
+
isFrameEqualToFrame(frame) { return this.frame.isEqualTo(frame); }
|
|
33
|
+
|
|
34
|
+
isMetavariableEqualToMetavariable(metavariable) { return this.metavariable.isEqualTo(metavariable); }
|
|
35
|
+
|
|
36
|
+
matchParameter(parameter) { return this.metavariable.matchParameter(parameter); }
|
|
37
|
+
|
|
38
|
+
verify(context) {
|
|
39
|
+
let verifies = false;
|
|
40
|
+
|
|
41
|
+
const frameSubstitutionString = this.string; ///
|
|
42
|
+
|
|
43
|
+
context.trace(`Verifiying the '${frameSubstitutionString}' frame substitutin...`);
|
|
44
|
+
|
|
45
|
+
const frameSimple = this.frame.isSimple();
|
|
46
|
+
|
|
47
|
+
if (frameSimple) {
|
|
48
|
+
if (this.metavariable === null) {
|
|
49
|
+
context.debug(`The specific frame is not simple.`);
|
|
50
|
+
} else {
|
|
51
|
+
const metavariablePresent = context.isMetavariablePresent(this.metavariable);
|
|
52
|
+
|
|
53
|
+
if (metavariablePresent) {
|
|
54
|
+
const metavariable = this.frame.getMetavariable(),
|
|
55
|
+
metavariablePresent = context.isMetavariablePresent(metavariable);
|
|
56
|
+
|
|
57
|
+
if (metavariablePresent) {
|
|
58
|
+
verifies = true;
|
|
59
|
+
} else {
|
|
60
|
+
const metavariableString = metavariable.getString();
|
|
61
|
+
|
|
62
|
+
context.debug(`The '${metavariableString}' metavariable is not present.`);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
const metavariableString = this.metavariable.getString();
|
|
66
|
+
|
|
67
|
+
context.debug(`The '${metavariableString}' metavariable is not present.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
context.debug(`The general frame is not simple.`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (verifies) {
|
|
75
|
+
const substititoin = this; ///
|
|
76
|
+
|
|
77
|
+
context.addSubstitution(substititoin);
|
|
78
|
+
|
|
79
|
+
context.debug(`...verified the '${frameSubstitutionString}' frame substitutin.`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return verifies;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static name = "FrameSubstitution";
|
|
86
|
+
|
|
87
|
+
static fromStatement(statement, context) {
|
|
39
88
|
let frameSubstitution = null;
|
|
40
89
|
|
|
41
|
-
const
|
|
90
|
+
const statementNode = statement.getNode(),
|
|
91
|
+
frameSubstitutionNode = statementNode.getFrameSubstitutionNode();
|
|
42
92
|
|
|
43
93
|
if (frameSubstitutionNode !== null) {
|
|
44
|
-
const
|
|
94
|
+
const { Frame, Metavariable } = ontology,
|
|
45
95
|
firstFrameNode = frameSubstitutionNode.getFirstFrameNode(),
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
string = stringFromFrameAndMetavariable(frame, metavariable);
|
|
57
|
-
|
|
58
|
-
frameSubstitution = new FrameSubstitution(string, node, tokens, frame, metavariable);
|
|
59
|
-
}
|
|
96
|
+
lastMetavariableNode = frameSubstitutionNode.getLastMetavariableNode(),
|
|
97
|
+
metavariableNode = lastMetavariableNode, ///
|
|
98
|
+
frameNode = firstFrameNode, ///
|
|
99
|
+
node = frameSubstitutionNode, ///
|
|
100
|
+
tokens = context.nodeAsTokens(node),
|
|
101
|
+
string = context.nodeAsString(node),
|
|
102
|
+
frame = Frame.fromFrameNode(frameNode, context),
|
|
103
|
+
metavariable = Metavariable.fromMetavariableNode(metavariableNode, context);
|
|
104
|
+
|
|
105
|
+
frameSubstitution = new FrameSubstitution(context, string, node, tokens, frame, metavariable);
|
|
60
106
|
}
|
|
61
107
|
|
|
62
108
|
return frameSubstitution;
|
|
@@ -69,7 +115,7 @@ export default define(class FrameSubstitution extends Substitution {
|
|
|
69
115
|
frameSubstitutionPartialContext = FrameSubstitutionPartialContext.fromStringLexerAndParser(string, lexer, parser),
|
|
70
116
|
node = frameSubstitutionPartialContext.getNode(),
|
|
71
117
|
tokens = frameSubstitutionPartialContext.getTokens(),
|
|
72
|
-
frameSubstitution = new FrameSubstitution(string, node, tokens, frame, metavariable);
|
|
118
|
+
frameSubstitution = new FrameSubstitution(context, string, node, tokens, frame, metavariable);
|
|
73
119
|
|
|
74
120
|
return frameSubstitution;
|
|
75
121
|
}
|
|
@@ -6,8 +6,8 @@ import ReferenceSubstitutionPartialContext from "../../context/partial/substitut
|
|
|
6
6
|
import { define } from "../../ontology";
|
|
7
7
|
|
|
8
8
|
export default define(class ReferenceSubstitution extends Substitution {
|
|
9
|
-
constructor(string, node, tokens, reference, metavariable) {
|
|
10
|
-
super(string, node, tokens);
|
|
9
|
+
constructor(context, string, node, tokens, reference, metavariable) {
|
|
10
|
+
super(context, string, node, tokens);
|
|
11
11
|
|
|
12
12
|
this.reference = reference;
|
|
13
13
|
this.metavariable = metavariable;
|
|
@@ -21,12 +21,14 @@ export default define(class ReferenceSubstitution extends Substitution {
|
|
|
21
21
|
return this.metavariable;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
const
|
|
24
|
+
isReferenceEqualToReference(reference) {
|
|
25
|
+
const referenceEqualToReference = this.reference.isEqualTo(reference);
|
|
26
26
|
|
|
27
|
-
return
|
|
27
|
+
return referenceEqualToReference;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
static name = "ReferenceSubstitution";
|
|
31
|
+
|
|
30
32
|
static fromReferenceAndMetavariable(reference, metavariable, context) {
|
|
31
33
|
const string = stringFromReferenceAndMetavariable(reference, metavariable),
|
|
32
34
|
lexer = context.getLexer(),
|
|
@@ -34,7 +36,7 @@ export default define(class ReferenceSubstitution extends Substitution {
|
|
|
34
36
|
referenceSubstitutionPartialContext = ReferenceSubstitutionPartialContext.fromStringLexerAndParser(string, lexer, parser),
|
|
35
37
|
node = referenceSubstitutionPartialContext.getNode(),
|
|
36
38
|
tokens = referenceSubstitutionPartialContext.getTokens(),
|
|
37
|
-
referenceSubstitution = new ReferenceSubstitution(string, node, tokens, reference, metavariable);
|
|
39
|
+
referenceSubstitution = new ReferenceSubstitution(context, string, node, tokens, reference, metavariable);
|
|
38
40
|
|
|
39
41
|
return referenceSubstitution;
|
|
40
42
|
}
|
|
@@ -10,8 +10,8 @@ import { stripBracketsFromStatement } from "../../utilities/brackets";
|
|
|
10
10
|
import { statementFromJSON, statementToStatementJSON, metavariableFromJSON, metavariableToMetavariableJSON } from "../../utilities/json";
|
|
11
11
|
|
|
12
12
|
export default define(class StatementSubstitution extends Substitution {
|
|
13
|
-
constructor(string, node, tokens, resolved, statement, metavariable, substitution) {
|
|
14
|
-
super(string, node, tokens);
|
|
13
|
+
constructor(context, string, node, tokens, resolved, statement, metavariable, substitution) {
|
|
14
|
+
super(context, string, node, tokens);
|
|
15
15
|
|
|
16
16
|
this.resolved = resolved;
|
|
17
17
|
this.statement = statement;
|
|
@@ -35,125 +35,139 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
35
35
|
return this.substitution;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
getReplacementNode() {
|
|
39
|
+
const statementNode = this.statement.getNode(),
|
|
40
|
+
replacementNode = statementNode; ///
|
|
41
|
+
|
|
42
|
+
return replacementNode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
isSimple() {
|
|
46
|
+
const simple = (this.substitution === null);
|
|
47
|
+
|
|
48
|
+
return simple;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
isStatementEqualToStatement(statement, context) {
|
|
39
52
|
statement = stripBracketsFromStatement(statement, context); ///
|
|
40
53
|
|
|
41
|
-
const
|
|
54
|
+
const statementEqualToStatement = this.statement.isEqualTo(statement);
|
|
42
55
|
|
|
43
|
-
return
|
|
56
|
+
return statementEqualToStatement;
|
|
44
57
|
}
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
isMetavariableEqualToMetavariable(metavariable) { return this.metavariable.isEqualTo(metavariable); }
|
|
47
60
|
|
|
48
|
-
|
|
49
|
-
let
|
|
61
|
+
isSubstitutionEqualToSubstitution(substitution) {
|
|
62
|
+
let substitutionEqualToSubstitution;
|
|
50
63
|
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
} else if ((substitution === null) && (this.substitution === null)) {
|
|
54
|
-
substitutionEqualTo = true;
|
|
55
|
-
} else if ((substitution !== null) && (this.substitution === null)) {
|
|
56
|
-
substitutionEqualTo = false;
|
|
57
|
-
} else if ((substitution === null) && (this.substitution !== null)) {
|
|
58
|
-
substitutionEqualTo = false;
|
|
64
|
+
if (this.substitution === null) {
|
|
65
|
+
substitutionEqualToSubstitution = (substitution === null);
|
|
59
66
|
} else {
|
|
60
|
-
|
|
67
|
+
if (substitution === null) {
|
|
68
|
+
substitutionEqualToSubstitution = false;
|
|
69
|
+
} else {
|
|
70
|
+
substitutionEqualToSubstitution = this.substitution.isEqualToSubstitution(substitution);
|
|
71
|
+
}
|
|
61
72
|
}
|
|
62
73
|
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
isSimple() {
|
|
67
|
-
const simple = (this.substitution === null);
|
|
68
|
-
|
|
69
|
-
return simple;
|
|
74
|
+
return substitutionEqualToSubstitution;
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
matchParameter(parameter) { return this.metavariable.matchParameter(parameter); }
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
replacementNode = statementNode; ///
|
|
77
|
-
|
|
78
|
-
return replacementNode;
|
|
79
|
-
}
|
|
79
|
+
unifyStatement(statement, context) {
|
|
80
|
+
let substitution = null;
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
const substitutions = Substitutions.fromNothing(),
|
|
83
|
+
generalContext = context; ///
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable);
|
|
85
|
+
context = this.getContext();
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
const specificContext = context, ///
|
|
88
|
+
statementUnifies = statement.unifyStatement(this.statement, substitutions, generalContext, specificContext);
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
if (statementUnifies) {
|
|
91
|
+
const substitutionsNonTrivialLength = substitutions.getNonTrivialLength();
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
if (substitutionsNonTrivialLength === 1) {
|
|
94
|
+
const firstSubstitution = substitutions.getFirstSubstitution();
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
specificContext.debug(`...resolved the ${substitutionString} substitution.`);
|
|
96
|
+
substitution = firstSubstitution; ///
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
|
|
100
|
+
return substitution;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
unifySubstitution(substitution, substitutions, context) {
|
|
104
|
+
const frame = context.getFrame(),
|
|
105
|
+
generalSubstitution = this.substitution, ///
|
|
106
|
+
specificSubstitution = substitution, ///
|
|
107
|
+
generalSubstitutionString = generalSubstitution.getString(),
|
|
108
|
+
specificSubstitutionString = specificSubstitution.getString();
|
|
103
109
|
|
|
104
|
-
|
|
110
|
+
context.trace(`Unifying the '${specificSubstitutionString}' substitution with the '${generalSubstitutionString}' substitution...`);
|
|
105
111
|
|
|
106
|
-
|
|
112
|
+
let substitutionContext;
|
|
107
113
|
|
|
108
|
-
|
|
109
|
-
specificSubstitution = this.unifyStatement(statement, specificContext, specificContext); ///
|
|
114
|
+
substitutionContext = this.substitution.getContext();
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
substitutions.snapshot();
|
|
116
|
+
const generalContext = substitutionContext; ///
|
|
113
117
|
|
|
114
|
-
|
|
115
|
-
specificSubstitutionString = specificSubstitution.getString();
|
|
118
|
+
substitutionContext = substitution.getContext();
|
|
116
119
|
|
|
117
|
-
|
|
120
|
+
const specificContext = substitutionContext; ///
|
|
118
121
|
|
|
119
|
-
|
|
122
|
+
specificContext.addFrame(frame);
|
|
120
123
|
|
|
124
|
+
substitutions.snapshot();
|
|
121
125
|
|
|
122
|
-
|
|
123
|
-
specificContext.trace(`...unified the '${specificSubstitutionString}' substitution with the '${generalSubstitutionString}' substitution.`);
|
|
124
|
-
}
|
|
126
|
+
const substitutionUnifies = unifySubstitution(generalSubstitution, specificSubstitution, substitutions, generalContext, specificContext);
|
|
125
127
|
|
|
126
|
-
|
|
127
|
-
substitutions.continue() :
|
|
128
|
-
substitutions.rollback(specificContext);
|
|
128
|
+
specificContext.removeFrame(frame);
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
substitutionUnifies ?
|
|
131
|
+
substitutions.continue() :
|
|
132
|
+
substitutions.rollback(context);
|
|
132
133
|
|
|
133
|
-
if (
|
|
134
|
-
|
|
134
|
+
if (substitutionUnifies) {
|
|
135
|
+
context.trace(`...unified the '${specificSubstitutionString}' substitution with the '${generalSubstitutionString}' substitution.`);
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
return
|
|
138
|
+
return substitutionUnifies;
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
resolve(substitutions, context) {
|
|
142
|
+
const substitutionString = this.string; ///
|
|
142
143
|
|
|
143
|
-
|
|
144
|
-
statementUnifies = this.statement.unifyStatement(statement, substitutions, generalContext, specificContext);
|
|
144
|
+
context.trace(`Resolving the ${substitutionString} substitution...`);
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
const metavariable = this.getMetavariable(),
|
|
147
|
+
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable);
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
if (simpleSubstitution !== null) {
|
|
150
|
+
let substitution;
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
substitution = simpleSubstitution; ///
|
|
153
|
+
|
|
154
|
+
const context = substitution.getContext(),
|
|
155
|
+
statement = substitution.getStatement();
|
|
156
|
+
|
|
157
|
+
substitution = this.unifyStatement(statement, context);
|
|
158
|
+
|
|
159
|
+
if (substitution !== null) {
|
|
160
|
+
const substitutionUnifies = this.unifySubstitution(substitution, substitutions, context);
|
|
161
|
+
|
|
162
|
+
if (substitutionUnifies) {
|
|
163
|
+
this.resolved = true;
|
|
164
|
+
}
|
|
153
165
|
}
|
|
154
166
|
}
|
|
155
167
|
|
|
156
|
-
|
|
168
|
+
if (this.resolved) {
|
|
169
|
+
context.debug(`...resolved the ${substitutionString} substitution.`);
|
|
170
|
+
}
|
|
157
171
|
}
|
|
158
172
|
|
|
159
173
|
toJSON() {
|
|
@@ -171,6 +185,8 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
171
185
|
return json;
|
|
172
186
|
}
|
|
173
187
|
|
|
188
|
+
static name = "StatementSubstitution";
|
|
189
|
+
|
|
174
190
|
static fromJSON(json, context) {
|
|
175
191
|
const { string } = json,
|
|
176
192
|
lexer = context.getLexer(),
|
|
@@ -182,7 +198,7 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
182
198
|
statement = statementFromJSON(json, context),
|
|
183
199
|
metavariable = metavariableFromJSON(json, context),
|
|
184
200
|
substitution = null, ///
|
|
185
|
-
statementSubstitution = new StatementSubstitution(string, node, tokens, resolved, statement, metavariable, substitution);
|
|
201
|
+
statementSubstitution = new StatementSubstitution(context, string, node, tokens, resolved, statement, metavariable, substitution);
|
|
186
202
|
|
|
187
203
|
return statementSubstitution;
|
|
188
204
|
}
|
|
@@ -198,7 +214,7 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
198
214
|
tokens = statementSubstitutionPartialContext.getTokens(),
|
|
199
215
|
resolved = true,
|
|
200
216
|
substitution = null,
|
|
201
|
-
statementSubstitution = new StatementSubstitution(string, node, tokens, resolved, statement, metavariable, substitution);
|
|
217
|
+
statementSubstitution = new StatementSubstitution(context, string, node, tokens, resolved, statement, metavariable, substitution);
|
|
202
218
|
|
|
203
219
|
return statementSubstitution;
|
|
204
220
|
}
|
|
@@ -213,7 +229,7 @@ export default define(class StatementSubstitution extends Substitution {
|
|
|
213
229
|
node = statementSubstitutionPartialContext.getNode(),
|
|
214
230
|
tokens = statementSubstitutionPartialContext.getTokens(),
|
|
215
231
|
resolved = false,
|
|
216
|
-
statementSubstitution = new StatementSubstitution(string, node, tokens, resolved, statement, metavariable, substitution);
|
|
232
|
+
statementSubstitution = new StatementSubstitution(context, string, node, tokens, resolved, statement, metavariable, substitution);
|
|
217
233
|
|
|
218
234
|
return statementSubstitution;
|
|
219
235
|
}
|