occam-verify-cli 0.0.1002 → 0.0.1005
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/README.md +0 -2
- package/bin/abbreviations.js +1 -3
- package/bin/action/help.js +0 -2
- package/bin/action/verify.js +4 -24
- package/bin/defaults.js +0 -2
- package/bin/main.js +3 -4
- package/bin/options.js +0 -2
- package/lib/assertion/subproof.js +106 -0
- package/lib/assignment/metavariable.js +2 -2
- package/lib/combinator.js +50 -16
- package/lib/conclusion.js +73 -14
- package/lib/context/file.js +191 -31
- package/lib/context/local.js +37 -49
- package/lib/context/release.js +42 -35
- package/lib/context/release.other.js +605 -0
- package/lib/declaration/combinator.js +83 -0
- package/lib/derivation.js +86 -0
- package/lib/equality.js +3 -11
- package/lib/index.js +1 -1
- package/lib/judgement.js +3 -10
- package/lib/label.js +58 -16
- package/lib/log.js +3 -11
- package/lib/metaType.js +31 -19
- package/lib/metavariable.js +39 -12
- package/lib/mixins/statement/qualified/unify.js +118 -0
- package/lib/mixins/statement/unify.js +57 -0
- package/lib/mixins/statement/verify.js +184 -0
- package/lib/node/statement/combinator/bracketed.js +15 -11
- package/lib/ocmbinator/bracketed.js +52 -8
- package/lib/premise.js +109 -56
- package/lib/proof.js +91 -0
- package/lib/proofStep.js +78 -25
- package/lib/reference.js +62 -16
- package/lib/rule.js +146 -26
- package/lib/ruleNames.js +5 -5
- package/lib/statement/qualified.js +127 -0
- package/lib/statement/unqualified.js +89 -0
- package/lib/statement.js +176 -0
- package/lib/subDerivation.js +86 -0
- package/lib/subproof.js +155 -0
- package/lib/substitution/frameForMetavariable.js +14 -15
- package/lib/substitution/statementForMetavariable.js +23 -24
- package/lib/substitution/termForVariable.js +11 -12
- package/lib/substitution.js +9 -2
- package/lib/substitutions.js +14 -14
- package/lib/supposition.js +92 -60
- package/lib/unifier/statementWithCombinator.js +3 -3
- package/lib/unify/metavariableWithFrame.js +2 -2
- package/lib/unify/metavariableWithStatement.js +2 -2
- package/lib/unify/metavariableWithStatementGivenSubstitution.js +2 -2
- package/lib/unify/variableWithTerm.js +2 -2
- package/lib/utilities/node.js +13 -11
- package/lib/utilities/releaseContext.js +3 -3
- package/lib/utilities/string.js +8 -2
- package/lib/utilities/subproof.js +5 -5
- package/lib/utilities/tokens.js +10 -10
- package/lib/variable.js +1 -10
- package/lib/verifier/metaLevel.js +2 -2
- package/lib/verifier/topLevel.js +5 -5
- package/lib/verify/axiom.js +3 -5
- package/lib/verify/conjecture.js +4 -7
- package/lib/verify/consequent.js +2 -3
- package/lib/verify/declaration/combinator.js +2 -14
- package/lib/verify/declaration/metavariable.js +9 -10
- package/lib/verify/files.js +4 -4
- package/lib/verify/frame.js +12 -12
- package/lib/verify/lemma.js +4 -7
- package/lib/verify/metaLemma.js +4 -7
- package/lib/verify/metatheorem.js +4 -7
- package/lib/verify/proofStep.js +2 -31
- package/lib/verify/theorem.js +4 -7
- package/package.json +4 -4
- package/src/assertion/subproof.js +84 -0
- package/src/assignment/metavariable.js +2 -2
- package/src/combinator.js +45 -15
- package/src/conclusion.js +83 -13
- package/src/context/file.js +223 -11
- package/src/context/local.js +12 -16
- package/src/context/release.js +57 -39
- package/src/context/release.other.js +547 -0
- package/src/declaration/combinator.js +44 -0
- package/src/derivation.js +50 -0
- package/src/equality.js +2 -9
- package/src/index.js +0 -1
- package/src/judgement.js +2 -8
- package/src/label.js +56 -13
- package/src/log.js +2 -9
- package/src/metaType.js +26 -14
- package/src/metavariable.js +57 -9
- package/src/mixins/statement/qualified/unify.js +186 -0
- package/src/mixins/statement/unify.js +70 -0
- package/src/mixins/statement/verify.js +274 -0
- package/src/node/statement/combinator/bracketed.js +4 -3
- package/src/ocmbinator/bracketed.js +15 -12
- package/src/premise.js +136 -44
- package/src/proof.js +58 -0
- package/src/proofStep.js +92 -22
- package/src/reference.js +58 -12
- package/src/rule.js +199 -30
- package/src/ruleNames.js +1 -1
- package/src/statement/qualified.js +104 -0
- package/src/statement/unqualified.js +60 -0
- package/src/statement.js +179 -0
- package/src/subDerivation.js +52 -0
- package/src/subproof.js +99 -0
- package/src/substitution/frameForMetavariable.js +20 -17
- package/src/substitution/statementForMetavariable.js +31 -29
- package/src/substitution/termForVariable.js +15 -14
- package/src/substitution.js +8 -0
- package/src/substitutions.js +12 -13
- package/src/supposition.js +94 -44
- package/src/unifier/statementWithCombinator.js +6 -3
- package/src/unify/metavariableWithFrame.js +1 -1
- package/src/unify/metavariableWithStatement.js +1 -1
- package/src/unify/metavariableWithStatementGivenSubstitution.js +1 -1
- package/src/unify/variableWithTerm.js +1 -1
- package/src/utilities/node.js +18 -12
- package/src/utilities/releaseContext.js +2 -2
- package/src/utilities/string.js +6 -2
- package/src/utilities/subproof.js +2 -2
- package/src/utilities/tokens.js +7 -7
- package/src/variable.js +0 -10
- package/src/verifier/metaLevel.js +3 -2
- package/src/verifier/topLevel.js +6 -4
- package/src/verify/axiom.js +1 -2
- package/src/verify/conjecture.js +2 -3
- package/src/verify/consequent.js +1 -1
- package/src/verify/declaration/combinator.js +0 -20
- package/src/verify/declaration/metavariable.js +8 -12
- package/src/verify/files.js +3 -3
- package/src/verify/frame.js +11 -11
- package/src/verify/lemma.js +2 -3
- package/src/verify/metaLemma.js +2 -3
- package/src/verify/metatheorem.js +2 -3
- package/src/verify/proofStep.js +0 -41
- package/src/verify/theorem.js +2 -3
- package/lib/tokens/combinatorStatement/bracketed.js +0 -17
- package/lib/unify/premiseWithProofStep.js +0 -41
- package/lib/unify/premisesWithProofSteps.js +0 -31
- package/lib/unify/qualifiedStatement.js +0 -136
- package/lib/unify/statementWithBracketedCombinator.js +0 -30
- package/lib/unify/statementWithCombinator.js +0 -29
- package/lib/unify/statementWithCombinators.js +0 -31
- package/lib/unify/statementWithMetaType.js +0 -24
- package/lib/verify/conclusion.js +0 -39
- package/lib/verify/derivation.js +0 -31
- package/lib/verify/label.js +0 -37
- package/lib/verify/labels.js +0 -28
- package/lib/verify/premise.js +0 -45
- package/lib/verify/premises.js +0 -28
- package/lib/verify/proof.js +0 -34
- package/lib/verify/rule.js +0 -56
- package/lib/verify/statement/qualified.js +0 -41
- package/lib/verify/statement/unqualified.js +0 -45
- package/lib/verify/statement.js +0 -219
- package/lib/verify/statementAsCombinator.js +0 -33
- package/lib/verify/statementGivenMetaType.js +0 -52
- package/lib/verify/subproof.js +0 -34
- package/lib/verify/supposition.js +0 -45
- package/lib/verify/suppositions.js +0 -28
- package/src/tokens/combinatorStatement/bracketed.js +0 -10
- package/src/unify/premiseWithProofStep.js +0 -54
- package/src/unify/premisesWithProofSteps.js +0 -23
- package/src/unify/qualifiedStatement.js +0 -208
- package/src/unify/statementWithBracketedCombinator.js +0 -22
- package/src/unify/statementWithCombinator.js +0 -22
- package/src/unify/statementWithCombinators.js +0 -23
- package/src/unify/statementWithMetaType.js +0 -14
- package/src/verify/conclusion.js +0 -40
- package/src/verify/derivation.js +0 -23
- package/src/verify/label.js +0 -34
- package/src/verify/labels.js +0 -17
- package/src/verify/premise.js +0 -49
- package/src/verify/premises.js +0 -17
- package/src/verify/proof.js +0 -31
- package/src/verify/rule.js +0 -71
- package/src/verify/statement/qualified.js +0 -40
- package/src/verify/statement/unqualified.js +0 -49
- package/src/verify/statement.js +0 -312
- package/src/verify/statementAsCombinator.js +0 -27
- package/src/verify/statementGivenMetaType.js +0 -52
- package/src/verify/subproof.js +0 -32
- package/src/verify/supposition.js +0 -49
- package/src/verify/suppositions.js +0 -17
package/src/statement.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import shim from "./shim";
|
|
4
|
+
import unifyMixins from "./mixins/statement/unify";
|
|
5
|
+
import verifyMixins from "./mixins/statement/verify";
|
|
6
|
+
import statementAsCombinatorVerifier from "./verifier/statementAsCombinator";
|
|
7
|
+
|
|
8
|
+
import { statementNodeFromStatementString } from "./utilities/node";
|
|
9
|
+
import { FRAME_META_TYPE_NAME, REFERENCE_META_TYPE_NAME, STATEMENT_META_TYPE_NAME } from "./metaTypeNames";
|
|
10
|
+
|
|
11
|
+
class Statement {
|
|
12
|
+
constructor(string, node) {
|
|
13
|
+
this.string = string;
|
|
14
|
+
this.node = node;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getString() {
|
|
18
|
+
return this.string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getNode() {
|
|
22
|
+
return this.node;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
isEqualTo(statement) {
|
|
26
|
+
const node = statement.getNode(),
|
|
27
|
+
matches = this.node.match(node),
|
|
28
|
+
equalTo = matches; ///
|
|
29
|
+
|
|
30
|
+
return equalTo;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
verify(assignments, stated, localContext) {
|
|
34
|
+
let verified = false;
|
|
35
|
+
|
|
36
|
+
const statement = this, ///
|
|
37
|
+
statementString = this.string; ///
|
|
38
|
+
|
|
39
|
+
localContext.trace(`Verifying the '${statementString}' statement...`);
|
|
40
|
+
|
|
41
|
+
if (!verified) {
|
|
42
|
+
verified = unifyMixins.some((unifyMixin) => { ///
|
|
43
|
+
const unified = unifyMixin(statement, assignments, stated, localContext);
|
|
44
|
+
|
|
45
|
+
if (unified) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!verified) {
|
|
52
|
+
verified = verifyMixins.some((verifyMixin) => {
|
|
53
|
+
const verified = verifyMixin(statement, assignments, stated, localContext);
|
|
54
|
+
|
|
55
|
+
if (verified) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (verified) {
|
|
62
|
+
localContext.debug(`...verified the '${statementString}' statement.`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return verified;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
unifyWithMetaType(metaType, assignments, stated, localContext) {
|
|
69
|
+
let unifiedWithMetaType;
|
|
70
|
+
|
|
71
|
+
const verifiedGivenMetaType = this.verifyGivenMetaType(metaType, assignments, stated, localContext);
|
|
72
|
+
|
|
73
|
+
unifiedWithMetaType = verifiedGivenMetaType; ///
|
|
74
|
+
|
|
75
|
+
return unifiedWithMetaType;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
verifyAsCombinator(localContext) {
|
|
79
|
+
let verifiedAsCombinator;
|
|
80
|
+
|
|
81
|
+
const statementNode = this.node, ///
|
|
82
|
+
statementString = this.string; ///
|
|
83
|
+
|
|
84
|
+
localContext.trace(`Verifying the '${statementString}' statement as a combinator...`);
|
|
85
|
+
|
|
86
|
+
verifiedAsCombinator = statementAsCombinatorVerifier.verifyStatement(statementNode, localContext);
|
|
87
|
+
|
|
88
|
+
if (verifiedAsCombinator) {
|
|
89
|
+
localContext.debug(`...verified the '${statementString}' statement as a combinator.`, statementNode);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return verifiedAsCombinator;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
verifyGivenMetaType(metaType, assignments, stated, localContext) {
|
|
96
|
+
let verifiedGivenMetaType;
|
|
97
|
+
|
|
98
|
+
const metaTypeName = metaType.getName();
|
|
99
|
+
|
|
100
|
+
switch (metaTypeName) {
|
|
101
|
+
case FRAME_META_TYPE_NAME:
|
|
102
|
+
case REFERENCE_META_TYPE_NAME: {
|
|
103
|
+
debugger
|
|
104
|
+
|
|
105
|
+
// verifiedGivenMetaType = false;
|
|
106
|
+
//
|
|
107
|
+
// const metavariableNode = metavariableNodeQuery(statementNode);
|
|
108
|
+
//
|
|
109
|
+
// if (metavariableNode !== null) {
|
|
110
|
+
// const metavariableName = metavariableNameFromMetavariableNode(metavariableNode),
|
|
111
|
+
// metavariable = localContext.findMetavariableByMetavariableName(metavariableName);
|
|
112
|
+
//
|
|
113
|
+
// if (metavariable !== null) {
|
|
114
|
+
// const metavariableMetaType = metavariable.getMetaType();
|
|
115
|
+
//
|
|
116
|
+
// if (metavariableMetaType === metaType) {
|
|
117
|
+
// verifiedGivenMetaType = true;
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
120
|
+
// }
|
|
121
|
+
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
case STATEMENT_META_TYPE_NAME: {
|
|
126
|
+
const verified = this.verify(assignments, stated, localContext)
|
|
127
|
+
|
|
128
|
+
verifiedGivenMetaType = verified; ///
|
|
129
|
+
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return verifiedGivenMetaType;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
toJSON() {
|
|
138
|
+
const string = this.string, ///
|
|
139
|
+
json = {
|
|
140
|
+
string
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
return json;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static fromJSON(json, fileContext) {
|
|
147
|
+
const { string } = json,
|
|
148
|
+
statementString = string, ///
|
|
149
|
+
lexer = fileContext.getLexer(),
|
|
150
|
+
parser = fileContext.getParser(),
|
|
151
|
+
statementNode = statementNodeFromStatementString(statementString, lexer, parser),
|
|
152
|
+
node = statementNode, ///
|
|
153
|
+
statement = new Statement(string, node);
|
|
154
|
+
|
|
155
|
+
return statement;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static fromStatementNode(statementNode, localContext) {
|
|
159
|
+
let statement;
|
|
160
|
+
|
|
161
|
+
if (statementNode !== null) {
|
|
162
|
+
const node = statementNode, ///
|
|
163
|
+
string = localContext.nodeAsString(node);
|
|
164
|
+
|
|
165
|
+
statement = new Statement(string, node);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return statement;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
Object.assign(shim, {
|
|
173
|
+
Statement
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
Object.assign(Statement.prototype, unifyMixins);
|
|
177
|
+
|
|
178
|
+
export default Statement;
|
|
179
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import shim from "./shim";
|
|
4
|
+
|
|
5
|
+
import { last } from "./utilities/array";
|
|
6
|
+
import { nodesQuery } from "./utilities/query";
|
|
7
|
+
|
|
8
|
+
const proofStepNodesQuery = nodesQuery("/subDerivation/proofStep|lastProofStep");
|
|
9
|
+
|
|
10
|
+
export default class SubDerivation {
|
|
11
|
+
constructor(proofSteps) {
|
|
12
|
+
this.proofSteps = proofSteps;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getProofSteps() {
|
|
16
|
+
return this.proofSteps;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getLastProofStep() {
|
|
20
|
+
const lastProofStep = last(this.proofSteps);
|
|
21
|
+
|
|
22
|
+
return lastProofStep;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
verify(substitutions, localContext) {
|
|
26
|
+
let verified;
|
|
27
|
+
|
|
28
|
+
verified = this.proofSteps.every((proofStep) => { ///
|
|
29
|
+
const proofStepVerified = proofStep.verify(substitutions, localContext);
|
|
30
|
+
|
|
31
|
+
if (proofStepVerified) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return verified;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static fromSubDerivationNode(subDerivationNode, fileContext) {
|
|
40
|
+
const { ProofStep } = shim,
|
|
41
|
+
proofStepNodes = proofStepNodesQuery(subDerivationNode),
|
|
42
|
+
proofSteps = proofStepNodes.map((proofStepNode) => {
|
|
43
|
+
const proofStep = ProofStep.fromProofStepNode(proofStepNode, fileContext);
|
|
44
|
+
|
|
45
|
+
return proofStep;
|
|
46
|
+
}),
|
|
47
|
+
subDerivation = new SubDerivation(proofSteps);
|
|
48
|
+
|
|
49
|
+
return subDerivation;
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/subproof.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Supposition from "./supposition";
|
|
4
|
+
import LocalContext from "./context/local";
|
|
5
|
+
import SubDerivation from "./subDerivation";
|
|
6
|
+
|
|
7
|
+
import { nodeQuery, nodesQuery } from "./utilities/query";
|
|
8
|
+
import {subproofNodeAsSubproofString, subproofStringFromSubproofNode} from "./utilities/subproof";
|
|
9
|
+
|
|
10
|
+
const suppositionNodesQuery = nodesQuery("/subproof/supposition"),
|
|
11
|
+
subDerivationNodeQuery = nodeQuery("/subproof/subDerivation");
|
|
12
|
+
|
|
13
|
+
export default class Subproof {
|
|
14
|
+
constructor(string, suppositions, subDerivation) {
|
|
15
|
+
this.string = string;
|
|
16
|
+
this.suppositions = suppositions;
|
|
17
|
+
this.subDerivation = subDerivation;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getString() {
|
|
21
|
+
return this.string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getNode() {
|
|
25
|
+
return this.node;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getSuppositions() {
|
|
29
|
+
return this.suppositions;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getSubDerivation() {
|
|
33
|
+
return this.subDerivation;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getLastProofStep() { return this.subDerivation.getLastProofStep(); }
|
|
37
|
+
|
|
38
|
+
getStatements() {
|
|
39
|
+
const lastProofStep = this.getLastProofStep(),
|
|
40
|
+
suppositionStatements = this.suppositions.map((supposition) => {
|
|
41
|
+
const suppositionStatement = supposition.getStatement();
|
|
42
|
+
|
|
43
|
+
return suppositionStatement;
|
|
44
|
+
}),
|
|
45
|
+
lastProofStepStatement = lastProofStep.getStatement(),
|
|
46
|
+
statements = [
|
|
47
|
+
...suppositionStatements,
|
|
48
|
+
lastProofStepStatement
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
return statements;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
verify(substitutions, localContext) {
|
|
56
|
+
let subproofVerified = false;
|
|
57
|
+
|
|
58
|
+
localContext = LocalContext.fromLocalContext(localContext); ///
|
|
59
|
+
|
|
60
|
+
const suppositionsVerified = this.suppositions.every((supposition) => {
|
|
61
|
+
const suppositionVerified = supposition.verify(localContext);
|
|
62
|
+
|
|
63
|
+
if (suppositionVerified) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (suppositionsVerified) {
|
|
69
|
+
const subDerivationVerified = this.subDerivation.verify(substitutions, localContext);
|
|
70
|
+
|
|
71
|
+
if (subDerivationVerified) {
|
|
72
|
+
subproofVerified = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return subproofVerified;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static fromSubproofNode(subproofNode, fileContext) {
|
|
80
|
+
let subproof = null;
|
|
81
|
+
|
|
82
|
+
if (subproofNode !== null) {
|
|
83
|
+
const subproofString = subproofStringFromSubproofNode(subproofNode, fileContext),
|
|
84
|
+
suppositionNodes = suppositionNodesQuery(subproofNode),
|
|
85
|
+
subDerivationNode = subDerivationNodeQuery(subproofNode),
|
|
86
|
+
string = subproofString, ///
|
|
87
|
+
suppositions = suppositionNodes.map((suppositionNode) => {
|
|
88
|
+
const supposition = Supposition.fromSuppositionNode(suppositionNode, fileContext);
|
|
89
|
+
|
|
90
|
+
return supposition;
|
|
91
|
+
}),
|
|
92
|
+
subDerivation = SubDerivation.fromSubDerivationNode(subDerivationNode, fileContext);
|
|
93
|
+
|
|
94
|
+
subproof = new Subproof(string, suppositions, subDerivation);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return subproof;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -9,8 +9,8 @@ const substitutionFrameNodeQuery = nodeQuery("/substitution/frame!"),
|
|
|
9
9
|
substitutionMetavariableNodeQuery = nodeQuery("/substitution/metavariable!");
|
|
10
10
|
|
|
11
11
|
export default class FrameForMetavariableSubstitution extends Substitution {
|
|
12
|
-
constructor(frameNode, metavariableNode) {
|
|
13
|
-
super();
|
|
12
|
+
constructor(string, frameNode, metavariableNode) {
|
|
13
|
+
super(string);
|
|
14
14
|
|
|
15
15
|
this.frameNode = frameNode;
|
|
16
16
|
this.metavariableNode = metavariableNode;
|
|
@@ -69,17 +69,7 @@ export default class FrameForMetavariableSubstitution extends Substitution {
|
|
|
69
69
|
return metavariableNodeMatches;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
const frameNodeB = this.frameNode, ///
|
|
74
|
-
frameStringB = localContextB.nodeAsString(frameNodeB),
|
|
75
|
-
metavariableNodeA = this.metavariableNode, ///
|
|
76
|
-
metavariableStringA = localContextA.nodeAsString(metavariableNodeA),
|
|
77
|
-
string = `[${frameStringB} for ${metavariableStringA}]`;
|
|
78
|
-
|
|
79
|
-
return string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static fromSubstitutionNode(substitutionNode) {
|
|
72
|
+
static fromSubstitutionNode(substitutionNode, localContextA, localContextB) {
|
|
83
73
|
let frameForMetavariableSubstitution = null;
|
|
84
74
|
|
|
85
75
|
const substitutionFrameNode = substitutionFrameNodeQuery(substitutionNode);
|
|
@@ -87,16 +77,18 @@ export default class FrameForMetavariableSubstitution extends Substitution {
|
|
|
87
77
|
if (substitutionFrameNode !== null) {
|
|
88
78
|
const substitutionMetavariableNode = substitutionMetavariableNodeQuery(substitutionNode),
|
|
89
79
|
metavariableNode = substitutionMetavariableNode, ///
|
|
90
|
-
frameNode = substitutionFrameNode
|
|
80
|
+
frameNode = substitutionFrameNode, ///
|
|
81
|
+
string = stringFromFrameNodeAndMetavariableNode(frameNode, metavariableNode, localContextA, localContextB);
|
|
91
82
|
|
|
92
|
-
|
|
83
|
+
frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode);
|
|
93
84
|
}
|
|
94
85
|
|
|
95
86
|
return frameForMetavariableSubstitution;
|
|
96
87
|
}
|
|
97
88
|
|
|
98
|
-
static fromFrameNodeAndMetavariableNode(frameNode, metavariableNode) {
|
|
99
|
-
const
|
|
89
|
+
static fromFrameNodeAndMetavariableNode(frameNode, metavariableNode, localContextA, localContextB) {
|
|
90
|
+
const string = stringFromFrameNodeAndMetavariableNode(frameNode, metavariableNode, localContextA, localContextB),
|
|
91
|
+
frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode);
|
|
100
92
|
|
|
101
93
|
return frameForMetavariableSubstitution;
|
|
102
94
|
}
|
|
@@ -146,3 +138,14 @@ function transformMetavariableNode(metavariableNode, substitutions) {
|
|
|
146
138
|
|
|
147
139
|
return transformedMetavariableNode;
|
|
148
140
|
}
|
|
141
|
+
|
|
142
|
+
function stringFromFrameNodeAndMetavariableNode(frameNode, metavariableNode, localContextA, localContextB) {
|
|
143
|
+
const frameNodeB = frameNode, ///
|
|
144
|
+
frameStringB = localContextB.nodeAsString(frameNodeB),
|
|
145
|
+
metavariableNodeA = metavariableNode, ///
|
|
146
|
+
metavariableStringA = localContextA.nodeAsString(metavariableNodeA),
|
|
147
|
+
string = `[${frameStringB} for ${metavariableStringA}]`;
|
|
148
|
+
|
|
149
|
+
return string;
|
|
150
|
+
}
|
|
151
|
+
|
|
@@ -7,8 +7,8 @@ import FrameForMetavariableSubstitution from "../substitution/frameForMetavariab
|
|
|
7
7
|
import { stripBracketsFromStatement } from "../utilities/brackets";
|
|
8
8
|
|
|
9
9
|
export default class StatementForMetavariableSubstitution extends Substitution {
|
|
10
|
-
constructor(statementNode, metavariableNode, substitution) {
|
|
11
|
-
super();
|
|
10
|
+
constructor(string, statementNode, metavariableNode, substitution) {
|
|
11
|
+
super(string);
|
|
12
12
|
|
|
13
13
|
this.statementNode = statementNode;
|
|
14
14
|
this.metavariableNode = metavariableNode;
|
|
@@ -53,49 +53,32 @@ export default class StatementForMetavariableSubstitution extends Substitution {
|
|
|
53
53
|
return metavariableNodeMatches;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
let string;
|
|
58
|
-
|
|
59
|
-
const statementNodeB = this.statementNode, ///
|
|
60
|
-
statementStringB = localContextB.nodeAsString(statementNodeB),
|
|
61
|
-
metavariableNodeA = this.metavariableNode, ///
|
|
62
|
-
metavariableStringA = localContextA.nodeAsString(metavariableNodeA);
|
|
63
|
-
|
|
64
|
-
if (this.substitution === null) {
|
|
65
|
-
string = `[${statementStringB} for ${metavariableStringA}]`;
|
|
66
|
-
} else {
|
|
67
|
-
const substitutionString = this.substitution.asString(localContextA, localContextA);
|
|
68
|
-
|
|
69
|
-
string = `[${statementStringB} for ${metavariableStringA}${substitutionString}]`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return string;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
static fromStatementNodeAndMetavariableNode(statementNode, metavariableNode) {
|
|
56
|
+
static fromStatementNodeAndMetavariableNode(statementNode, metavariableNode, localContextA, localContextB) {
|
|
76
57
|
statementNode = stripBracketsFromStatement(statementNode); ///
|
|
77
58
|
|
|
78
59
|
const substitution = null,
|
|
79
|
-
|
|
60
|
+
string = stringFromStatementNodeMetavariableNodeAndSubstitution(statementNode, metavariableNode, substitution, localContextA, localContextB),
|
|
61
|
+
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, statementNode, metavariableNode, substitution);
|
|
80
62
|
|
|
81
63
|
return statementForMetavariableSubstitution;
|
|
82
64
|
}
|
|
83
65
|
|
|
84
|
-
static fromStatementNodeMetavariableNodeAndSubstitutionNode(statementNode, metavariableNode, substitutionNode) {
|
|
66
|
+
static fromStatementNodeMetavariableNodeAndSubstitutionNode(statementNode, metavariableNode, substitutionNode, localContextA, localContextB) {
|
|
85
67
|
statementNode = stripBracketsFromStatement(statementNode); ///
|
|
86
68
|
|
|
87
|
-
const substitution = substitutionFromSubstitutionNode(substitutionNode),
|
|
88
|
-
|
|
69
|
+
const substitution = substitutionFromSubstitutionNode(substitutionNode, localContextA, localContextB),
|
|
70
|
+
string = stringFromStatementNodeMetavariableNodeAndSubstitution(statementNode, metavariableNode, substitution, localContextA, localContextB),
|
|
71
|
+
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, statementNode, metavariableNode, substitution);
|
|
89
72
|
|
|
90
73
|
return statementForMetavariableSubstitution;
|
|
91
74
|
}
|
|
92
75
|
}
|
|
93
76
|
|
|
94
|
-
function substitutionFromSubstitutionNode(substitutionNode) {
|
|
77
|
+
function substitutionFromSubstitutionNode(substitutionNode, localContextA, localContextB) {
|
|
95
78
|
let substitution = null;
|
|
96
79
|
|
|
97
80
|
if (substitution === null) {
|
|
98
|
-
const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitutionNode(substitutionNode);
|
|
81
|
+
const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitutionNode(substitutionNode, localContextA, localContextB);
|
|
99
82
|
|
|
100
83
|
if (termForVariableSubstitution !== null) {
|
|
101
84
|
substitution = termForVariableSubstitution; ///
|
|
@@ -103,7 +86,7 @@ function substitutionFromSubstitutionNode(substitutionNode) {
|
|
|
103
86
|
}
|
|
104
87
|
|
|
105
88
|
if (substitution === null) {
|
|
106
|
-
const frameForMetavariableSubstitution = FrameForMetavariableSubstitution.fromSubstitutionNode(substitutionNode);
|
|
89
|
+
const frameForMetavariableSubstitution = FrameForMetavariableSubstitution.fromSubstitutionNode(substitutionNode, localContextA, localContextB);
|
|
107
90
|
|
|
108
91
|
if (frameForMetavariableSubstitution !== null) {
|
|
109
92
|
substitution = frameForMetavariableSubstitution; ///
|
|
@@ -112,3 +95,22 @@ function substitutionFromSubstitutionNode(substitutionNode) {
|
|
|
112
95
|
|
|
113
96
|
return substitution;
|
|
114
97
|
}
|
|
98
|
+
|
|
99
|
+
function stringFromStatementNodeMetavariableNodeAndSubstitution(statementNode, metavariableNode, substitution, localContextA, localContextB) {
|
|
100
|
+
let string;
|
|
101
|
+
|
|
102
|
+
const statementNodeB = statementNode, ///
|
|
103
|
+
statementStringB = localContextB.nodeAsString(statementNodeB),
|
|
104
|
+
metavariableNodeA = metavariableNode, ///
|
|
105
|
+
metavariableStringA = localContextA.nodeAsString(metavariableNodeA);
|
|
106
|
+
|
|
107
|
+
if (substitution === null) {
|
|
108
|
+
string = `[${statementStringB} for ${metavariableStringA}]`;
|
|
109
|
+
} else {
|
|
110
|
+
const substitutionString = substitution.asString(localContextA, localContextA);
|
|
111
|
+
|
|
112
|
+
string = `[${statementStringB} for ${metavariableStringA}${substitutionString}]`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return string;
|
|
116
|
+
}
|
|
@@ -10,8 +10,8 @@ const termVariableNodeQuery = nodeQuery("/term/variable!"),
|
|
|
10
10
|
substitutionsVariableNodeQuery = nodeQuery("/substitution/variable!");
|
|
11
11
|
|
|
12
12
|
export default class TermForVariableSubstitution extends Substitution {
|
|
13
|
-
constructor(termNode, variableNode) {
|
|
14
|
-
super();
|
|
13
|
+
constructor(string, termNode, variableNode) {
|
|
14
|
+
super(string);
|
|
15
15
|
|
|
16
16
|
this.termNode = termNode;
|
|
17
17
|
this.variableNode = variableNode;
|
|
@@ -88,16 +88,6 @@ export default class TermForVariableSubstitution extends Substitution {
|
|
|
88
88
|
return unifiedWithEquivalence;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
asString(localContextA, localContextB) {
|
|
92
|
-
const termNodeB = this.termNode, ///
|
|
93
|
-
termStringB = localContextB.nodeAsString(termNodeB),
|
|
94
|
-
variableNodeA = this.variableNode, ///
|
|
95
|
-
variableStringA = localContextA.nodeAsString(variableNodeA),
|
|
96
|
-
string = `[${termStringB} for ${variableStringA}]`;
|
|
97
|
-
|
|
98
|
-
return string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
91
|
static fromSubstitutionNode(substitutionNode) {
|
|
102
92
|
let termForVariableSubstitution = null;
|
|
103
93
|
|
|
@@ -117,10 +107,11 @@ export default class TermForVariableSubstitution extends Substitution {
|
|
|
117
107
|
return termForVariableSubstitution;
|
|
118
108
|
}
|
|
119
109
|
|
|
120
|
-
static fromTernNodeAndVariableNode(termNode, variableNode) {
|
|
110
|
+
static fromTernNodeAndVariableNode(termNode, variableNode, localContextA, localContextB) {
|
|
121
111
|
termNode = stripBracketsFromTerm(termNode); ///
|
|
122
112
|
|
|
123
|
-
const
|
|
113
|
+
const string = stringFromTermNodeAndVariableNode(termNode, variableNode, localContextA, localContextB),
|
|
114
|
+
termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode);
|
|
124
115
|
|
|
125
116
|
return termForVariableSubstitution;
|
|
126
117
|
}
|
|
@@ -170,3 +161,13 @@ function transformVariableNode(variableNode, substitutions) {
|
|
|
170
161
|
|
|
171
162
|
return transformedVariableNode;
|
|
172
163
|
}
|
|
164
|
+
|
|
165
|
+
function stringFromTermNodeAndVariableNode(termNode, variableNode, localContextA, localContextB) {
|
|
166
|
+
const termNodeB = termNode, ///
|
|
167
|
+
termStringB = localContextB.nodeAsString(termNodeB),
|
|
168
|
+
variableNodeA = variableNode, ///
|
|
169
|
+
variableStringA = localContextA.nodeAsString(variableNodeA),
|
|
170
|
+
string = `[${termStringB} for ${variableStringA}]`;
|
|
171
|
+
|
|
172
|
+
return string;
|
|
173
|
+
}
|
package/src/substitution.js
CHANGED
package/src/substitutions.js
CHANGED
|
@@ -177,16 +177,15 @@ export default class Substitutions {
|
|
|
177
177
|
return complexSubstitution;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
addSubstitution(substitution,
|
|
180
|
+
addSubstitution(substitution, localContext) {
|
|
181
181
|
this.array.push(substitution);
|
|
182
182
|
|
|
183
|
-
const
|
|
184
|
-
substitutionString = substitution.asString(localContextA, localContextB);
|
|
183
|
+
const substitutionString = substitution.getString();
|
|
185
184
|
|
|
186
|
-
|
|
185
|
+
localContext.trace(`Added the ${substitutionString} substitution.`);
|
|
187
186
|
}
|
|
188
187
|
|
|
189
|
-
removeSubstitution(substitution,
|
|
188
|
+
removeSubstitution(substitution, localContext) {
|
|
190
189
|
const substitutionA = substitution; ///
|
|
191
190
|
|
|
192
191
|
prune(this.array, (substitution) => {
|
|
@@ -198,15 +197,15 @@ export default class Substitutions {
|
|
|
198
197
|
});
|
|
199
198
|
|
|
200
199
|
const substitutionNode = substitution.getNode(),
|
|
201
|
-
substitutionString = substitution.
|
|
200
|
+
substitutionString = substitution.getString();
|
|
202
201
|
|
|
203
|
-
|
|
202
|
+
localContext.trace(`Removed the ${substitutionString} substitution.`, substitutionNode);
|
|
204
203
|
}
|
|
205
204
|
|
|
206
|
-
unifyWithEquivalences(equivalences,
|
|
205
|
+
unifyWithEquivalences(equivalences, localContext) {
|
|
207
206
|
const unifiedWithEquivalences = this.everySubstitution((substitution) => {
|
|
208
207
|
const substitutions = this, ///
|
|
209
|
-
substitutionUnifiedWithEquivalence = substitution.unifyWithEquivalences(equivalences, substitutions,
|
|
208
|
+
substitutionUnifiedWithEquivalence = substitution.unifyWithEquivalences(equivalences, substitutions, localContext);
|
|
210
209
|
|
|
211
210
|
if (substitutionUnifiedWithEquivalence) {
|
|
212
211
|
return true;
|
|
@@ -232,7 +231,7 @@ export default class Substitutions {
|
|
|
232
231
|
];
|
|
233
232
|
}
|
|
234
233
|
|
|
235
|
-
rollback(
|
|
234
|
+
rollback(localContext) {
|
|
236
235
|
const array = [
|
|
237
236
|
...this.array
|
|
238
237
|
];
|
|
@@ -240,7 +239,7 @@ export default class Substitutions {
|
|
|
240
239
|
rightDifference(this.savedArray, array);
|
|
241
240
|
|
|
242
241
|
array.forEach((substitution) => {
|
|
243
|
-
this.removeSubstitution(substitution,
|
|
242
|
+
this.removeSubstitution(substitution, localContext);
|
|
244
243
|
});
|
|
245
244
|
|
|
246
245
|
this.array = [
|
|
@@ -254,9 +253,9 @@ export default class Substitutions {
|
|
|
254
253
|
this.savedArray = null;
|
|
255
254
|
}
|
|
256
255
|
|
|
257
|
-
|
|
256
|
+
getString(localContextA, localContextB) {
|
|
258
257
|
let string = this.array.reduce((string, substitution) => {
|
|
259
|
-
const substitutionString = substitution.
|
|
258
|
+
const substitutionString = substitution.getString(localContextA, localContextB);
|
|
260
259
|
|
|
261
260
|
string = (string === null) ?
|
|
262
261
|
substitutionString :
|