occam-verify-cli 0.0.479 → 0.0.481
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/conclusion.js +21 -20
- package/lib/constants.js +5 -1
- package/lib/equality.js +10 -13
- package/lib/metaSubstitution.js +26 -24
- package/lib/premise.js +21 -16
- package/lib/substitution.js +27 -25
- package/lib/utilities/node.js +16 -15
- package/lib/verify/statement.js +14 -16
- package/lib/verify/statementAsEquality.js +139 -0
- package/lib/verify/statementTypeAssertion.js +82 -0
- package/package.json +1 -1
- package/src/conclusion.js +35 -41
- package/src/constants.js +1 -0
- package/src/equality.js +14 -16
- package/src/metaSubstitution.js +33 -29
- package/src/premise.js +24 -26
- package/src/substitution.js +34 -30
- package/src/utilities/node.js +13 -13
- package/src/verify/statement.js +15 -19
- package/src/verify/statementAsEquality.js +146 -0
- package/src/verify/{assertion/type.js → statementTypeAssertion.js} +35 -29
- package/lib/verify/assertion/type.js +0 -79
- package/lib/verify/equality.js +0 -133
- package/src/verify/equality.js +0 -136
package/src/premise.js
CHANGED
|
@@ -195,6 +195,8 @@ function matchPremiseNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, su
|
|
|
195
195
|
childNodes = nonTerminalNode.getChildNodes(),
|
|
196
196
|
premiseNonTerminalNodeRuleName = premiseNonTerminalNode.getRuleName(),
|
|
197
197
|
premiseNonTerminalNodeChildNodes = premiseNonTerminalNode.getChildNodes(),
|
|
198
|
+
nodes = childNodes, ///
|
|
199
|
+
premiseNodes = premiseNonTerminalNodeChildNodes, ///
|
|
198
200
|
ruleNameStatementRuleName = (ruleName === STATEMENT_RULE_NAME),
|
|
199
201
|
premiseNonTerminalNodeRuleNameMetastatementRuleName = (premiseNonTerminalNodeRuleName === METASTATEMENT_RULE_NAME);
|
|
200
202
|
|
|
@@ -206,16 +208,12 @@ function matchPremiseNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, su
|
|
|
206
208
|
if (premiseMetastatementNodeMatches) {
|
|
207
209
|
premiseNonTerminalNodeMatches = true;
|
|
208
210
|
} else {
|
|
209
|
-
const
|
|
210
|
-
premiseNodes = premiseNonTerminalNodeChildNodes, ///
|
|
211
|
-
premiseNonTerminalNodeChildNodesMatches = matchPremiseNodes(premiseNodes, nodes, substitutions);
|
|
211
|
+
const premiseNonTerminalNodeChildNodesMatches = matchPremiseNodes(premiseNodes, nodes, substitutions);
|
|
212
212
|
|
|
213
213
|
premiseNonTerminalNodeMatches = premiseNonTerminalNodeChildNodesMatches; ///
|
|
214
214
|
}
|
|
215
215
|
} else if (ruleName === premiseNonTerminalNodeRuleName) {
|
|
216
|
-
const
|
|
217
|
-
premiseNodes = premiseNonTerminalNodeChildNodes, ///
|
|
218
|
-
premiseNonTerminalNodeChildNodesMatches = matchPremiseNodes(premiseNodes, nodes, substitutions);
|
|
216
|
+
const premiseNonTerminalNodeChildNodesMatches = matchPremiseNodes(premiseNodes, nodes, substitutions);
|
|
219
217
|
|
|
220
218
|
premiseNonTerminalNodeMatches = premiseNonTerminalNodeChildNodesMatches; ///
|
|
221
219
|
}
|
|
@@ -223,7 +221,7 @@ function matchPremiseNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, su
|
|
|
223
221
|
return premiseNonTerminalNodeMatches;
|
|
224
222
|
}
|
|
225
223
|
|
|
226
|
-
function matchPremiseMetavariableNode(premiseMetavariableNode,
|
|
224
|
+
function matchPremiseMetavariableNode(premiseMetavariableNode, statementNode, substitutions) {
|
|
227
225
|
let premiseMetavariableNodeMatches;
|
|
228
226
|
|
|
229
227
|
const premiseMetavariableName = metavariableNameFromMetavariableNode(premiseMetavariableNode),
|
|
@@ -236,12 +234,12 @@ function matchPremiseMetavariableNode(premiseMetavariableNode, nodes, substituti
|
|
|
236
234
|
}) || null;
|
|
237
235
|
|
|
238
236
|
if (substitution !== null) {
|
|
239
|
-
const substitutionNodesMatch = substitution.
|
|
237
|
+
const substitutionNodesMatch = substitution.matchStatementNode(statementNode);
|
|
240
238
|
|
|
241
239
|
premiseMetavariableNodeMatches = substitutionNodesMatch; ///
|
|
242
240
|
} else {
|
|
243
241
|
const metavariableName = premiseMetavariableName, ///
|
|
244
|
-
substitution = Substitution.
|
|
242
|
+
substitution = Substitution.fromMetavariableNameAndStatementNode(metavariableName, statementNode);
|
|
245
243
|
|
|
246
244
|
substitutions.push(substitution);
|
|
247
245
|
|
|
@@ -270,10 +268,7 @@ function matchPremiseMetastatementNode(premiseMetastatementNode, statementNode,
|
|
|
270
268
|
|
|
271
269
|
if (premiseNonTerminalChildNodeRuleNameMetavariableRuleName) {
|
|
272
270
|
const premiseMetavariableNode = premiseNonTerminalChildNode, ///
|
|
273
|
-
|
|
274
|
-
childNodes = nonTerminalNode.getChildNodes(),
|
|
275
|
-
nodes = childNodes, ///
|
|
276
|
-
premiseMetaVariableNodeMatches = matchPremiseMetavariableNode(premiseMetavariableNode, nodes, substitutions);
|
|
271
|
+
premiseMetaVariableNodeMatches = matchPremiseMetavariableNode(premiseMetavariableNode, statementNode, substitutions);
|
|
277
272
|
|
|
278
273
|
premiseMetastatementNodeMatches = premiseMetaVariableNodeMatches; ///
|
|
279
274
|
}
|
|
@@ -339,7 +334,11 @@ function metaMatchPremiseNonTerminalNode(premiseNonTerminalNode, nonTerminalNode
|
|
|
339
334
|
let premiseNonTerminalNodeMatches = false;
|
|
340
335
|
|
|
341
336
|
const ruleName = nonTerminalNode.getRuleName(),
|
|
337
|
+
childNodes = nonTerminalNode.getChildNodes(),
|
|
342
338
|
premiseNonTerminalNodeRuleName = premiseNonTerminalNode.getRuleName(),
|
|
339
|
+
premiseNonTerminalNodeChildNodes = premiseNonTerminalNode.getChildNodes(),
|
|
340
|
+
nodes = childNodes, ///
|
|
341
|
+
premiseNodes = premiseNonTerminalNodeChildNodes, ///
|
|
343
342
|
ruleNameMetastatementRuleName = (ruleName === METASTATEMENT_RULE_NAME),
|
|
344
343
|
premiseNonTerminalNodeRuleNameMetastatementRuleName = (premiseNonTerminalNodeRuleName === METASTATEMENT_RULE_NAME);
|
|
345
344
|
|
|
@@ -348,13 +347,15 @@ function metaMatchPremiseNonTerminalNode(premiseNonTerminalNode, nonTerminalNode
|
|
|
348
347
|
premiseMetastatementNode = premiseNonTerminalNode, ///
|
|
349
348
|
premiseMetastatementNodeMatches = metaMatchPremiseMetastatementNode(premiseMetastatementNode, metastatementNode, metaSubstitutions);
|
|
350
349
|
|
|
351
|
-
|
|
350
|
+
if (premiseMetastatementNodeMatches) {
|
|
351
|
+
premiseNonTerminalNodeMatches = true;
|
|
352
|
+
} else {
|
|
353
|
+
const premiseNonTerminalNodeChildNodesMatches = metaMatchPremiseNodes(premiseNodes, nodes, metaSubstitutions);
|
|
354
|
+
|
|
355
|
+
premiseNonTerminalNodeMatches = premiseNonTerminalNodeChildNodesMatches; ///
|
|
356
|
+
}
|
|
352
357
|
} else if (ruleName === premiseNonTerminalNodeRuleName) {
|
|
353
|
-
const
|
|
354
|
-
premiseNonTerminalNodeChildNodes = premiseNonTerminalNode.getChildNodes(), ///
|
|
355
|
-
nodes = childNodes, ///
|
|
356
|
-
premiseNodes = premiseNonTerminalNodeChildNodes, ///
|
|
357
|
-
premiseNonTerminalNodeChildNodesMatches = metaMatchPremiseNodes(premiseNodes, nodes, metaSubstitutions);
|
|
358
|
+
const premiseNonTerminalNodeChildNodesMatches = metaMatchPremiseNodes(premiseNodes, nodes, metaSubstitutions);
|
|
358
359
|
|
|
359
360
|
premiseNonTerminalNodeMatches = premiseNonTerminalNodeChildNodesMatches; ///
|
|
360
361
|
}
|
|
@@ -362,7 +363,7 @@ function metaMatchPremiseNonTerminalNode(premiseNonTerminalNode, nonTerminalNode
|
|
|
362
363
|
return premiseNonTerminalNodeMatches;
|
|
363
364
|
}
|
|
364
365
|
|
|
365
|
-
function metaMatchPremiseMetavariableNode(premiseMetavariableNode,
|
|
366
|
+
function metaMatchPremiseMetavariableNode(premiseMetavariableNode, metastatementNode, metaSubstitutions) {
|
|
366
367
|
let premiseMetavariableNodeMatches;
|
|
367
368
|
|
|
368
369
|
const premiseMetavariableName = metavariableNameFromMetavariableNode(premiseMetavariableNode),
|
|
@@ -375,12 +376,12 @@ function metaMatchPremiseMetavariableNode(premiseMetavariableNode, nodes, metaSu
|
|
|
375
376
|
}) || null;
|
|
376
377
|
|
|
377
378
|
if (metaSubstitution !== null) {
|
|
378
|
-
const metaSubstitutionNodesMatch = metaSubstitution.
|
|
379
|
+
const metaSubstitutionNodesMatch = metaSubstitution.matchMetastatementNode(metastatementNode);
|
|
379
380
|
|
|
380
381
|
premiseMetavariableNodeMatches = metaSubstitutionNodesMatch; ///
|
|
381
382
|
} else {
|
|
382
383
|
const metavariableName = premiseMetavariableName, ///
|
|
383
|
-
metaSubstitution = MetaSubstitution.
|
|
384
|
+
metaSubstitution = MetaSubstitution.fromMetavariableNameAndMetastatementNode(metavariableName, metastatementNode);
|
|
384
385
|
|
|
385
386
|
metaSubstitutions.push(metaSubstitution);
|
|
386
387
|
|
|
@@ -409,10 +410,7 @@ function metaMatchPremiseMetastatementNode(premiseMetastatementNode, metastateme
|
|
|
409
410
|
|
|
410
411
|
if (premiseNonTerminalChildNodeRuleNameMetavariableRuleName) {
|
|
411
412
|
const premiseMetavariableNode = premiseNonTerminalChildNode, ///
|
|
412
|
-
|
|
413
|
-
childNodes = nonTerminalNode.getChildNodes(),
|
|
414
|
-
nodes = childNodes, ///
|
|
415
|
-
premiseMetaVariableNodeMatches = metaMatchPremiseMetavariableNode(premiseMetavariableNode, nodes, metaSubstitutions);
|
|
413
|
+
premiseMetaVariableNodeMatches = metaMatchPremiseMetavariableNode(premiseMetavariableNode, metastatementNode, metaSubstitutions);
|
|
416
414
|
|
|
417
415
|
premiseMetastatementNodeMatches = premiseMetaVariableNodeMatches; ///
|
|
418
416
|
}
|
package/src/substitution.js
CHANGED
|
@@ -1,59 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { STATEMENT_RULE_NAME } from "./ruleNames";
|
|
4
|
+
import { matchNode, bracketedNonTerminalChildNodeFromChildNodes } from "./utilities/node";
|
|
4
5
|
|
|
5
6
|
export default class Substitution {
|
|
6
|
-
constructor(metavariableName,
|
|
7
|
+
constructor(metavariableName, statementNode) {
|
|
7
8
|
this.metavariableName = metavariableName;
|
|
8
|
-
this.
|
|
9
|
+
this.statementNode = statementNode;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
getMetavariableName() {
|
|
12
13
|
return this.metavariableName;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
return this.
|
|
16
|
+
getStatementNode() {
|
|
17
|
+
return this.statementNode;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
let
|
|
20
|
+
matchStatementNode(statementNode) {
|
|
21
|
+
let matchesStatementNode;
|
|
21
22
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const nodeA = this.statementNode, ///
|
|
24
|
+
nodeB = statementNode,
|
|
25
|
+
nodeMatches = matchNode(nodeA, nodeB);
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
matchesStatementNode = nodeMatches; ///
|
|
27
28
|
|
|
28
|
-
if (!
|
|
29
|
-
const
|
|
30
|
-
|
|
29
|
+
if (!matchesStatementNode) {
|
|
30
|
+
const nonTerminalNode = statementNode, ///
|
|
31
|
+
childNodes = nonTerminalNode.getChildNodes(), ///
|
|
32
|
+
ruleName = STATEMENT_RULE_NAME;
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
const nonTerminalNode = bracketedChildNode, ///
|
|
34
|
-
childNodes = nonTerminalNode.getChildNodes(),
|
|
35
|
-
nodesB = childNodes, ///
|
|
36
|
-
nodesMatch = matchNodes(nodesA, nodesB);
|
|
34
|
+
statementNode = bracketedNonTerminalChildNodeFromChildNodes(childNodes, ruleName); ///
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
if (statementNode !== null) {
|
|
37
|
+
const nodeA = this.statementNode, ///
|
|
38
|
+
nodeB = statementNode,
|
|
39
|
+
nodeMatches = matchNode(nodeA, nodeB);
|
|
40
|
+
|
|
41
|
+
matchesStatementNode = nodeMatches; ///
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
return
|
|
45
|
+
return matchesStatementNode;
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
static
|
|
46
|
-
|
|
48
|
+
static fromMetavariableNameAndStatementNode(metavariableName, statementNode) {
|
|
49
|
+
let substitution = new Substitution(metavariableName, statementNode);
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
const nonTerminalNode = statementNode, ///
|
|
52
|
+
childNodes = nonTerminalNode.getChildNodes(),
|
|
53
|
+
ruleName = STATEMENT_RULE_NAME;
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
}
|
|
55
|
+
statementNode = bracketedNonTerminalChildNodeFromChildNodes(childNodes, ruleName); ///
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
if (statementNode !== null) {
|
|
58
|
+
substitution = new Substitution(metavariableName, statementNode);
|
|
59
|
+
}
|
|
56
60
|
|
|
57
|
-
return
|
|
61
|
+
return substitution;
|
|
58
62
|
}
|
|
59
63
|
}
|
package/src/utilities/node.js
CHANGED
|
@@ -61,10 +61,10 @@ export function matchBracketedNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB
|
|
|
61
61
|
if (!bracketedNodeMatches) {
|
|
62
62
|
const nonTerminalNodeAChildNodes = nonTerminalNodeA.getChildNodes(),
|
|
63
63
|
childNodesA = nonTerminalNodeAChildNodes, ///
|
|
64
|
-
|
|
64
|
+
bracketedNonTerminalChildNodeA = bracketedNonTerminalChildNodeFromChildNodes(childNodesA);
|
|
65
65
|
|
|
66
|
-
if (
|
|
67
|
-
const nodeA =
|
|
66
|
+
if (bracketedNonTerminalChildNodeA !== null) {
|
|
67
|
+
const nodeA = bracketedNonTerminalChildNodeA, ///
|
|
68
68
|
nodeB = nonTerminalNodeB, ///
|
|
69
69
|
nodeMatches = matchNode(nodeA, nodeB);
|
|
70
70
|
|
|
@@ -75,10 +75,10 @@ export function matchBracketedNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB
|
|
|
75
75
|
if (!bracketedNodeMatches) {
|
|
76
76
|
const nonTerminalNodeBChildNodes = nonTerminalNodeB.getChildNodes(),
|
|
77
77
|
childNodesB = nonTerminalNodeBChildNodes, ///
|
|
78
|
-
|
|
78
|
+
bracketedNonTerminalChildNodeB = bracketedNonTerminalChildNodeFromChildNodes(childNodesB);
|
|
79
79
|
|
|
80
|
-
if (
|
|
81
|
-
const nodeB =
|
|
80
|
+
if (bracketedNonTerminalChildNodeB !== null) {
|
|
81
|
+
const nodeB = bracketedNonTerminalChildNodeB, ///
|
|
82
82
|
nodeA = nonTerminalNodeA, ///
|
|
83
83
|
nodeMatches = matchNode(nodeA, nodeB);
|
|
84
84
|
|
|
@@ -89,8 +89,8 @@ export function matchBracketedNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB
|
|
|
89
89
|
return bracketedNodeMatches;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export function
|
|
93
|
-
let
|
|
92
|
+
export function bracketedNonTerminalChildNodeFromChildNodes(childNodes, ruleName = METASTATEMENT_RULE_NAME) {
|
|
93
|
+
let bracketedNonTerminalChildNode = null;
|
|
94
94
|
|
|
95
95
|
const childNodesLength = childNodes.length;
|
|
96
96
|
|
|
@@ -109,17 +109,17 @@ export function bracketedChildNodeFromChildNodes(childNodes) {
|
|
|
109
109
|
nonTerminalNodeRuleName = nonTerminalNode.getRuleName(),
|
|
110
110
|
firstTerminalNodeContent = firstTerminalNode.getContent(),
|
|
111
111
|
secondTerminalNodeContent = secondTerminalNode.getContent(),
|
|
112
|
+
nonTerminalNodeRuleNameRuleName = (nonTerminalNodeRuleName === ruleName),
|
|
112
113
|
firstTerminalNodeContentLeftBracket = (firstTerminalNodeContent === LEFT_BRACKET),
|
|
113
|
-
secondTerminalNodeContentRightBracket = (secondTerminalNodeContent === RIGHT_BRACKET)
|
|
114
|
-
nonTerminalNodeRuleNameMetastatementRuleName = (nonTerminalNodeRuleName === METASTATEMENT_RULE_NAME);
|
|
114
|
+
secondTerminalNodeContentRightBracket = (secondTerminalNodeContent === RIGHT_BRACKET);
|
|
115
115
|
|
|
116
|
-
if (
|
|
117
|
-
|
|
116
|
+
if (nonTerminalNodeRuleNameRuleName && firstTerminalNodeContentLeftBracket && secondTerminalNodeContentRightBracket) {
|
|
117
|
+
bracketedNonTerminalChildNode = nonTerminalNode; ///
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
return
|
|
122
|
+
return bracketedNonTerminalChildNode;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
function matchTerminalNode(terminalNodeA, terminalNodeB) {
|
package/src/verify/statement.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import verifyStatementAsEquality from "../verify/statementAsEquality";
|
|
4
|
+
import verifyStatementTypeAssertion from "../verify/statementTypeAssertion";
|
|
5
5
|
|
|
6
|
-
import { nodeQuery } from "../utilities/query";
|
|
7
6
|
import { nodeAsString } from "../utilities/string";
|
|
8
7
|
|
|
9
|
-
const equalityNodeQuery = nodeQuery("/statement/equality!"),
|
|
10
|
-
typeAssertionNodeQuery = nodeQuery("/statement/typeAssertion!");
|
|
11
|
-
|
|
12
8
|
export default function verifyStatement(statementNode, proofContext) {
|
|
13
9
|
let statementVerified = false;
|
|
14
10
|
|
|
15
11
|
proofContext.begin(statementNode);
|
|
16
12
|
|
|
17
|
-
const
|
|
18
|
-
statementString = nodeAsString(statementNode),
|
|
19
|
-
typeAssertionNode = typeAssertionNodeQuery(statementNode);
|
|
13
|
+
const statementString = nodeAsString(statementNode);
|
|
20
14
|
|
|
21
15
|
proofContext.debug(`Verifying the '${statementString}' statement...`);
|
|
22
16
|
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
if (!statementVerified) {
|
|
18
|
+
const equalityVerifiedAsEquality = verifyStatementAsEquality(statementNode, proofContext);
|
|
19
|
+
|
|
20
|
+
statementVerified = equalityVerifiedAsEquality; ///
|
|
21
|
+
}
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
if (!statementVerified) {
|
|
24
|
+
const statementTypeAssertionVerified = verifyStatementTypeAssertion(statementNode, proofContext);
|
|
25
|
+
|
|
26
|
+
statementVerified = statementTypeAssertionVerified; ///
|
|
27
|
+
}
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
statementVerified = true;
|
|
29
|
+
if (!statementVerified) {
|
|
30
|
+
statementVerified = true; ///
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
statementVerified ?
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Equality from "../equality";
|
|
4
|
+
import Variable from "../variable";
|
|
5
|
+
import verifyTerm from "../verify/term";
|
|
6
|
+
|
|
7
|
+
import { nodeQuery } from "../utilities/query";
|
|
8
|
+
import { nodeAsString } from "../utilities/string";
|
|
9
|
+
import { first, second } from "../utilities/array";
|
|
10
|
+
import { verifyTermAsVariable } from "../verify/term";
|
|
11
|
+
import { EQUALS_CHARACTER, MAXIMUM_INDEXES_LENGTH } from "../constants";
|
|
12
|
+
|
|
13
|
+
const specialNodeQuery = nodeQuery("/statement/@special!"),
|
|
14
|
+
leftTermNodeQuery = nodeQuery("/statement/term[0]"),
|
|
15
|
+
rightTermNodeQuery = nodeQuery("/statement/term[1]");
|
|
16
|
+
|
|
17
|
+
export default function verifyStatementAsEquality(statementNode, proofContext) {
|
|
18
|
+
let statementVerifiedAsEquality = false;
|
|
19
|
+
|
|
20
|
+
proofContext.begin(statementNode);
|
|
21
|
+
|
|
22
|
+
const statementString = nodeAsString(statementNode);
|
|
23
|
+
|
|
24
|
+
proofContext.debug(`Verifying the '${statementString}' statement as an equality...`);
|
|
25
|
+
|
|
26
|
+
const specialNode = specialNodeQuery(statementNode);
|
|
27
|
+
|
|
28
|
+
if (specialNode !== null) {
|
|
29
|
+
const terminalNode = specialNode, ///
|
|
30
|
+
terminalNodeContent = terminalNode.getContent();
|
|
31
|
+
|
|
32
|
+
if (terminalNodeContent === EQUALS_CHARACTER) {
|
|
33
|
+
const types = [],
|
|
34
|
+
context = proofContext, ///
|
|
35
|
+
leftTermNode = leftTermNodeQuery(statementNode),
|
|
36
|
+
rightTermNode = rightTermNodeQuery(statementNode),
|
|
37
|
+
leftTermVerified = verifyTerm(leftTermNode, types, context),
|
|
38
|
+
rightTermVerified = verifyTerm(rightTermNode, types, context);
|
|
39
|
+
|
|
40
|
+
if (leftTermVerified && rightTermVerified) {
|
|
41
|
+
const firstType = first(types),
|
|
42
|
+
secondType = second(types),
|
|
43
|
+
leftType = firstType, ///
|
|
44
|
+
rightType = secondType, ///
|
|
45
|
+
leftTermString = nodeAsString(leftTermNode),
|
|
46
|
+
rightTermString = nodeAsString(rightTermNode);
|
|
47
|
+
|
|
48
|
+
if ((leftType === null) && (rightType === null)) {
|
|
49
|
+
proofContext.error(`The types of the '${leftTermString}' and '${rightTermString}' terms are both undefined and therefore the terms cannot be equated.`);
|
|
50
|
+
} else if (rightType === null) {
|
|
51
|
+
const type = leftType, ///
|
|
52
|
+
termNode = rightTermNode, ///
|
|
53
|
+
variable = addVariable(type, termNode, proofContext);
|
|
54
|
+
|
|
55
|
+
if (variable !== null) {
|
|
56
|
+
const leftTypeName = leftType.getName();
|
|
57
|
+
|
|
58
|
+
proofContext.info(`The '${rightTermString}' variable has been given the '${leftTypeName}' type.`);
|
|
59
|
+
|
|
60
|
+
statementVerifiedAsEquality = true;
|
|
61
|
+
}
|
|
62
|
+
} else if (leftType === null) {
|
|
63
|
+
const type = rightType, ///
|
|
64
|
+
termNode = leftType, ///
|
|
65
|
+
variable = addVariable(type, termNode, proofContext);
|
|
66
|
+
|
|
67
|
+
if (variable !== null) {
|
|
68
|
+
const rightTypeName = rightType.getName();
|
|
69
|
+
|
|
70
|
+
proofContext.info(`The '${rightTermString}' variable has been given the '${rightTypeName}' type.`);
|
|
71
|
+
|
|
72
|
+
statementVerifiedAsEquality = true;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
const leftTypeMatchesRightType = leftType.match(rightType);
|
|
76
|
+
|
|
77
|
+
if (!leftTypeMatchesRightType) {
|
|
78
|
+
proofContext.error(`The types of the '${leftTermString}' and '${rightTermString}' terms do not match and therefore the terms cannot be equated.`);
|
|
79
|
+
} else {
|
|
80
|
+
const derived = proofContext.isDerived();
|
|
81
|
+
|
|
82
|
+
if (!derived) {
|
|
83
|
+
statementVerifiedAsEquality = true;
|
|
84
|
+
} else {
|
|
85
|
+
const equality = Equality.fromLeftTermNodeAndRightTermNode(leftTermNode, rightTermNode),
|
|
86
|
+
proofSteps = proofContext.getProofSteps(),
|
|
87
|
+
equalities = equalitiesFromProofSteps(proofSteps),
|
|
88
|
+
equalityEquates = equality.equate(equalities, proofContext);
|
|
89
|
+
|
|
90
|
+
statementVerifiedAsEquality = equalityEquates; ///
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (statementVerifiedAsEquality) {
|
|
99
|
+
proofContext.info(`Verified the '${statementString}' equality.`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
statementVerifiedAsEquality ?
|
|
103
|
+
proofContext.complete(statementNode) :
|
|
104
|
+
proofContext.halt(statementNode);
|
|
105
|
+
|
|
106
|
+
return statementVerifiedAsEquality;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function equalitiesFromProofSteps(proofSteps) {
|
|
110
|
+
const start = -MAXIMUM_INDEXES_LENGTH; ///
|
|
111
|
+
|
|
112
|
+
proofSteps = proofSteps.slice(start); ///
|
|
113
|
+
|
|
114
|
+
const equalities = proofSteps.reduce((equalities, proofStep, index) => {
|
|
115
|
+
const equality = Equality.fromProofStep(proofStep);
|
|
116
|
+
|
|
117
|
+
if (equality !== null) {
|
|
118
|
+
equalities.push(equality);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return equalities;
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
return equalities;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function addVariable(type, termNode, proofContext) {
|
|
128
|
+
let variable = null;
|
|
129
|
+
|
|
130
|
+
const variables = [],
|
|
131
|
+
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, proofContext);
|
|
132
|
+
|
|
133
|
+
if (termVerifiedAsVariable) {
|
|
134
|
+
const firstVariable = first(variables);
|
|
135
|
+
|
|
136
|
+
variable = firstVariable; ///
|
|
137
|
+
|
|
138
|
+
const name = variable.getName();
|
|
139
|
+
|
|
140
|
+
variable = Variable.fromTypeAndName(type, name); ///
|
|
141
|
+
|
|
142
|
+
proofContext.addVariable(variable);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return variable;
|
|
146
|
+
}
|
|
@@ -1,53 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
3
|
+
import Variable from "../variable";
|
|
4
|
+
|
|
5
|
+
import { first } from "../utilities/array";
|
|
6
|
+
import { nodeAsString } from "../utilities/string";
|
|
7
|
+
import { nodeQuery, typeNameFromTypeNode } from "../utilities/query";
|
|
8
|
+
import { verifyTermAsVariable, verifyTermAgainstConstructors } from "../verify/term";
|
|
8
9
|
|
|
9
10
|
const termNodeQuery = nodeQuery("/typeAssertion/term"),
|
|
10
|
-
typeNodeQuery = nodeQuery("/typeAssertion/type")
|
|
11
|
+
typeNodeQuery = nodeQuery("/typeAssertion/type"),
|
|
12
|
+
typeAssertionNodeQuery = nodeQuery("/statement/typeAssertion!");
|
|
11
13
|
|
|
12
|
-
export default function
|
|
14
|
+
export default function verifyStatementTypeAssertion(statementNode, proofContext) {
|
|
13
15
|
let typeAssertionVerified = false;
|
|
14
16
|
|
|
15
|
-
proofContext.begin(
|
|
17
|
+
proofContext.begin(statementNode);
|
|
16
18
|
|
|
17
|
-
const
|
|
19
|
+
const statementString = nodeAsString(statementNode);
|
|
18
20
|
|
|
19
|
-
proofContext.debug(`Verifying the '${
|
|
21
|
+
proofContext.debug(`Verifying the '${statementString}' statement type assertion...`);
|
|
20
22
|
|
|
21
|
-
const
|
|
22
|
-
typeName = typeNameFromTypeNode(typeNode),
|
|
23
|
-
typePresent = proofContext.isTypePresentByTypeName(typeName);
|
|
24
|
-
|
|
25
|
-
if (!typePresent) {
|
|
26
|
-
proofContext.error(`The ${typeName} type is not present.`);
|
|
27
|
-
} else {
|
|
28
|
-
const context = proofContext, ///
|
|
29
|
-
termNode = termNodeQuery(typeAssertionNode),
|
|
30
|
-
variables = [],
|
|
31
|
-
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context);
|
|
23
|
+
const typeAssertionNode = typeAssertionNodeQuery(statementNode);
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
if (typeAssertionNode !== null) {
|
|
26
|
+
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
27
|
+
typeName = typeNameFromTypeNode(typeNode),
|
|
28
|
+
typePresent = proofContext.isTypePresentByTypeName(typeName);
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
if (!typePresent) {
|
|
31
|
+
proofContext.error(`The ${typeName} type is not present.`);
|
|
37
32
|
} else {
|
|
38
|
-
const
|
|
33
|
+
const context = proofContext, ///
|
|
34
|
+
termNode = termNodeQuery(typeAssertionNode),
|
|
35
|
+
variables = [],
|
|
36
|
+
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context);
|
|
37
|
+
|
|
38
|
+
if (termVerifiedAsVariable) {
|
|
39
|
+
const variableTypeAssertionVerified = verifyVariableTypeAssertion(typeAssertionNode, proofContext);
|
|
40
|
+
|
|
41
|
+
typeAssertionVerified = variableTypeAssertionVerified; ///
|
|
42
|
+
} else {
|
|
43
|
+
const termTypeAssertionVerified = verifyTermTypeAssertion(typeAssertionNode, proofContext);
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
typeAssertionVerified = termTypeAssertionVerified; ///
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
if (typeAssertionVerified) {
|
|
45
|
-
proofContext.info(`Verified the '${
|
|
51
|
+
proofContext.info(`Verified the '${statementString}' statement type assertion.`);
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
typeAssertionVerified ?
|
|
49
|
-
proofContext.complete(
|
|
50
|
-
proofContext.halt(
|
|
55
|
+
proofContext.complete(statementNode) :
|
|
56
|
+
proofContext.halt(statementNode);
|
|
51
57
|
|
|
52
58
|
return typeAssertionVerified;
|
|
53
59
|
}
|