occam-verify-cli 0.0.1003 → 0.0.1006
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/bin/utilities/releaseContext.js +9 -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 +74 -14
- package/lib/context/file.js +191 -31
- package/lib/context/local.js +37 -49
- package/lib/context/release.js +25 -81
- 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 -55
- 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 -61
- 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 +5 -6
- 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 +1 -1
- package/src/assertion/subproof.js +84 -0
- package/src/assignment/metavariable.js +2 -2
- package/src/combinator.js +45 -15
- package/src/conclusion.js +85 -13
- package/src/context/file.js +223 -11
- package/src/context/local.js +12 -16
- package/src/context/release.js +31 -100
- 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 +138 -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 +96 -51
- 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 +5 -8
- 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/rule.js
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import Label from "./label";
|
|
4
|
+
import Proof from "./proof";
|
|
5
|
+
import Premise from "./premise";
|
|
6
|
+
import Conclusion from "./conclusion";
|
|
7
|
+
import LocalContext from "./context/local";
|
|
3
8
|
import Substitutions from "./substitutions";
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
9
|
+
|
|
10
|
+
import { reverse, correlate } from "./utilities/array";
|
|
11
|
+
import { nodeQuery, nodesQuery } from "./utilities/query";
|
|
12
|
+
|
|
13
|
+
const proofNodeQuery = nodeQuery("/rule/proof"),
|
|
14
|
+
labelNodesQuery = nodesQuery("/rule/label"),
|
|
15
|
+
premiseNodesQuery = nodesQuery("/rule/premise"),
|
|
16
|
+
conclusionNodeQuery = nodeQuery("/rule/conclusion");
|
|
7
17
|
|
|
8
18
|
export default class Rule {
|
|
9
|
-
constructor(labels, premises, conclusion,
|
|
19
|
+
constructor(fileContext, labels, premises, conclusion, proof) {
|
|
20
|
+
this.fileContext = fileContext;
|
|
10
21
|
this.labels = labels;
|
|
11
22
|
this.premises = premises;
|
|
12
23
|
this.conclusion = conclusion;
|
|
13
|
-
this.
|
|
24
|
+
this.proof = proof;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getFileContext() {
|
|
28
|
+
return this.fileContext;
|
|
14
29
|
}
|
|
15
30
|
|
|
16
31
|
getLabels() {
|
|
@@ -25,50 +40,204 @@ export default class Rule {
|
|
|
25
40
|
return this.conclusion;
|
|
26
41
|
}
|
|
27
42
|
|
|
28
|
-
|
|
29
|
-
return this.
|
|
43
|
+
getProof() {
|
|
44
|
+
return this.proof;
|
|
30
45
|
}
|
|
31
46
|
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
matchMetavariableNode(metavariableNode) {
|
|
48
|
+
const metavariableNodeMatches = this.labels.some((label) => {
|
|
49
|
+
const metavariableNodeMatches = label.matchMetavariableNode(metavariableNode);
|
|
50
|
+
|
|
51
|
+
if (metavariableNodeMatches) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
34
55
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
premisesA = this.premises,
|
|
38
|
-
proofStepsB = proofSteps, ///
|
|
39
|
-
fileContextA = this.fileContext, ///
|
|
40
|
-
localContextB = localContext, ///
|
|
41
|
-
premisesUnified = unifyPremisesWithProofSteps(premisesA, proofStepsB, substitutions, fileContextA, localContextB);
|
|
56
|
+
return metavariableNodeMatches;
|
|
57
|
+
}
|
|
42
58
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
conclusionUnified = unifyConclusionWithStatement(conclusionA, statementNode, substitutions, fileContextA, localContextB);
|
|
59
|
+
unifyStatement(statement, localContext) {
|
|
60
|
+
let statementUnified = false;
|
|
46
61
|
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
const proofSteps = localContext.getProofSteps(),
|
|
63
|
+
substitutions = Substitutions.fromNothing(),
|
|
64
|
+
proofStepsUnified = this.unifyProofSteps(proofSteps, substitutions, localContext);
|
|
49
65
|
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
if (proofStepsUnified) {
|
|
67
|
+
statementUnified = this.conclusion.unifyStatement(statement, substitutions, localContext);
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
return statementUnified;
|
|
55
71
|
}
|
|
56
72
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const metavariableNodeMatches = label.matchMetavariableNode(metavariableNode);
|
|
73
|
+
unifyProofSteps(proofSteps, substitutions, localContext) {
|
|
74
|
+
let proofStepsUnified;
|
|
60
75
|
|
|
61
|
-
|
|
76
|
+
let premises = this.premises;
|
|
77
|
+
|
|
78
|
+
premises = reverse(premises); ///
|
|
79
|
+
|
|
80
|
+
proofSteps = reverse(proofSteps); ///
|
|
81
|
+
|
|
82
|
+
proofStepsUnified = correlate(premises, proofSteps, (premise, proofStep) => {
|
|
83
|
+
const proofStepUnified = premise.unifyProofStep(proofStep, substitutions, localContext);
|
|
84
|
+
|
|
85
|
+
if (proofStepUnified) {
|
|
62
86
|
return true;
|
|
63
87
|
}
|
|
64
88
|
});
|
|
65
89
|
|
|
66
|
-
return
|
|
90
|
+
return proofStepsUnified;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
verify(fileContext) {
|
|
94
|
+
let verified = false;
|
|
95
|
+
|
|
96
|
+
const labelsString = labelsStringFromLabels(this.labels);
|
|
97
|
+
|
|
98
|
+
fileContext.trace(`Verifying the '${labelsString}' rule...`);
|
|
99
|
+
|
|
100
|
+
const labelsVerified = this.labels.every((label) => {
|
|
101
|
+
const labelVVerified = label.verify(fileContext);
|
|
102
|
+
|
|
103
|
+
if (labelVVerified) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (labelsVerified) {
|
|
109
|
+
const localContext = LocalContext.fromFileContext(fileContext),
|
|
110
|
+
premisesVerified = this.premises.every((premise) => {
|
|
111
|
+
const premiseVerified = premise.verify(localContext);
|
|
112
|
+
|
|
113
|
+
if (premiseVerified) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (premisesVerified) {
|
|
119
|
+
const conclusionVerified = this.conclusion.verify(localContext);
|
|
120
|
+
|
|
121
|
+
if (conclusionVerified) {
|
|
122
|
+
let proofVerified = true; ///
|
|
123
|
+
|
|
124
|
+
if (this.proof !== null) {
|
|
125
|
+
const substitutions = Substitutions.fromNothing();
|
|
126
|
+
|
|
127
|
+
proofVerified = this.proof.verify(substitutions, this.conclusion, localContext);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (proofVerified) {
|
|
131
|
+
const rule = this; ///
|
|
132
|
+
|
|
133
|
+
fileContext.addRule(rule);
|
|
134
|
+
|
|
135
|
+
verified = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (verified) {
|
|
142
|
+
fileContext.debug(`...verified the '${labelsString}' rule.`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return verified;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
toJSON() {
|
|
149
|
+
const labelsJSON = this.labels.map((label) => {
|
|
150
|
+
const labelJSON = label.toJSON();
|
|
151
|
+
|
|
152
|
+
return labelJSON;
|
|
153
|
+
}),
|
|
154
|
+
premisesJSON = this.premises.map((premise) => {
|
|
155
|
+
const premiseJSON = premise.toJSON();
|
|
156
|
+
|
|
157
|
+
return premiseJSON;
|
|
158
|
+
}),
|
|
159
|
+
conclusionJSON = this.conclusion.toJSON(),
|
|
160
|
+
labels = labelsJSON, ///
|
|
161
|
+
premises = premisesJSON, ///
|
|
162
|
+
conclusion = conclusionJSON, ///
|
|
163
|
+
json = {
|
|
164
|
+
labels,
|
|
165
|
+
premises,
|
|
166
|
+
conclusion
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return json;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static fromJSON(json, fileContext) {
|
|
173
|
+
let rule;
|
|
174
|
+
|
|
175
|
+
let { labels } = json;
|
|
176
|
+
|
|
177
|
+
const labelsJSON = labels; ///
|
|
178
|
+
|
|
179
|
+
labels = labelsJSON.map((labelJSON) => {
|
|
180
|
+
const json = labelJSON, ///
|
|
181
|
+
label = Label.fromJSON(json, fileContext);
|
|
182
|
+
|
|
183
|
+
return label;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
let { premises } = json;
|
|
187
|
+
|
|
188
|
+
const premisesJSON = premises; ///
|
|
189
|
+
|
|
190
|
+
premises = premisesJSON.map((premiseJSON) => {
|
|
191
|
+
const json = premiseJSON, ///
|
|
192
|
+
premise = Premise.fromJSON(json, fileContext);
|
|
193
|
+
|
|
194
|
+
return premise;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
let { conclusion } = json;
|
|
198
|
+
|
|
199
|
+
const conclusionJSON = conclusion; ///
|
|
200
|
+
|
|
201
|
+
json = conclusionJSON; ///
|
|
202
|
+
|
|
203
|
+
conclusion = Conclusion.fromJSON(json, fileContext);
|
|
204
|
+
|
|
205
|
+
const proof = null;
|
|
206
|
+
|
|
207
|
+
rule = new Rule(fileContext, labels, premises, conclusion, proof);
|
|
208
|
+
|
|
209
|
+
return rule;
|
|
67
210
|
}
|
|
68
211
|
|
|
69
|
-
static
|
|
70
|
-
const
|
|
212
|
+
static fromRuleNode(ruleNode, fileContext) {
|
|
213
|
+
const proofNode = proofNodeQuery(ruleNode),
|
|
214
|
+
labelNodes = labelNodesQuery(ruleNode),
|
|
215
|
+
premiseNodes = premiseNodesQuery(ruleNode),
|
|
216
|
+
conclusionNode = conclusionNodeQuery(ruleNode),
|
|
217
|
+
labels = labelNodes.map((labelNode) => {
|
|
218
|
+
const label = Label.fromLabelNode(labelNode, fileContext);
|
|
219
|
+
|
|
220
|
+
return label;
|
|
221
|
+
}),
|
|
222
|
+
premises = premiseNodes.map((premiseNode) => {
|
|
223
|
+
const premise = Premise.fromPremiseNode(premiseNode, fileContext);
|
|
224
|
+
|
|
225
|
+
return premise;
|
|
226
|
+
}),
|
|
227
|
+
conclusion = Conclusion.fromConclusionNode(conclusionNode, fileContext),
|
|
228
|
+
proof = Proof.fromProofNode(proofNode, fileContext),
|
|
229
|
+
rule = new Rule(fileContext, labels, premises, conclusion, proof);
|
|
71
230
|
|
|
72
231
|
return rule;
|
|
73
232
|
}
|
|
74
233
|
}
|
|
234
|
+
|
|
235
|
+
function labelsStringFromLabels(labels) {
|
|
236
|
+
const labelsString = labels.map((label) => {
|
|
237
|
+
const labelString = label.getString();
|
|
238
|
+
|
|
239
|
+
return labelString;
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
return labelsString;
|
|
243
|
+
}
|
package/src/ruleNames.js
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Statement from "../statement";
|
|
4
|
+
import Reference from "../reference";
|
|
5
|
+
import unifyMixins from "../mixins/statement/qualified/unify";
|
|
6
|
+
import LocalContext from "../context/local";
|
|
7
|
+
|
|
8
|
+
import { trim } from "../utilities/string";
|
|
9
|
+
import { nodeQuery } from "../utilities/query";
|
|
10
|
+
import { assignAssignments } from "../utilities/assignments";
|
|
11
|
+
|
|
12
|
+
const statementNodeQuery = nodeQuery("/qualifiedStatement/statement"),
|
|
13
|
+
referenceNodeQuery = nodeQuery("/qualifiedStatement/reference");
|
|
14
|
+
|
|
15
|
+
export default class QualifiedStatement {
|
|
16
|
+
constructor(string, statement, reference) {
|
|
17
|
+
this.string = string;
|
|
18
|
+
this.statement = statement;
|
|
19
|
+
this.reference = reference;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getString() {
|
|
23
|
+
return this.string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getStatement() {
|
|
27
|
+
return this.statement;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getReference() {
|
|
31
|
+
return this.reference;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getMetavariableNode() { return this.reference.getMetavariableNode(); }
|
|
35
|
+
|
|
36
|
+
verify(substitutions, localContext) {
|
|
37
|
+
let verified;
|
|
38
|
+
|
|
39
|
+
const qualifiedStatementString = trim(this.string); ///
|
|
40
|
+
|
|
41
|
+
localContext.trace(`Verifying the '${qualifiedStatementString}' qualified statement...`);
|
|
42
|
+
|
|
43
|
+
const stated = true,
|
|
44
|
+
assignments = [],
|
|
45
|
+
statementVerified = this.statement.verify(assignments, stated, localContext);
|
|
46
|
+
|
|
47
|
+
if (statementVerified) {
|
|
48
|
+
const unified = this.unify(substitutions, localContext);
|
|
49
|
+
|
|
50
|
+
if (unified) {
|
|
51
|
+
const assignmentsAssigned = assignAssignments(assignments, localContext);
|
|
52
|
+
|
|
53
|
+
verified = assignmentsAssigned; ///
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (verified) {
|
|
58
|
+
localContext.debug(`...verified the '${qualifiedStatementString}' qualified statement.`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return verified;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
unify(substitutions, localContext) {
|
|
65
|
+
let unified;
|
|
66
|
+
|
|
67
|
+
const qualifiedStatement = this, ///
|
|
68
|
+
qualifiedStatementString = trim(this.string); ///
|
|
69
|
+
|
|
70
|
+
localContext.trace(`Unifying the '${qualifiedStatementString}' qualified statement...`);
|
|
71
|
+
|
|
72
|
+
unified = unifyMixins.some((unifyMixin) => {
|
|
73
|
+
const unified = unifyMixin(qualifiedStatement, substitutions, localContext);
|
|
74
|
+
|
|
75
|
+
return unified;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (unified) {
|
|
79
|
+
localContext.debug(`...unified the '${qualifiedStatementString}' qualified statement.`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return unified;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static fromQualifiedStatementNode(qualifiedStatementNode, fileContext) {
|
|
86
|
+
let qualifiedStatement = null;
|
|
87
|
+
|
|
88
|
+
if (qualifiedStatementNode !== null) {
|
|
89
|
+
const statementNode = statementNodeQuery(qualifiedStatementNode),
|
|
90
|
+
referenceNode = referenceNodeQuery(qualifiedStatementNode),
|
|
91
|
+
localContext = LocalContext.fromFileContext(fileContext),
|
|
92
|
+
statement = (statementNode !== null) ?
|
|
93
|
+
Statement.fromStatementNode(statementNode, localContext) :
|
|
94
|
+
null,
|
|
95
|
+
reference = Reference.fromReferenceNode(referenceNode, fileContext),
|
|
96
|
+
node = qualifiedStatementNode, ///
|
|
97
|
+
string = fileContext.nodeAsString(node);
|
|
98
|
+
|
|
99
|
+
qualifiedStatement = new QualifiedStatement(string, statement, reference);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return qualifiedStatement;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Statement from "../statement";
|
|
4
|
+
import LocalContext from "../context/local";
|
|
5
|
+
|
|
6
|
+
import { trim } from "../utilities/string";
|
|
7
|
+
import { nodeQuery } from "../utilities/query";
|
|
8
|
+
|
|
9
|
+
const statementNodeQuery = nodeQuery("/unqualifiedStatement/statement");
|
|
10
|
+
|
|
11
|
+
export default class UnqualifiedStatement {
|
|
12
|
+
constructor(string, statement) {
|
|
13
|
+
this.string = string;
|
|
14
|
+
this.statement = statement;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getString() {
|
|
18
|
+
return this.string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getStatement() {
|
|
22
|
+
return this.statement;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
verify(assignments, stated, localContext) {
|
|
26
|
+
let verified;
|
|
27
|
+
|
|
28
|
+
const unqualifiedStatementString = trim(this.string); ///
|
|
29
|
+
|
|
30
|
+
localContext.trace(`Verifying the '${unqualifiedStatementString}' unqualified statement...`);
|
|
31
|
+
|
|
32
|
+
const statementVerified = this.statement.verify(assignments, stated, localContext);
|
|
33
|
+
|
|
34
|
+
verified = statementVerified; ///
|
|
35
|
+
|
|
36
|
+
if (verified) {
|
|
37
|
+
localContext.debug(`...verified the '${unqualifiedStatementString}' unqualified statement.`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return verified;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static fromUnqualifiedStatementNode(unqualifiedStatementNode, fileContext) {
|
|
44
|
+
let unqualifiedStatement = null;
|
|
45
|
+
|
|
46
|
+
if (unqualifiedStatementNode !== null) {
|
|
47
|
+
const statementNode = statementNodeQuery(unqualifiedStatementNode),
|
|
48
|
+
localContext = LocalContext.fromFileContext(fileContext),
|
|
49
|
+
statement = (statementNode !== null) ?
|
|
50
|
+
Statement.fromStatementNode(statementNode, localContext) :
|
|
51
|
+
null,
|
|
52
|
+
node = unqualifiedStatementNode, ///
|
|
53
|
+
string = fileContext.nodeAsString(node);
|
|
54
|
+
|
|
55
|
+
unqualifiedStatement = new UnqualifiedStatement(string, statement);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return unqualifiedStatement;
|
|
59
|
+
}
|
|
60
|
+
}
|
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
|
+
}
|