occam-verify-cli 0.0.697 → 0.0.698
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/assignment/equality.js +6 -4
- package/lib/assignment/metavariable.js +62 -0
- package/lib/assignment/variable.js +6 -4
- package/lib/context/file.js +34 -26
- package/lib/context/local.js +24 -16
- package/lib/context/localMeta.js +17 -13
- package/lib/equality.js +13 -5
- package/lib/metavariable.js +25 -22
- package/lib/substitution/metastatementForMetavariable.js +17 -10
- package/lib/substitution/statementForMetavariable.js +17 -10
- package/lib/substitution/termForVariable.js +17 -11
- package/lib/utilities/query.js +2 -16
- package/lib/variable.js +33 -27
- package/lib/verifier/node/metastatement.js +2 -3
- package/lib/verifier/node.js +2 -2
- package/lib/verifier/nodes/metastatementForMetavariable.js +5 -5
- package/lib/verifier/nodes/statementForMetavariable.js +5 -5
- package/lib/verifier/nodes/termForVariable.js +6 -6
- package/lib/verifier/nodes.js +2 -2
- package/lib/verify/derivation.js +2 -2
- package/lib/verify/equality.js +3 -3
- package/lib/verify/file.js +2 -2
- package/lib/verify/metavariable.js +8 -6
- package/lib/verify/standaloneType.js +32 -0
- package/lib/verify/statement/unqualified.js +2 -2
- package/lib/verify/supposition.js +7 -4
- package/lib/verify/term.js +3 -3
- package/lib/verify/termAndStandaloneType.js +39 -0
- package/lib/verify/termAsVariableAndStandaloneType.js +39 -0
- package/lib/verify/theorem.js +3 -3
- package/lib/verify/type.js +2 -2
- package/lib/verify/typeAssertion.js +57 -91
- package/lib/verify/variable.js +12 -10
- package/package.json +1 -1
- package/src/assignment/equality.js +12 -3
- package/src/assignment/metavariable.js +30 -0
- package/src/assignment/variable.js +12 -3
- package/src/context/file.js +41 -29
- package/src/context/local.js +34 -19
- package/src/context/localMeta.js +21 -15
- package/src/equality.js +10 -3
- package/src/metavariable.js +25 -18
- package/src/substitution/metastatementForMetavariable.js +13 -7
- package/src/substitution/statementForMetavariable.js +13 -7
- package/src/substitution/termForVariable.js +13 -9
- package/src/utilities/query.js +1 -19
- package/src/variable.js +41 -26
- package/src/verifier/node/metastatement.js +1 -3
- package/src/verifier/nodes/metastatementForMetavariable.js +5 -7
- package/src/verifier/nodes/statementForMetavariable.js +5 -7
- package/src/verifier/nodes/termForVariable.js +6 -8
- package/src/verify/derivation.js +1 -1
- package/src/verify/equality.js +2 -2
- package/src/verify/file.js +1 -1
- package/src/verify/metavariable.js +10 -9
- package/src/verify/standaloneType.js +34 -0
- package/src/verify/statement/unqualified.js +1 -1
- package/src/verify/supposition.js +7 -3
- package/src/verify/term.js +3 -4
- package/src/verify/termAndStandaloneType.js +37 -0
- package/src/verify/termAsVariableAndStandaloneType.js +38 -0
- package/src/verify/theorem.js +2 -2
- package/src/verify/type.js +1 -1
- package/src/verify/typeAssertion.js +76 -112
- package/src/verify/variable.js +13 -13
|
@@ -1,165 +1,129 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import Variable from "../variable";
|
|
4
3
|
import VariableAssignment from "../assignment/variable";
|
|
4
|
+
import verifyTermAndStandaloneType from "../verify/termAndStandaloneType";
|
|
5
|
+
import verifyTermAsVariableAndStandaloneType from "../verify/termAsVariableAndStandaloneType";
|
|
5
6
|
|
|
6
7
|
import { first } from "../utilities/array";
|
|
7
|
-
import { nodeQuery
|
|
8
|
-
import { verifyTermAsVariable, verifyTermAgainstConstructors } from "../verify/term";
|
|
8
|
+
import { nodeQuery } from "../utilities/query";
|
|
9
9
|
|
|
10
10
|
const termNodeQuery = nodeQuery("/typeAssertion/term!"),
|
|
11
11
|
typeNodeQuery = nodeQuery("/typeAssertion/type!");
|
|
12
12
|
|
|
13
13
|
export default function verifyTypeAssertion(typeAssertionNode, assignments, derived, context, verifyAhead) {
|
|
14
|
-
let typeAssertionVerified
|
|
14
|
+
let typeAssertionVerified;
|
|
15
15
|
|
|
16
16
|
const typeAssertionString = context.nodeAsString(typeAssertionNode);
|
|
17
17
|
|
|
18
18
|
context.trace(`Verifying the '${typeAssertionString}' type assertion...`, typeAssertionNode);
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
typeAssertionVerified = verifyTypeAssertionFunctions.some((verifyTypeAssertionFunction) => {
|
|
34
|
-
const typeAssertionVerified = verifyTypeAssertionFunction(typeAssertionNode, assertedType, assignments, derived, context, verifyAhead);
|
|
35
|
-
|
|
36
|
-
if (typeAssertionVerified) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
20
|
+
const verifyTypeAssertionFunctions = [
|
|
21
|
+
verifyDerivedTypeAssertion,
|
|
22
|
+
verifyStandaloneTypeAssertion
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
typeAssertionVerified = verifyTypeAssertionFunctions.some((verifyTypeAssertionFunction) => {
|
|
26
|
+
const typeAssertionVerified = verifyTypeAssertionFunction(typeAssertionNode, assignments, derived, context, verifyAhead);
|
|
27
|
+
|
|
28
|
+
if (typeAssertionVerified) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
41
32
|
|
|
42
33
|
if (typeAssertionVerified) {
|
|
43
|
-
context.debug(`...verified the '${typeAssertionString}'
|
|
34
|
+
context.debug(`...verified the '${typeAssertionString}' type assertion.`, typeAssertionNode);
|
|
44
35
|
}
|
|
45
36
|
|
|
46
37
|
return typeAssertionVerified;
|
|
47
38
|
}
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
const typeAssertionString = context.nodeAsString(typeAssertionNode);
|
|
53
|
-
|
|
54
|
-
context.trace(`Verifying the '${typeAssertionString}' variable type assertion...`, typeAssertionNode);
|
|
40
|
+
function verifyDerivedTypeAssertion(typeAssertionNode, assignments, derived, context, verifyAhead) {
|
|
41
|
+
let derivedTypeAssertionVerified = false;
|
|
55
42
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context, () => {
|
|
59
|
-
let verifiedAhead = false;
|
|
43
|
+
if (derived) {
|
|
44
|
+
const typeAssertionString = context.nodeAsString(typeAssertionNode);
|
|
60
45
|
|
|
61
|
-
|
|
62
|
-
variable = firstVariable, ///
|
|
63
|
-
variableName = variable.getName(),
|
|
64
|
-
variableType = variable.getType();
|
|
46
|
+
context.trace(`Verifying the '${typeAssertionString}' derived type assertion...`, typeAssertionNode);
|
|
65
47
|
|
|
66
|
-
|
|
67
|
-
|
|
48
|
+
const terms = [],
|
|
49
|
+
types = [],
|
|
50
|
+
termNode = termNodeQuery(typeAssertionNode),
|
|
51
|
+
typeNode = typeNodeQuery(typeAssertionNode),
|
|
52
|
+
termAndStandaloneTypeVerified = verifyTermAndStandaloneType(termNode, typeNode, terms, types, context, () => {
|
|
53
|
+
let verifiedAhead = false;
|
|
68
54
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
verifiedAhead = verifyAhead();
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
const assertedTypeEqualToOrSubTypeOfVariableType = assertedType.isEqualToOrSubTypeOf(variableType);
|
|
79
|
-
|
|
80
|
-
if (!assertedTypeEqualToOrSubTypeOfVariableType) {
|
|
81
|
-
const assertedTypeName = assertedType.getName(),
|
|
82
|
-
variableTypeName = variableType.getName();
|
|
83
|
-
|
|
84
|
-
context.debug(`The '${assertedTypeName}' asserted type is not equal to or a sub-type of the '${variableName}' variable's '${variableTypeName}' type.`, typeAssertionNode);
|
|
85
|
-
} else {
|
|
86
|
-
const name = variableName, ///
|
|
87
|
-
type = assertedType, ///
|
|
88
|
-
variable = Variable.fromNameAndType(name, type),
|
|
89
|
-
variableAssignment = VariableAssignment.fromVariable(variable),
|
|
90
|
-
assignment = variableAssignment; ///
|
|
91
|
-
|
|
92
|
-
assignments.push(assignment);
|
|
55
|
+
const firstTerm = first(terms),
|
|
56
|
+
firstType = first(types),
|
|
57
|
+
term = firstTerm, ///
|
|
58
|
+
type = firstType, ///
|
|
59
|
+
termType = term.getType(),
|
|
60
|
+
termTypeEqualToOrSuperTypeOfType = termType.isEqualToOrSuperTypeOf(type);
|
|
93
61
|
|
|
94
|
-
|
|
62
|
+
if (termTypeEqualToOrSuperTypeOfType) {
|
|
63
|
+
debugger
|
|
95
64
|
|
|
96
|
-
if (
|
|
97
|
-
|
|
65
|
+
if (false) { ///
|
|
66
|
+
verifiedAhead = verifyAhead();
|
|
98
67
|
}
|
|
99
68
|
}
|
|
100
|
-
}
|
|
101
69
|
|
|
102
|
-
|
|
103
|
-
|
|
70
|
+
return verifiedAhead;
|
|
71
|
+
});
|
|
104
72
|
|
|
105
|
-
|
|
73
|
+
derivedTypeAssertionVerified = termAndStandaloneTypeVerified; ///
|
|
106
74
|
|
|
107
|
-
|
|
108
|
-
|
|
75
|
+
if (derivedTypeAssertionVerified) {
|
|
76
|
+
context.trace(`...verified the '${typeAssertionString}' derived type assertion.`, typeAssertionNode);
|
|
77
|
+
}
|
|
109
78
|
}
|
|
110
79
|
|
|
111
|
-
return
|
|
80
|
+
return derivedTypeAssertionVerified;
|
|
112
81
|
}
|
|
113
82
|
|
|
114
|
-
function
|
|
115
|
-
let
|
|
83
|
+
function verifyStandaloneTypeAssertion(typeAssertionNode, assignments, derived, context, verifyAhead) {
|
|
84
|
+
let standaloneTypeAssertionVerified = false;
|
|
116
85
|
|
|
117
|
-
|
|
86
|
+
if (!derived) {
|
|
87
|
+
const typeAssertionString = context.nodeAsString(typeAssertionNode);
|
|
118
88
|
|
|
119
|
-
|
|
89
|
+
context.trace(`Verifying the '${typeAssertionString}' standalone type assertion...`, typeAssertionNode);
|
|
120
90
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
91
|
+
const types = [],
|
|
92
|
+
variables = [],
|
|
93
|
+
termNode = termNodeQuery(typeAssertionNode),
|
|
94
|
+
typeNode = typeNodeQuery(typeAssertionNode),
|
|
95
|
+
termAsVariableAndStandaloneTypeVerified = verifyTermAsVariableAndStandaloneType(termNode, typeNode, variables, types, context, () => {
|
|
96
|
+
let verifiedAhead = false;
|
|
125
97
|
|
|
126
|
-
|
|
127
|
-
|
|
98
|
+
const firstVariable = first(variables),
|
|
99
|
+
firstType = first(types),
|
|
100
|
+
variable = firstVariable, ///
|
|
101
|
+
type = firstType, ///
|
|
102
|
+
variableType = variable.getType(),
|
|
103
|
+
variableTypeEqualToOrSuperTypeOfType = variableType.isEqualToOrSuperTypeOf(type);
|
|
128
104
|
|
|
129
|
-
|
|
130
|
-
|
|
105
|
+
if (variableTypeEqualToOrSuperTypeOfType) {
|
|
106
|
+
const variableAssignment = VariableAssignment.fromVariable(variable),
|
|
107
|
+
assignment = variableAssignment; ///
|
|
131
108
|
|
|
132
|
-
|
|
133
|
-
const termString = context.nodeAsString(termNode),
|
|
134
|
-
termTypeName = termType.getName(),
|
|
135
|
-
assertedTypeName = assertedType.getName();
|
|
109
|
+
assignments.push(assignment);
|
|
136
110
|
|
|
137
|
-
context.debug(`The '${assertedTypeName}' asserted type is not equal to or a super-type of the '${termString}' term's '${termTypeName}' type.`, typeAssertionNode);
|
|
138
|
-
} else {
|
|
139
111
|
verifiedAhead = verifyAhead();
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
const assertedTypeIsEqualToOrSubTypeOfTermType = assertedType.isEqualToOrSubTypeOf(termType);
|
|
143
|
-
|
|
144
|
-
if (!assertedTypeIsEqualToOrSubTypeOfTermType) {
|
|
145
|
-
const termString = context.nodeAsString(termNode),
|
|
146
|
-
termTypeName = termType.getName(),
|
|
147
|
-
assertedTypeName = assertedType.getName();
|
|
148
112
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
113
|
+
if (!verifiedAhead) {
|
|
114
|
+
assignments.pop();
|
|
115
|
+
}
|
|
152
116
|
}
|
|
153
|
-
}
|
|
154
117
|
|
|
155
|
-
|
|
156
|
-
|
|
118
|
+
return verifiedAhead;
|
|
119
|
+
});
|
|
157
120
|
|
|
158
|
-
|
|
121
|
+
standaloneTypeAssertionVerified = termAsVariableAndStandaloneTypeVerified; ///
|
|
159
122
|
|
|
160
|
-
|
|
161
|
-
|
|
123
|
+
if (standaloneTypeAssertionVerified) {
|
|
124
|
+
context.trace(`...verified the '${typeAssertionString}' standalone type assertion.`, typeAssertionNode);
|
|
125
|
+
}
|
|
162
126
|
}
|
|
163
127
|
|
|
164
|
-
return
|
|
128
|
+
return standaloneTypeAssertionVerified;
|
|
165
129
|
}
|
package/src/verify/variable.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Variable from "../variable";
|
|
4
|
+
import VariableAssignment from "../assignment/variable";
|
|
4
5
|
|
|
5
6
|
import { objectType } from "../type";
|
|
6
|
-
import { typeNameFromTypeNode
|
|
7
|
+
import { typeNameFromTypeNode } from "../utilities/query";
|
|
7
8
|
|
|
8
9
|
export default function verifyVariable(variableNode, typeNode, fileContext) {
|
|
9
10
|
let variableVerified = false;
|
|
@@ -12,37 +13,36 @@ export default function verifyVariable(variableNode, typeNode, fileContext) {
|
|
|
12
13
|
|
|
13
14
|
fileContext.trace(`Verifying the '${variableString}' variable...`, variableNode);
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
-
variablePresent = fileContext.isVariablePresentByVariableName(variableName);
|
|
16
|
+
const variablePresent = fileContext.isVariablePresentByVariableNode(variableNode);
|
|
17
17
|
|
|
18
18
|
if (variablePresent) {
|
|
19
|
-
fileContext.debug(`The variable '${
|
|
19
|
+
fileContext.debug(`The variable '${variableString}' is already present.`, variableNode);
|
|
20
20
|
} else {
|
|
21
21
|
let variable;
|
|
22
22
|
|
|
23
23
|
const typeName = typeNameFromTypeNode(typeNode);
|
|
24
24
|
|
|
25
25
|
if (typeName === null) {
|
|
26
|
-
const
|
|
27
|
-
type = objectType;
|
|
26
|
+
const type = objectType;
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
variable = Variable.fromVariableNodeAndType(variableNode, type);
|
|
30
29
|
} else {
|
|
31
30
|
const type = fileContext.findTypeByTypeName(typeName);
|
|
32
31
|
|
|
33
32
|
if (type === null) {
|
|
34
|
-
fileContext.debug(`The '${
|
|
33
|
+
fileContext.debug(`The '${variableString}' variable's '${typeName}' type is not present.`, variableNode);
|
|
35
34
|
} else {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
variable = Variable.fromNameAndType(name, type);
|
|
35
|
+
variable = Variable.fromVariableNodeAndType(variableNode, type);
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
if (variable !== null) {
|
|
43
|
-
|
|
40
|
+
const variableAssignment = VariableAssignment.fromVariable(variable),
|
|
41
|
+
variableAssigned = variableAssignment.assign(fileContext);
|
|
44
42
|
|
|
45
|
-
|
|
43
|
+
if (variableAssigned) {
|
|
44
|
+
variableVerified = true;
|
|
45
|
+
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|