occam-verify-cli 0.0.869 → 0.0.870
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 +3 -3
- package/lib/equality.js +2 -4
- package/lib/equivalence.js +1 -1
- package/lib/premise.js +4 -4
- package/lib/ruleNames.js +1 -29
- package/lib/substitution/metastatementForMetavariable.js +3 -2
- package/lib/substitution/statementForMetavariable.js +27 -64
- package/lib/substitution/termForVariable.js +5 -5
- package/lib/utilities/verifier.js +86 -0
- package/lib/verifier/node/metastatement.js +41 -28
- package/lib/verifier/node/statementAsCombinator.js +41 -28
- package/lib/verifier/node/termAsConstructor.js +30 -22
- package/lib/verifier/nodes/equality.js +27 -32
- package/lib/verifier/nodes/intrinsicLevel.js +25 -34
- package/lib/verifier/nodes/intrinsicLevelAgainstMetaLevel.js +270 -0
- package/lib/verifier/nodes/metaLevel.js +25 -34
- package/lib/verifier/nodes/statementAgainstCombinator.js +45 -49
- package/lib/verifier/nodes/termAgainstConstructor.js +24 -51
- package/lib/verify/argumentAgainstArgument.js +24 -0
- package/lib/verify/containment.js +5 -5
- package/lib/verify/equality.js +9 -9
- package/lib/verify/metaDerivation.js +19 -19
- package/lib/verify/metaLemma.js +1 -1
- package/lib/verify/metaproof.js +4 -6
- package/lib/verify/metavariable.js +7 -5
- package/lib/verify/metavariableAgainstMetastatement.js +44 -0
- package/lib/verify/metavariableAgainstStatement.js +65 -0
- package/lib/verify/statement.js +4 -4
- package/lib/verify/statementAgainstMetaType.js +24 -0
- package/lib/verify/statementAtainstStatement.js +52 -0
- package/lib/verify/term.js +7 -8
- package/lib/verify/termAgainstTerm.js +22 -0
- package/lib/verify/termAgainstType.js +26 -0
- package/lib/verify/terms.js +2 -3
- package/lib/verify/type.js +7 -5
- package/lib/verify/typeAssertion.js +45 -40
- package/lib/verify/variable.js +7 -5
- package/lib/verify/variableAgainstTerm.js +70 -0
- package/package.json +4 -4
- package/src/conclusion.js +2 -2
- package/src/equality.js +3 -9
- package/src/equivalence.js +1 -1
- package/src/premise.js +3 -3
- package/src/ruleNames.js +0 -7
- package/src/substitution/metastatementForMetavariable.js +3 -1
- package/src/substitution/statementForMetavariable.js +32 -74
- package/src/substitution/termForVariable.js +3 -3
- package/src/utilities/verifier.js +46 -0
- package/src/verifier/node/metastatement.js +41 -34
- package/src/verifier/node/statementAsCombinator.js +39 -32
- package/src/verifier/node/termAsConstructor.js +30 -25
- package/src/verifier/nodes/equality.js +31 -36
- package/src/verifier/nodes/intrinsicLevel.js +30 -38
- package/src/verifier/nodes/intrinsicLevelAgainstMetaLevel.js +222 -0
- package/src/verifier/nodes/metaLevel.js +30 -38
- package/src/verifier/nodes/statementAgainstCombinator.js +52 -55
- package/src/verifier/nodes/termAgainstConstructor.js +30 -71
- package/src/verify/argumentAgainstArgument.js +15 -0
- package/src/verify/containment.js +4 -4
- package/src/verify/equality.js +8 -8
- package/src/verify/metaDerivation.js +18 -18
- package/src/verify/metaLemma.js +2 -2
- package/src/verify/metaproof.js +3 -6
- package/src/verify/metavariable.js +7 -5
- package/src/verify/metavariableAgainstMetastatement.js +42 -0
- package/src/verify/metavariableAgainstStatement.js +77 -0
- package/src/verify/statement.js +5 -5
- package/src/verify/statementAgainstMetaType.js +21 -0
- package/src/verify/statementAtainstStatement.js +60 -0
- package/src/verify/term.js +13 -17
- package/src/verify/termAgainstTerm.js +20 -0
- package/src/verify/termAgainstType.js +28 -0
- package/src/verify/terms.js +1 -3
- package/src/verify/type.js +7 -5
- package/src/verify/typeAssertion.js +56 -55
- package/src/verify/variable.js +7 -5
- package/src/verify/variableAgainstTerm.js +86 -0
- package/lib/verifier/nodes/metaLevelToIntrinsicLevel.js +0 -327
- package/lib/verifier/nodes/substitution.js +0 -223
- package/lib/verify/givenMetavariable.js +0 -31
- package/lib/verify/givenType.js +0 -31
- package/lib/verify/givenVariable.js +0 -31
- package/lib/verify/termAndGivenType.js +0 -39
- package/src/verifier/nodes/metaLevelToIntrinsicLevel.js +0 -219
- package/src/verifier/nodes/substitution.js +0 -125
- package/src/verify/givenMetavariable.js +0 -31
- package/src/verify/givenType.js +0 -31
- package/src/verify/givenVariable.js +0 -31
- package/src/verify/termAndGivenType.js +0 -37
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import TermForVariableSubstitution from "../substitution/termForVariable";
|
|
4
|
+
import verifyStatementAgainstStatement from "../verify/statementAtainstStatement";
|
|
5
|
+
import StatementForMetavariableSubstitution from "../substitution/statementForMetavariable";
|
|
6
|
+
|
|
7
|
+
export default function verifyMetavariableAgainstStatement(metavariableNode, statementNode, substitutionNode, substitutions, localContextA, localContextB, verifyAhead) {
|
|
8
|
+
let metavariableVerifiedAgainstStatement = false;
|
|
9
|
+
|
|
10
|
+
const substitution = substitutions.find((substitution) => {
|
|
11
|
+
const substitutionMatchesMetavariableNodeA = substitution.matchMetavariableNode(metavariableNode);
|
|
12
|
+
|
|
13
|
+
if (substitutionMatchesMetavariableNodeA) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
}) || null;
|
|
17
|
+
|
|
18
|
+
if (substitution !== null) {
|
|
19
|
+
const substitutionStatementNode = substitution.getStatementNode();
|
|
20
|
+
|
|
21
|
+
if (substitutionNode !== null) {
|
|
22
|
+
const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitutionNode(substitutionNode),
|
|
23
|
+
substitution = termForVariableSubstitution, ///
|
|
24
|
+
statementNodeA = substitutionStatementNode, ///
|
|
25
|
+
statementNodeB = statementNode, ///
|
|
26
|
+
statementVerifiedAgainstStatement = verifyStatementAgainstStatement(statementNodeA, statementNodeB, substitution, substitutions, localContextA, localContextB);
|
|
27
|
+
|
|
28
|
+
if (statementVerifiedAgainstStatement) {
|
|
29
|
+
const verifiedAhead = verifyAhead();
|
|
30
|
+
|
|
31
|
+
metavariableVerifiedAgainstStatement = verifiedAhead; ///
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
const substitutionSubstitution = substitution.getSubstitution();
|
|
35
|
+
|
|
36
|
+
if (substitutionSubstitution !== null) {
|
|
37
|
+
localContextA = localContextB; ///
|
|
38
|
+
|
|
39
|
+
const substitution = substitutionSubstitution,
|
|
40
|
+
statementNodeA = statementNode, ///
|
|
41
|
+
statementNodeB = substitutionStatementNode, ///
|
|
42
|
+
statementVerifiedAgainstStatement = verifyStatementAgainstStatement(statementNodeA, statementNodeB, substitution, substitutions, localContextA, localContextB);
|
|
43
|
+
|
|
44
|
+
if (statementVerifiedAgainstStatement) {
|
|
45
|
+
const verifiedAhead = verifyAhead();
|
|
46
|
+
|
|
47
|
+
metavariableVerifiedAgainstStatement = verifiedAhead; ///
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
const statementNodeMatches = substitution.matchStatementNode(statementNode);
|
|
51
|
+
|
|
52
|
+
if (statementNodeMatches) {
|
|
53
|
+
const verifiedAhead = verifyAhead();
|
|
54
|
+
|
|
55
|
+
metavariableVerifiedAgainstStatement = verifiedAhead; ///
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
let verifiedAhead;
|
|
61
|
+
|
|
62
|
+
const statementForMetavariableSubstitution = StatementForMetavariableSubstitution.fromMetavariableNodeStatementNodeAndSubstitutionNode(metavariableNode, statementNode, substitutionNode),
|
|
63
|
+
substitution = statementForMetavariableSubstitution; ///
|
|
64
|
+
|
|
65
|
+
substitutions.push(substitution);
|
|
66
|
+
|
|
67
|
+
verifiedAhead = verifyAhead();
|
|
68
|
+
|
|
69
|
+
if (!verifiedAhead) {
|
|
70
|
+
substitutions.pop();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
metavariableVerifiedAgainstStatement = verifiedAhead; ///
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return metavariableVerifiedAgainstStatement;
|
|
77
|
+
}
|
package/src/verify/statement.js
CHANGED
|
@@ -12,9 +12,9 @@ import { nodeQuery } from "../utilities/query";
|
|
|
12
12
|
const termNodeQuery = nodeQuery("/statement/term!"),
|
|
13
13
|
equalityNodeQuery = nodeQuery("/statement/equality!"),
|
|
14
14
|
definingNodeQuery = nodeQuery("/statement/defining!"),
|
|
15
|
-
statementNodeQuery = nodeQuery("/
|
|
15
|
+
statementNodeQuery = nodeQuery("/metastatement/statement!"),
|
|
16
16
|
containmentNodeQuery = nodeQuery("/statement/containment!"),
|
|
17
|
-
|
|
17
|
+
metastatementNodeQuery = nodeQuery("/statement/metastatement!"),
|
|
18
18
|
typeAssertionNodeQuery = nodeQuery("/statement/typeAssertion!");
|
|
19
19
|
|
|
20
20
|
function verifyStatement(statementNode, assignments, derived, localContext, verifyAhead) {
|
|
@@ -151,11 +151,11 @@ function verifyStatementAboutContainment(statementNode, assignments, derived, lo
|
|
|
151
151
|
localContext.trace(`Verifying the '${statementString}' statement about containment...`, statementNode);
|
|
152
152
|
|
|
153
153
|
const termNode = termNodeQuery(statementNode),
|
|
154
|
-
|
|
155
|
-
containmentVerified = verifyContainment(termNode, containmentNode,
|
|
154
|
+
metastatementNode = metastatementNodeQuery(statementNode),
|
|
155
|
+
containmentVerified = verifyContainment(termNode, containmentNode, metastatementNode, localContext);
|
|
156
156
|
|
|
157
157
|
if (containmentVerified) {
|
|
158
|
-
statementNode = statementNodeQuery(
|
|
158
|
+
statementNode = statementNodeQuery(metastatementNode); ///
|
|
159
159
|
|
|
160
160
|
const verifyStatementFunctions = [
|
|
161
161
|
verifyStatementAsEquality,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { nodeQuery } from "../utilities/query";
|
|
4
|
+
import { STATEMENT_META_TYPE_NAME } from "../metaTypeNames";
|
|
5
|
+
|
|
6
|
+
const metaTypeTerminalNodeQuery = nodeQuery("/metaType/@meta-type!");
|
|
7
|
+
|
|
8
|
+
export default function verifyStatementAgainstMetaType(statementNode, metaTypeNode, localContext, verifyAhead) {
|
|
9
|
+
let statementVerifiedAgainstMetaType = false;
|
|
10
|
+
|
|
11
|
+
const metaTypeTerminalNode = metaTypeTerminalNodeQuery(metaTypeNode),
|
|
12
|
+
content = metaTypeTerminalNode.getContent();
|
|
13
|
+
|
|
14
|
+
if (content === STATEMENT_META_TYPE_NAME) {
|
|
15
|
+
const verifiedAhead = verifyAhead();
|
|
16
|
+
|
|
17
|
+
statementVerifiedAgainstMetaType = verifiedAhead; ///
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return statementVerifiedAgainstMetaType;
|
|
21
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import TermForVariableSubstitution from "../substitution/termForVariable";
|
|
4
|
+
import intrinsicLevelNodesVerifier from "../verifier/nodes/intrinsicLevel";
|
|
5
|
+
|
|
6
|
+
import { push } from "../utilities/array";
|
|
7
|
+
|
|
8
|
+
export default function verifyStatementAgainstStatement(statementNodeA, statementNodeB, substitution, substitutions, localContextA, localContextB) {
|
|
9
|
+
let statementVerifiedAgainstStatement = false;
|
|
10
|
+
|
|
11
|
+
const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitutionAndSubstitutions(substitution, substitutions),
|
|
12
|
+
transformed = termForVariableSubstitution.isTransformed(substitution);
|
|
13
|
+
|
|
14
|
+
let substitutionsA = []; ///
|
|
15
|
+
|
|
16
|
+
if (transformed) {
|
|
17
|
+
const substitutionA = termForVariableSubstitution; ///
|
|
18
|
+
|
|
19
|
+
substitutionsA.push(substitutionA);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const nonTerminalNodeA = statementNodeA, ///
|
|
23
|
+
nonTerminalNodeB = statementNodeB, ///
|
|
24
|
+
nonTerminalNodeVerified = intrinsicLevelNodesVerifier.verifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutionsA, localContextA, localContextB, () => {
|
|
25
|
+
const verifiedAhead = true;
|
|
26
|
+
|
|
27
|
+
return verifiedAhead;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (nonTerminalNodeVerified) {
|
|
31
|
+
if (!transformed) {
|
|
32
|
+
const substitutionB = termForVariableSubstitution, ///
|
|
33
|
+
substitutionsB = [
|
|
34
|
+
substitutionB
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
substitutionsA = transformSubstitutions(substitutionsA, substitutionsB);
|
|
38
|
+
|
|
39
|
+
push(substitutions, substitutionsA);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
statementVerifiedAgainstStatement = true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return statementVerifiedAgainstStatement;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function transformSubstitutions(substitutionsA, substitutionsB) {
|
|
49
|
+
substitutionsA = substitutionsA.map((substitutionA) => {
|
|
50
|
+
const substitution = substitutionA, ///
|
|
51
|
+
substitutions = substitutionsB,
|
|
52
|
+
termForVariableSubstitution = TermForVariableSubstitution.fromSubstitutionAndSubstitutions(substitution, substitutions);
|
|
53
|
+
|
|
54
|
+
substitutionA = termForVariableSubstitution; ///
|
|
55
|
+
|
|
56
|
+
return substitutionA;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return substitutionsA;
|
|
60
|
+
}
|
package/src/verify/term.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Term from "../term";
|
|
4
|
-
import termAgainstConstructorNodesVerifier from "../verifier/nodes/termAgainstConstructor";
|
|
5
|
-
import verifyGivenVariable from "../verify/givenVariable";
|
|
6
4
|
import bracketedConstructor from "../constructor/bracketed";
|
|
5
|
+
import termAgainstConstructorNodesVerifier from "../verifier/nodes/termAgainstConstructor";
|
|
7
6
|
|
|
8
7
|
import { first } from "../utilities/array";
|
|
9
8
|
import { nodeQuery } from "../utilities/query";
|
|
@@ -74,27 +73,24 @@ function verifyTermAsVariable(termNode, terms, localContext, verifyAhead) {
|
|
|
74
73
|
|
|
75
74
|
localContext.trace(`Verifying the '${termString}' term as a variable...`, termNode);
|
|
76
75
|
|
|
77
|
-
const
|
|
78
|
-
givenVariableVerified = verifyGivenVariable(variableNode, variables, localContext, () => {
|
|
79
|
-
let verifiedAhead;
|
|
76
|
+
const variable = localContext.findVariableByVariableNode(variableNode);
|
|
80
77
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
type = variable.getType(),
|
|
84
|
-
term = Term.fromTermNodeAndType(termNode, type);
|
|
78
|
+
if (variable !== null) {
|
|
79
|
+
let verifiedAhead;
|
|
85
80
|
|
|
86
|
-
|
|
81
|
+
const type = variable.getType(),
|
|
82
|
+
term = Term.fromTermNodeAndType(termNode, type);
|
|
87
83
|
|
|
88
|
-
|
|
84
|
+
terms.push(term);
|
|
89
85
|
|
|
90
|
-
|
|
91
|
-
terms.pop();
|
|
92
|
-
}
|
|
86
|
+
verifiedAhead = verifyAhead();
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
if (!verifiedAhead) {
|
|
89
|
+
terms.pop();
|
|
90
|
+
}
|
|
96
91
|
|
|
97
|
-
|
|
92
|
+
termVerifiedAsVariable = verifiedAhead; ///
|
|
93
|
+
}
|
|
98
94
|
|
|
99
95
|
if (termVerifiedAsVariable) {
|
|
100
96
|
localContext.debug(`...verified the '${termString}' term as a variable.`, termNode);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { areTermNodesEqual } from "../utilities/equivalences";
|
|
4
|
+
|
|
5
|
+
export default function verifyTermAgainstTerm(termNodeA, termNodeB, localContext, verifyAhead) {
|
|
6
|
+
let termVerifiedAgainstTerm = false;
|
|
7
|
+
|
|
8
|
+
const leftTermNode = termNodeA, ///
|
|
9
|
+
rightTermNode = termNodeB, ///
|
|
10
|
+
equivalences = localContext.getEquivalences(),
|
|
11
|
+
termNodesEqual = areTermNodesEqual(leftTermNode, rightTermNode, equivalences);
|
|
12
|
+
|
|
13
|
+
if (termNodesEqual) {
|
|
14
|
+
const verifiedAhead = verifyAhead();
|
|
15
|
+
|
|
16
|
+
termVerifiedAgainstTerm = verifiedAhead; ///
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return termVerifiedAgainstTerm;
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { first } from "../utilities/array";
|
|
4
|
+
|
|
5
|
+
export default function verifyTermAgainstType(termNode, typeNode, localContext, verifyAhead, verifyTerm) {
|
|
6
|
+
let termVerifiedAgainstType;
|
|
7
|
+
|
|
8
|
+
const terms = [],
|
|
9
|
+
termVerified = verifyTerm(termNode, terms, localContext, () => {
|
|
10
|
+
let verifiedAhead = false;
|
|
11
|
+
|
|
12
|
+
const firstTerm = first(terms),
|
|
13
|
+
term = firstTerm, ///
|
|
14
|
+
termType = term.getType(),
|
|
15
|
+
type = localContext.findTypeByTypeNode(typeNode),
|
|
16
|
+
termTypeEqualToOrSubTypeOfType = termType.isEqualToOrSubTypeOf(type);
|
|
17
|
+
|
|
18
|
+
if (termTypeEqualToOrSubTypeOfType) {
|
|
19
|
+
verifiedAhead = verifyAhead();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return verifiedAhead;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
termVerifiedAgainstType = termVerified; ///
|
|
26
|
+
|
|
27
|
+
return termVerifiedAgainstType;
|
|
28
|
+
}
|
package/src/verify/terms.js
CHANGED
|
@@ -18,9 +18,7 @@ export default function verifyTerms(termNodes, terms, localContext, verifyAhead)
|
|
|
18
18
|
let verifiedAhead;
|
|
19
19
|
|
|
20
20
|
const secondTermVerified = verifyTerm(secondTermNode, terms, localContext, () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
verifiedAhead = verifyAhead();
|
|
21
|
+
const verifiedAhead = verifyAhead();
|
|
24
22
|
|
|
25
23
|
return verifiedAhead;
|
|
26
24
|
});
|
package/src/verify/type.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Type from "../type";
|
|
4
|
-
import verifyGivenType from "../verify/givenType";
|
|
5
4
|
|
|
6
5
|
import { typeNameFromTypeNode } from "../utilities/name";
|
|
7
6
|
|
|
@@ -52,16 +51,19 @@ export default function verifyType(typeNode, superTypeNode, fileContext) {
|
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
export function verifyStandaloneType(typeNode, localContext, verifyAhead) {
|
|
55
|
-
let standaloneTypeVerified;
|
|
54
|
+
let standaloneTypeVerified = false;
|
|
56
55
|
|
|
57
56
|
const typeString = localContext.nodeAsString(typeNode);
|
|
58
57
|
|
|
59
58
|
localContext.trace(`Verifying the '${typeString}' standalone type...`, typeNode);
|
|
60
59
|
|
|
61
|
-
const
|
|
62
|
-
givenTypeVerified = verifyGivenType(typeNode, types, localContext, verifyAhead);
|
|
60
|
+
const typePresent = localContext.isTypePresentByTypeNode(typeNode);
|
|
63
61
|
|
|
64
|
-
|
|
62
|
+
if (typePresent) {
|
|
63
|
+
const verifiedAhead = verifyAhead();
|
|
64
|
+
|
|
65
|
+
standaloneTypeVerified = verifiedAhead; ///
|
|
66
|
+
}
|
|
65
67
|
|
|
66
68
|
if (standaloneTypeVerified) {
|
|
67
69
|
localContext.debug(`...verified the '${typeString}' standalone type.`, typeNode);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Variable from "../variable";
|
|
4
|
+
import verifyTerm from "../verify/term";
|
|
4
5
|
import VariableAssignment from "../assignment/variable";
|
|
5
|
-
import verifyTermAndGivenType from "../verify/termAndGivenType";
|
|
6
6
|
|
|
7
7
|
import { first } from "../utilities/array";
|
|
8
8
|
import { nodeQuery } from "../utilities/query";
|
|
9
|
-
import { verifyTermAsGivenVariable } from "./term";
|
|
10
9
|
|
|
11
10
|
const termNodeQuery = nodeQuery("/typeAssertion/term!"),
|
|
12
11
|
typeNodeQuery = nodeQuery("/typeAssertion/type!"),
|
|
@@ -21,7 +20,7 @@ export default function verifyTypeAssertion(typeAssertionNode, assignments, deri
|
|
|
21
20
|
|
|
22
21
|
const verifyTypeAssertionFunctions = [
|
|
23
22
|
verifyDerivedTypeAssertion,
|
|
24
|
-
|
|
23
|
+
verifyStatedTypeAssertion
|
|
25
24
|
];
|
|
26
25
|
|
|
27
26
|
typeAssertionVerified = verifyTypeAssertionFunctions.some((verifyTypeAssertionFunction) => {
|
|
@@ -48,38 +47,39 @@ function verifyDerivedTypeAssertion(typeAssertionNode, assignments, derived, loc
|
|
|
48
47
|
localContext.trace(`Verifying the '${typeAssertionString}' derived type assertion...`, typeAssertionNode);
|
|
49
48
|
|
|
50
49
|
const terms = [],
|
|
51
|
-
types = [],
|
|
52
50
|
termNode = termNodeQuery(typeAssertionNode),
|
|
53
|
-
|
|
54
|
-
termAndGivenTypeVerified = verifyTermAndGivenType(termNode, typeNode, terms, types, localContext, () => {
|
|
51
|
+
termVerified = verifyTerm(termNode, terms, localContext, () => {
|
|
55
52
|
let verifiedAhead = false;
|
|
56
53
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
term = firstTerm, ///
|
|
60
|
-
type = firstType, ///
|
|
61
|
-
termType = localContext.getTermType(term),
|
|
62
|
-
typeEqualToOrSuperTypeOfTermType = type.isEqualToOrSuperTypeOf(termType);
|
|
54
|
+
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
55
|
+
type = localContext.findTypeByTypeNode(typeNode);
|
|
63
56
|
|
|
64
|
-
if (
|
|
65
|
-
const
|
|
57
|
+
if (type !== null) {
|
|
58
|
+
const firstTerm = first(terms),
|
|
59
|
+
term = firstTerm, ///
|
|
60
|
+
termType = localContext.getTermType(term),
|
|
61
|
+
typeEqualToOrSuperTypeOfTermType = type.isEqualToOrSuperTypeOf(termType);
|
|
66
62
|
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
} else {
|
|
70
|
-
let variable = localContext.findVariableByVariableNode(variableNode);
|
|
63
|
+
if (typeEqualToOrSuperTypeOfTermType) {
|
|
64
|
+
const variableNode = variableNodeQuery(termNode);
|
|
71
65
|
|
|
72
|
-
|
|
66
|
+
if (variableNode === null) {
|
|
67
|
+
verifiedAhead = verifyAhead();
|
|
68
|
+
} else {
|
|
69
|
+
let variable = localContext.findVariableByVariableNode(variableNode);
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
assignment = variableAssignment; ///
|
|
71
|
+
variable = Variable.fromVariableAndType(variable, type);
|
|
76
72
|
|
|
77
|
-
|
|
73
|
+
const variableAssignment = VariableAssignment.fromVariable(variable),
|
|
74
|
+
assignment = variableAssignment; ///
|
|
78
75
|
|
|
79
|
-
|
|
76
|
+
assignments.push(assignment);
|
|
80
77
|
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
verifiedAhead = verifyAhead();
|
|
79
|
+
|
|
80
|
+
if (!verifiedAhead) {
|
|
81
|
+
assignments.pop();
|
|
82
|
+
}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -87,7 +87,7 @@ function verifyDerivedTypeAssertion(typeAssertionNode, assignments, derived, loc
|
|
|
87
87
|
return verifiedAhead;
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
derivedTypeAssertionVerified =
|
|
90
|
+
derivedTypeAssertionVerified = termVerified; ///
|
|
91
91
|
|
|
92
92
|
if (derivedTypeAssertionVerified) {
|
|
93
93
|
localContext.trace(`...verified the '${typeAssertionString}' derived type assertion.`, typeAssertionNode);
|
|
@@ -97,47 +97,48 @@ function verifyDerivedTypeAssertion(typeAssertionNode, assignments, derived, loc
|
|
|
97
97
|
return derivedTypeAssertionVerified;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
function
|
|
101
|
-
let
|
|
100
|
+
function verifyStatedTypeAssertion(typeAssertionNode, assignments, derived, localContext, verifyAhead) {
|
|
101
|
+
let statedTypeAssertionVerified = false;
|
|
102
102
|
|
|
103
103
|
if (!derived) {
|
|
104
104
|
const typeAssertionString = localContext.nodeAsString(typeAssertionNode);
|
|
105
105
|
|
|
106
|
-
localContext.trace(`Verifying the '${typeAssertionString}'
|
|
106
|
+
localContext.trace(`Verifying the '${typeAssertionString}' stated type assertion...`, typeAssertionNode);
|
|
107
107
|
|
|
108
108
|
const terms = [],
|
|
109
|
-
types = [],
|
|
110
109
|
termNode = termNodeQuery(typeAssertionNode),
|
|
111
|
-
|
|
112
|
-
termAndGivenTypeVerified = verifyTermAndGivenType(termNode, typeNode, terms, types, localContext, () => {
|
|
110
|
+
termVerified = verifyTerm(termNode, terms, localContext, () => {
|
|
113
111
|
let verifiedAhead = false;
|
|
114
112
|
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
114
|
+
type = localContext.findTypeByTypeNode(typeNode);
|
|
115
|
+
|
|
116
|
+
if (type !== null) {
|
|
117
|
+
const firstTerm = first(terms),
|
|
118
|
+
term = firstTerm, ///
|
|
119
|
+
termType = term.getType(),
|
|
120
|
+
typeEqualToOrSubTypeOfTermType = type.isEqualToOrSubTypeOf(termType);
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
if (typeEqualToOrSubTypeOfTermType) {
|
|
123
|
+
const variableNode = variableNodeQuery(termNode);
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
if (variableNode === null) {
|
|
126
|
+
verifiedAhead = verifyAhead();
|
|
127
|
+
} else {
|
|
128
|
+
let variable = localContext.findVariableByVariableNode(variableNode);
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
variable = Variable.fromVariableAndType(variable, type);
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
const variableAssignment = VariableAssignment.fromVariable(variable),
|
|
133
|
+
assignment = variableAssignment; ///
|
|
134
134
|
|
|
135
|
-
|
|
135
|
+
assignments.push(assignment);
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
verifiedAhead = verifyAhead();
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
if (!verifiedAhead) {
|
|
140
|
+
assignments.pop();
|
|
141
|
+
}
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
}
|
|
@@ -145,12 +146,12 @@ function verifyGivenTypeAssertion(typeAssertionNode, assignments, derived, local
|
|
|
145
146
|
return verifiedAhead;
|
|
146
147
|
});
|
|
147
148
|
|
|
148
|
-
|
|
149
|
+
statedTypeAssertionVerified = termVerified; ///
|
|
149
150
|
|
|
150
|
-
if (
|
|
151
|
-
localContext.trace(`...verified the '${typeAssertionString}'
|
|
151
|
+
if (statedTypeAssertionVerified) {
|
|
152
|
+
localContext.trace(`...verified the '${typeAssertionString}' stated type assertion.`, typeAssertionNode);
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
|
|
155
|
-
return
|
|
156
|
+
return statedTypeAssertionVerified;
|
|
156
157
|
}
|
package/src/verify/variable.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import Variable from "../variable";
|
|
4
4
|
import VariableAssignment from "../assignment/variable";
|
|
5
|
-
import verifyGivenVariable from "../verify/givenVariable";
|
|
6
5
|
|
|
7
6
|
import { objectType } from "../type";
|
|
8
7
|
|
|
@@ -54,16 +53,19 @@ export default function verifyVariable(variableNode, typeNode, fileContext) {
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
export function verifyStandaloneVariable(variableNode, localContext, verifyAhead) {
|
|
57
|
-
let standaloneVariableVerified;
|
|
56
|
+
let standaloneVariableVerified = false;
|
|
58
57
|
|
|
59
58
|
const variableString = localContext.nodeAsString(variableNode);
|
|
60
59
|
|
|
61
60
|
localContext.trace(`Verifying the '${variableString}' standalone variable...`, variableNode);
|
|
62
61
|
|
|
63
|
-
const
|
|
64
|
-
givenVariableVerified = verifyGivenVariable(variableNode, variables, localContext, verifyAhead);
|
|
62
|
+
const variablePresent = localContext.isVariablePresentByVariableNode(variableNode);
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
if (variablePresent) {
|
|
65
|
+
const verifiedAhead = verifyAhead();
|
|
66
|
+
|
|
67
|
+
standaloneVariableVerified = verifiedAhead; ///
|
|
68
|
+
}
|
|
67
69
|
|
|
68
70
|
if (standaloneVariableVerified) {
|
|
69
71
|
localContext.debug(`...verified the '${variableString}' standalone variable.`, variableNode);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import verifyTerm from "../verify/term";
|
|
4
|
+
import TermForVariableSubstitution from "../substitution/termForVariable";
|
|
5
|
+
|
|
6
|
+
import { first } from "../utilities/array";
|
|
7
|
+
import { nodeQuery } from "../utilities/query";
|
|
8
|
+
|
|
9
|
+
const variableNodeQuery = nodeQuery("/term/variable");
|
|
10
|
+
|
|
11
|
+
export default function verifyVariableAgainstTerm(variableNode, termNode, substitutions, localContextA, localContextB, verifyAhead) {
|
|
12
|
+
let variableVerifiedAgainstTerm = false;
|
|
13
|
+
|
|
14
|
+
const substitution = substitutions.find((substitution) => {
|
|
15
|
+
const substitutionMatchesVariableNodeA = substitution.matchVariableNode(variableNode);
|
|
16
|
+
|
|
17
|
+
if (substitutionMatchesVariableNodeA) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}) || null;
|
|
21
|
+
|
|
22
|
+
if (substitution !== null) {
|
|
23
|
+
const termNodeMatches = substitution.matchTermNode(termNode);
|
|
24
|
+
|
|
25
|
+
if (termNodeMatches) {
|
|
26
|
+
const verifiedAhead = verifyAhead();
|
|
27
|
+
|
|
28
|
+
variableVerifiedAgainstTerm = verifiedAhead; ///
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
const variableA = localContextA.findVariableByVariableNode(variableNode);
|
|
32
|
+
|
|
33
|
+
if (variableA !== null) {
|
|
34
|
+
const terms = [],
|
|
35
|
+
termVerified = verifyTerm(termNode, terms, localContextB, () => {
|
|
36
|
+
let verifiedAhead = false;
|
|
37
|
+
|
|
38
|
+
const firstTerm = first(terms),
|
|
39
|
+
termB = firstTerm, ///
|
|
40
|
+
variableB = variableFromTerm(termB, localContextB);
|
|
41
|
+
|
|
42
|
+
if (variableA === variableB) {
|
|
43
|
+
verifiedAhead = verifyAhead();
|
|
44
|
+
} else {
|
|
45
|
+
const term = termB, ///
|
|
46
|
+
variable = variableA, ///
|
|
47
|
+
termType = term.getType(),
|
|
48
|
+
variableType = variable.getType(),
|
|
49
|
+
variableTypeEqualToOrSuperTypeOfTermType = variableType.isEqualToOrSuperTypeOf(termType);
|
|
50
|
+
|
|
51
|
+
if (variableTypeEqualToOrSuperTypeOfTermType) {
|
|
52
|
+
const termForVariableSubstitution = TermForVariableSubstitution.fromVariableNodeAndTermNode(variableNode, termNode),
|
|
53
|
+
substitution = termForVariableSubstitution; ///
|
|
54
|
+
|
|
55
|
+
substitutions.push(substitution);
|
|
56
|
+
|
|
57
|
+
verifiedAhead = verifyAhead();
|
|
58
|
+
|
|
59
|
+
if (!verifiedAhead) {
|
|
60
|
+
substitutions.pop();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return verifiedAhead;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
variableVerifiedAgainstTerm = termVerified; ///
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return variableVerifiedAgainstTerm;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function variableFromTerm(term, localContext) {
|
|
76
|
+
let variable = null;
|
|
77
|
+
|
|
78
|
+
const termNode = term.getNode(),
|
|
79
|
+
variableNode = variableNodeQuery(termNode);
|
|
80
|
+
|
|
81
|
+
if (variableNode !== null) {
|
|
82
|
+
variable = localContext.findVariableByVariableNode(variableNode);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return variable;
|
|
86
|
+
}
|