occam-verify-cli 0.0.532 → 0.0.533
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/assertion.js +60 -0
- package/lib/constants.js +1 -5
- package/lib/context/proof.js +1 -20
- package/lib/equality.js +61 -29
- package/lib/variable.js +23 -3
- package/lib/verify/assertion/type.js +56 -68
- package/lib/verify/statement.js +83 -28
- package/package.json +1 -1
- package/src/{assertion/type.js → assertion.js} +3 -3
- package/src/constants.js +0 -1
- package/src/context/proof.js +0 -25
- package/src/equality.js +35 -39
- package/src/variable.js +18 -2
- package/src/verify/assertion/type.js +83 -82
- package/src/verify/statement.js +76 -22
- package/lib/assertion/type.js +0 -60
- package/lib/node/statement/equality.js +0 -16
- package/src/node/statement/equality.js +0 -10
package/src/equality.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import Variable from "./variable";
|
|
4
4
|
import verifyTerm from "./verify/term";
|
|
5
|
-
import equalityCombinator from "./ocmbinator/equality";
|
|
6
|
-
import equalityStatementNode from "./node/statement/equality";
|
|
7
5
|
|
|
8
6
|
import { nodeQuery } from "./utilities/query";
|
|
9
7
|
import { first, second } from "./utilities/array";
|
|
10
|
-
import { EQUALITY_DEPTH } from "./constants";
|
|
11
8
|
import { TERM_RULE_NAME } from "./ruleNames";
|
|
12
|
-
import {
|
|
9
|
+
import { verifyTermAsVariable } from "./verify/term";
|
|
13
10
|
|
|
14
11
|
const leftTermNodeQuery = nodeQuery("/statement/argument[0]/term!"),
|
|
15
12
|
rightTermNodeQuery = nodeQuery("/statement/argument[1]/term!");
|
|
@@ -88,40 +85,10 @@ export default class Equality {
|
|
|
88
85
|
return equates;
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
static fromProofStep(proofStep) {
|
|
92
|
-
let equality = null;
|
|
93
|
-
|
|
94
|
-
const statementNode = proofStep.getStatementNode();
|
|
95
|
-
|
|
96
|
-
if (statementNode !== null) {
|
|
97
|
-
const nodeA = statementNode, ///
|
|
98
|
-
nodeB = equalityStatementNode, ///
|
|
99
|
-
depth = EQUALITY_DEPTH,
|
|
100
|
-
nodeMatches = matcher.matchNode(nodeA, nodeB, depth);
|
|
101
|
-
|
|
102
|
-
if (nodeMatches) {
|
|
103
|
-
const leftTermNode = leftTermNodeQuery(statementNode),
|
|
104
|
-
rightTermNode = rightTermNodeQuery(statementNode);
|
|
105
|
-
|
|
106
|
-
equality = new Equality(leftTermNode, rightTermNode);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return equality;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
88
|
static fromStatementNode(statementNode, context) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
statementVerifiedAgainstCombinator = verifyStatementAgainstCombinator(statementNode, combinator, context);
|
|
118
|
-
|
|
119
|
-
if (statementVerifiedAgainstCombinator) {
|
|
120
|
-
const leftTermNode = leftTermNodeQuery(statementNode),
|
|
121
|
-
rightTermNode = rightTermNodeQuery(statementNode);
|
|
122
|
-
|
|
123
|
-
equality = new Equality(leftTermNode, rightTermNode);
|
|
124
|
-
}
|
|
89
|
+
const leftTermNode = leftTermNodeQuery(statementNode),
|
|
90
|
+
rightTermNode = rightTermNodeQuery(statementNode),
|
|
91
|
+
equality = equalityFromLeftTermNodeAndRightTermNode(leftTermNode, rightTermNode, context);
|
|
125
92
|
|
|
126
93
|
return equality;
|
|
127
94
|
}
|
|
@@ -264,12 +231,41 @@ function equalityFromLeftTermNodeAndRightTermNode(leftTermNode, rightTermNode, c
|
|
|
264
231
|
if (leftTermTypeEqualToRightTermType) {
|
|
265
232
|
equality = new Equality(leftTermNode, rightTermNode);
|
|
266
233
|
} else {
|
|
234
|
+
const leftTermTypeSubTypeOfRightTermType = leftTermType.isSubTypeOf(rightTermType);
|
|
235
|
+
|
|
236
|
+
if (false) {
|
|
237
|
+
///
|
|
238
|
+
} else if (leftTermTypeSubTypeOfRightTermType) {
|
|
239
|
+
const variables = [],
|
|
240
|
+
rightTermVerifiedAsVariable = verifyTermAsVariable(rightTermNode, variables, context);
|
|
241
|
+
|
|
242
|
+
if (rightTermVerifiedAsVariable) {
|
|
243
|
+
let rightVariable;
|
|
244
|
+
|
|
245
|
+
const firstVariable = first(variables);
|
|
246
|
+
|
|
247
|
+
rightVariable = firstVariable; ///
|
|
248
|
+
|
|
249
|
+
const rightVariableName = rightVariable.getName(),
|
|
250
|
+
rightName = rightVariableName, ///
|
|
251
|
+
rightType = leftTermType; ///
|
|
252
|
+
|
|
253
|
+
rightVariable = Variable.fromTypeAndName(rightType, rightName);
|
|
254
|
+
|
|
255
|
+
context.addVariable(rightVariable);
|
|
256
|
+
|
|
257
|
+
equality = new Equality(leftTermNode, rightTermNode);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (equality === null) {
|
|
267
263
|
const leftTermString = context.nodeAsString(leftTermNode),
|
|
268
264
|
rightTermString = context.nodeAsString(rightTermNode),
|
|
269
265
|
leftTermTypeName = leftTermType.getName(),
|
|
270
266
|
rightTermTypeName = rightTermType.getName();
|
|
271
267
|
|
|
272
|
-
context.error(`The left '${leftTermString}' term's '${leftTermTypeName}' type is not equal to the right '${rightTermString}' term's '${rightTermTypeName}' type.'`, leftTermNode);
|
|
268
|
+
context.error(`The left '${leftTermString}' term's '${leftTermTypeName}' type is not equal to the right '${rightTermString}' term's '${rightTermTypeName}' type and neither can be inferred.'`, leftTermNode);
|
|
273
269
|
}
|
|
274
270
|
}
|
|
275
271
|
|
package/src/variable.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export default class Variable {
|
|
4
|
-
constructor(type, name) {
|
|
4
|
+
constructor(type, name, termNode) {
|
|
5
5
|
this.type = type;
|
|
6
6
|
this.name = name;
|
|
7
|
+
this.termNode = termNode;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
getType() {
|
|
@@ -14,6 +15,14 @@ export default class Variable {
|
|
|
14
15
|
return this.name;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
getTermNode() {
|
|
19
|
+
return this.termNode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isUndefined() {
|
|
23
|
+
return (this.termNode === null);
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
matchName(name) {
|
|
18
27
|
const matchesName = (this.name === name);
|
|
19
28
|
|
|
@@ -28,7 +37,14 @@ export default class Variable {
|
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
static fromTypeAndName(type, name) {
|
|
31
|
-
const
|
|
40
|
+
const termNode = null,
|
|
41
|
+
variable = new Variable(type, name, termNode);
|
|
42
|
+
|
|
43
|
+
return variable;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static fromTypeNameAndTermNode(type, name, termNode) {
|
|
47
|
+
const variable = new Variable(type, name, termNode);
|
|
32
48
|
|
|
33
49
|
return variable;
|
|
34
50
|
}
|
|
@@ -1,54 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Variable from "../../variable";
|
|
4
|
-
import
|
|
4
|
+
import Assertion from "../../assertion";
|
|
5
5
|
|
|
6
6
|
import { first } from "../../utilities/array";
|
|
7
|
-
import { verifyTermAsVariable } from "../../verify/term";
|
|
8
7
|
import { nodeQuery, typeNameFromTypeNode } from "../../utilities/query";
|
|
8
|
+
import { verifyTermAsVariable, verifyTermAgainstConstructors } from "../../verify/term";
|
|
9
9
|
|
|
10
10
|
const termNodeQuery = nodeQuery("/typeAssertion/term"),
|
|
11
11
|
typeNodeQuery = nodeQuery("/typeAssertion/type");
|
|
12
12
|
|
|
13
|
-
export default function verifyTypeAssertion(typeAssertionNode, assertions, derived,
|
|
13
|
+
export default function verifyTypeAssertion(typeAssertionNode, assertions, derived, context) {
|
|
14
14
|
let typeAssertionVerified = false;
|
|
15
15
|
|
|
16
|
-
const typeAssertionString =
|
|
16
|
+
const typeAssertionString = context.nodeAsString(typeAssertionNode);
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
context.debug(`Verifying the '${typeAssertionString}' type assertion...`, typeAssertionNode);
|
|
19
19
|
|
|
20
20
|
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
21
21
|
typeName = typeNameFromTypeNode(typeNode),
|
|
22
|
-
typePresent =
|
|
22
|
+
typePresent = context.isTypePresentByTypeName(typeName);
|
|
23
23
|
|
|
24
24
|
if (!typePresent) {
|
|
25
|
-
|
|
25
|
+
context.error(`The ${typeName} type is not present.`, typeAssertionNode);
|
|
26
26
|
} else {
|
|
27
27
|
if (!typeAssertionVerified) {
|
|
28
|
-
const variableTypeAssertionVerified = verifyVariableTypeAssertion(typeAssertionNode, assertions, derived,
|
|
28
|
+
const variableTypeAssertionVerified = verifyVariableTypeAssertion(typeAssertionNode, assertions, derived, context);
|
|
29
29
|
|
|
30
30
|
typeAssertionVerified = variableTypeAssertionVerified; ///
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
if (!typeAssertionVerified) {
|
|
34
|
+
const termTypeAssertionVerified = verifyTermTypeAssertion(typeAssertionNode, context);
|
|
35
|
+
|
|
36
|
+
typeAssertionVerified = termTypeAssertionVerified; ///
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (typeAssertionVerified) {
|
|
41
|
-
|
|
41
|
+
context.info(`Verified the '${typeAssertionString}' statement type assertion.`, typeAssertionNode);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
return typeAssertionVerified;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function verifyVariableTypeAssertion(typeAssertionNode, assertions, derived,
|
|
47
|
+
function verifyVariableTypeAssertion(typeAssertionNode, assertions, derived, context) {
|
|
48
48
|
let variableTypeAssertionVerified = false;
|
|
49
49
|
|
|
50
|
-
const
|
|
51
|
-
variables = [],
|
|
50
|
+
const variables = [],
|
|
52
51
|
termNode = termNodeQuery(typeAssertionNode),
|
|
53
52
|
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context);
|
|
54
53
|
|
|
@@ -56,41 +55,45 @@ function verifyVariableTypeAssertion(typeAssertionNode, assertions, derived, pro
|
|
|
56
55
|
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
57
56
|
typeName = typeNameFromTypeNode(typeNode),
|
|
58
57
|
assertedTypeName = typeName, ///
|
|
59
|
-
assertedType =
|
|
60
|
-
firstVariable = first(variables),
|
|
61
|
-
variable = firstVariable, ///
|
|
62
|
-
variableName = variable.getName(),
|
|
63
|
-
variableType = variable.getType();
|
|
64
|
-
|
|
65
|
-
if (derived) {
|
|
66
|
-
const variableTypeEqualToOrSubTypeOfAssertedType = variableType.isEqualToOrSubTypeOf(assertedType);
|
|
58
|
+
assertedType = context.findTypeByTypeName(assertedTypeName);
|
|
67
59
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
variableTypeName = variableType.getName();
|
|
71
|
-
|
|
72
|
-
proofContext.error(`The '${variableName}' variable's '${variableTypeName}' type is not equal to or a sub-type of the '${assertedTypeName}' asserted type.`, typeAssertionNode);
|
|
73
|
-
} else {
|
|
74
|
-
variableTypeAssertionVerified = true;
|
|
75
|
-
}
|
|
60
|
+
if (assertedType === null) {
|
|
61
|
+
context.error(`The '${assertedTypeName}' asserted type is not present.`, typeAssertionNode);
|
|
76
62
|
} else {
|
|
77
|
-
const
|
|
63
|
+
const firstVariable = first(variables),
|
|
64
|
+
variable = firstVariable, ///
|
|
65
|
+
variableName = variable.getName(),
|
|
66
|
+
variableType = variable.getType();
|
|
67
|
+
|
|
68
|
+
if (derived) {
|
|
69
|
+
const variableTypeEqualToOrSubTypeOfAssertedType = variableType.isEqualToOrSubTypeOf(assertedType);
|
|
70
|
+
|
|
71
|
+
if (!variableTypeEqualToOrSubTypeOfAssertedType) {
|
|
72
|
+
const assertedTypeName = assertedType.getName(),
|
|
73
|
+
variableTypeName = variableType.getName();
|
|
74
|
+
|
|
75
|
+
context.error(`The '${variableName}' variable's '${variableTypeName}' type is not equal to or a sub-type of the '${assertedTypeName}' asserted type.`, typeAssertionNode);
|
|
76
|
+
} else {
|
|
77
|
+
variableTypeAssertionVerified = true;
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const assertedTypeEqualToOrSubTypeOfVariableType = assertedType.isEqualToOrSubTypeOf(variableType);
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
if (!assertedTypeEqualToOrSubTypeOfVariableType) {
|
|
83
|
+
const assertedTypeName = assertedType.getName(),
|
|
84
|
+
variableTypeName = variableType.getName();
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
assertion = typeAssertion; ///
|
|
86
|
+
context.error(`The '${assertedTypeName}' asserted type is not equal to or a sub-type of the '${variableName}' variable's '${variableTypeName}' type.`, typeAssertionNode);
|
|
87
|
+
} else {
|
|
88
|
+
const type = assertedType, ///
|
|
89
|
+
name = variableName, ///
|
|
90
|
+
variable = Variable.fromTypeAndName(type, name),
|
|
91
|
+
assertion = Assertion.fromVariable(variable);
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
assertions.push(assertion);
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
variableTypeAssertionVerified = true;
|
|
96
|
+
}
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -98,40 +101,38 @@ function verifyVariableTypeAssertion(typeAssertionNode, assertions, derived, pro
|
|
|
98
101
|
return variableTypeAssertionVerified;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// return termTypeAssertionVerified;
|
|
136
|
-
// }
|
|
104
|
+
function verifyTermTypeAssertion(typeAssertionNode, context) {
|
|
105
|
+
let termTypeAssertionVerified = false;
|
|
106
|
+
|
|
107
|
+
const types = [],
|
|
108
|
+
termNode = termNodeQuery(typeAssertionNode),
|
|
109
|
+
termVerifiedAgainstConstructors = verifyTermAgainstConstructors(termNode, types, context);
|
|
110
|
+
|
|
111
|
+
if (termVerifiedAgainstConstructors) {
|
|
112
|
+
const typeNode = typeNodeQuery(typeAssertionNode),
|
|
113
|
+
typeName = typeNameFromTypeNode(typeNode),
|
|
114
|
+
assertedTypeName = typeName, ///
|
|
115
|
+
assertedType = context.findTypeByTypeName(assertedTypeName);
|
|
116
|
+
|
|
117
|
+
if (assertedType === null) {
|
|
118
|
+
context.error(`The '${assertedTypeName}' asserted type is not present.`, typeAssertionNode);
|
|
119
|
+
} else {
|
|
120
|
+
const firstType = first(types),
|
|
121
|
+
termType = firstType, ///
|
|
122
|
+
termTypeIsEqualToAssertedType = termType.isEqualTo(assertedType);
|
|
123
|
+
|
|
124
|
+
if (!termTypeIsEqualToAssertedType) {
|
|
125
|
+
const termString = context.nodeAsString(termNode),
|
|
126
|
+
termTypeName = termType.getName(),
|
|
127
|
+
assertedTypeName = assertedType.getName();
|
|
128
|
+
|
|
129
|
+
context.error(`The '${assertedTypeName}' asserted type is not equal to the '${termString}' term's '${termTypeName}' type.`, typeAssertionNode);
|
|
130
|
+
} else {
|
|
131
|
+
termTypeAssertionVerified = true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return termTypeAssertionVerified;
|
|
137
|
+
}
|
|
137
138
|
|
package/src/verify/statement.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import Variable from "../variable";
|
|
4
|
+
import Assertion from "../assertion";
|
|
4
5
|
import verifyTerm from "../verify/term";
|
|
6
|
+
import equalityCombinator from "../ocmbinator/equality";
|
|
5
7
|
import bracketedCombinator from "../ocmbinator/bracketed";
|
|
6
8
|
import verifyTypeAssertion from "../verify/assertion/type";
|
|
7
9
|
|
|
8
10
|
import { first } from "../utilities/array";
|
|
9
11
|
import { objectType } from "../type";
|
|
12
|
+
import { nodeAsString } from "../utilities/string";
|
|
10
13
|
import { OBJECT_TYPE_NAME } from "../typeNames";
|
|
11
14
|
import { STATEMENT_META_TYPE } from "../metaTypes";
|
|
15
|
+
import { verifyTermAsVariable } from "../verify/term";
|
|
12
16
|
import { nodeQuery, typeNameFromTypeNode } from "../utilities/query";
|
|
13
17
|
import { ARGUMENT_RULE_NAME, META_ARGUMENT_RULE_NAME } from "../ruleNames";
|
|
14
18
|
|
|
15
19
|
const termNodeQuery = nodeQuery("/argument/term!"),
|
|
16
20
|
typeNodeQuery = nodeQuery("/argument/type!"),
|
|
21
|
+
leftTermNodeQuery = nodeQuery("/statement/argument[0]/term!"),
|
|
22
|
+
rightTermNodeQuery = nodeQuery("/statement/argument[1]/term!"),
|
|
17
23
|
metaTypeNodeQuery = nodeQuery("/metaArgument/metaType!"),
|
|
18
24
|
statementNodeQuery = nodeQuery("/metaArgument/statement!"),
|
|
19
25
|
typeAssertionNodeQuery = nodeQuery("/statement/typeAssertion!"),
|
|
@@ -35,7 +41,7 @@ export default function verifyStatement(statementNode, assertions, derived, cont
|
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
if (!statementVerified) {
|
|
38
|
-
const statementVerifiedAsEquality = verifyStatementAsEquality(statementNode, derived, context);
|
|
44
|
+
const statementVerifiedAsEquality = verifyStatementAsEquality(statementNode, assertions, derived, context);
|
|
39
45
|
|
|
40
46
|
statementVerified = statementVerifiedAsEquality; //
|
|
41
47
|
}
|
|
@@ -43,16 +49,6 @@ export default function verifyStatement(statementNode, assertions, derived, cont
|
|
|
43
49
|
return statementVerified;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
export function verifyStatementAgainstCombinator(statementNode, combinator, context) {
|
|
47
|
-
const combinatorStatementNode = combinator.getStatementNode(),
|
|
48
|
-
node = statementNode, ///
|
|
49
|
-
combinatorNode = combinatorStatementNode, ///
|
|
50
|
-
nodeVerified = verifyNode(node, combinatorNode, context),
|
|
51
|
-
statementVerifiedAgainstCombinator = nodeVerified; ///
|
|
52
|
-
|
|
53
|
-
return statementVerifiedAgainstCombinator;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
52
|
function verifyStatementAgainstCombinators(statementNode, context) {
|
|
57
53
|
let statementVerifiedAgainstCombinators = false;
|
|
58
54
|
|
|
@@ -78,6 +74,16 @@ function verifyStatementAgainstCombinators(statementNode, context) {
|
|
|
78
74
|
return statementVerifiedAgainstCombinators;
|
|
79
75
|
}
|
|
80
76
|
|
|
77
|
+
function verifyStatementAgainstCombinator(statementNode, combinator, context) {
|
|
78
|
+
const combinatorStatementNode = combinator.getStatementNode(),
|
|
79
|
+
node = statementNode, ///
|
|
80
|
+
combinatorNode = combinatorStatementNode, ///
|
|
81
|
+
nodeVerified = verifyNode(node, combinatorNode, context),
|
|
82
|
+
statementVerifiedAgainstCombinator = nodeVerified; ///
|
|
83
|
+
|
|
84
|
+
return statementVerifiedAgainstCombinator;
|
|
85
|
+
}
|
|
86
|
+
|
|
81
87
|
function verifyStatementAsTypeAssertion(statementNode, assertions, derived, context) {
|
|
82
88
|
let statementVerifiedAsTypeAssertion = false;
|
|
83
89
|
|
|
@@ -92,25 +98,73 @@ function verifyStatementAsTypeAssertion(statementNode, assertions, derived, cont
|
|
|
92
98
|
return statementVerifiedAsTypeAssertion;
|
|
93
99
|
}
|
|
94
100
|
|
|
95
|
-
function verifyStatementAsEquality(statementNode, derived, context) {
|
|
101
|
+
function verifyStatementAsEquality(statementNode, assertions, derived, context) {
|
|
96
102
|
let statementVerifiedAsEquality = false;
|
|
97
103
|
|
|
98
|
-
const
|
|
104
|
+
const statementString = context.nodeAsString(statementNode);
|
|
99
105
|
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
const combinator = equalityCombinator, ///
|
|
107
|
+
statementVerifiedAgainstCombinator = verifyStatementAgainstCombinator(statementNode, combinator, context);
|
|
102
108
|
|
|
109
|
+
if (statementVerifiedAgainstCombinator) {
|
|
103
110
|
if (derived) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
debugger
|
|
112
|
+
} else {
|
|
113
|
+
const types = [],
|
|
114
|
+
variables = [],
|
|
115
|
+
leftTermNode = leftTermNodeQuery(statementNode),
|
|
116
|
+
rightTermNode = rightTermNodeQuery(statementNode),
|
|
117
|
+
leftTermVerifiedAsVariable = verifyTermAsVariable(leftTermNode, variables, context);
|
|
118
|
+
|
|
119
|
+
if (leftTermVerifiedAsVariable) {
|
|
120
|
+
verifyTerm(rightTermNode, types, context);
|
|
121
|
+
|
|
122
|
+
const firstVariable = first(variables),
|
|
123
|
+
leftVariable = firstVariable, ///
|
|
124
|
+
firstType = first(types),
|
|
125
|
+
rightTermType = firstType, ///
|
|
126
|
+
leftVariableType = leftVariable.getType(),
|
|
127
|
+
leftVariableName = leftVariable.getName(),
|
|
128
|
+
leftVariableTypeEqualToOrSuperTypeOfRightTermType = leftVariableType.isEqualToOrSuperTypeOf(rightTermType);
|
|
129
|
+
|
|
130
|
+
if (!leftVariableTypeEqualToOrSuperTypeOfRightTermType) {
|
|
131
|
+
const rightTermString = nodeAsString(rightTermNode),
|
|
132
|
+
rightTermTypeName = rightTermType.getName(),
|
|
133
|
+
leftVariableTypeName = leftVariableType.getName();
|
|
134
|
+
|
|
135
|
+
context.error(`The left '${leftVariableName}' variable's '${leftVariableTypeName}' type is not equal to or a super-type of the right '${rightTermString}' term's '${rightTermTypeName}' type.`, statementNode);
|
|
136
|
+
} else {
|
|
137
|
+
const type = leftVariableType, ///
|
|
138
|
+
name = leftVariableName, ///
|
|
139
|
+
termNode = rightTermNode, ///
|
|
140
|
+
variable = Variable.fromTypeNameAndTermNode(type, name, termNode),
|
|
141
|
+
assertion = Assertion.fromVariable(variable);
|
|
142
|
+
|
|
143
|
+
assertions.push(assertion);
|
|
144
|
+
|
|
145
|
+
statementVerifiedAsEquality = true;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
const rightTermVerifiedAsVariable = verifyTermAsVariable(rightTermNode, variables, context);
|
|
149
|
+
|
|
150
|
+
if (rightTermVerifiedAsVariable) {
|
|
151
|
+
const firstVariable = first(variables),
|
|
152
|
+
rightVariable = firstVariable, ///
|
|
153
|
+
leftTermString = nodeAsString(leftTermNode),
|
|
154
|
+
rightVariableName = rightVariable.getName();
|
|
155
|
+
|
|
156
|
+
context.error(`The left '${leftTermString}' term cannot be equated with the right '${rightVariableName}' variable.`, statementNode);
|
|
157
|
+
} else {
|
|
158
|
+
statementVerifiedAsEquality = true;
|
|
159
|
+
}
|
|
110
160
|
}
|
|
111
161
|
}
|
|
112
162
|
}
|
|
113
163
|
|
|
164
|
+
if (statementVerifiedAsEquality) {
|
|
165
|
+
context.info(`Verified the '${statementString}' statement as an equality.`, statementNode);
|
|
166
|
+
}
|
|
167
|
+
|
|
114
168
|
return statementVerifiedAsEquality;
|
|
115
169
|
}
|
|
116
170
|
|
package/lib/assertion/type.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return TypeAssertion;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function _classCallCheck(instance, Constructor) {
|
|
12
|
-
if (!(instance instanceof Constructor)) {
|
|
13
|
-
throw new TypeError("Cannot call a class as a function");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function _defineProperties(target, props) {
|
|
17
|
-
for(var i = 0; i < props.length; i++){
|
|
18
|
-
var descriptor = props[i];
|
|
19
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
20
|
-
descriptor.configurable = true;
|
|
21
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
22
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
26
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
27
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
28
|
-
return Constructor;
|
|
29
|
-
}
|
|
30
|
-
var TypeAssertion = /*#__PURE__*/ function() {
|
|
31
|
-
function TypeAssertion(variable) {
|
|
32
|
-
_classCallCheck(this, TypeAssertion);
|
|
33
|
-
this.variable = variable;
|
|
34
|
-
}
|
|
35
|
-
_createClass(TypeAssertion, [
|
|
36
|
-
{
|
|
37
|
-
key: "getVariable",
|
|
38
|
-
value: function getVariable() {
|
|
39
|
-
return this.variable;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
key: "assert",
|
|
44
|
-
value: function assert(proofContext) {
|
|
45
|
-
proofContext.addVariable(this.variable);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
], [
|
|
49
|
-
{
|
|
50
|
-
key: "fromVariable",
|
|
51
|
-
value: function fromVariable(variable) {
|
|
52
|
-
var typeAssertion = new TypeAssertion(variable);
|
|
53
|
-
return typeAssertion;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
]);
|
|
57
|
-
return TypeAssertion;
|
|
58
|
-
}();
|
|
59
|
-
|
|
60
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hc3NlcnRpb24vdHlwZS5qcyIsIjw8anN4LWNvbmZpZy1wcmFnbWEuanM+PiJdLCJzb3VyY2VzQ29udGVudCI6WyJcInVzZSBzdHJpY3RcIjtcblxuZXhwb3J0IGRlZmF1bHQgY2xhc3MgVHlwZUFzc2VydGlvbiB7XG4gIGNvbnN0cnVjdG9yKHZhcmlhYmxlKSB7XG4gICAgdGhpcy52YXJpYWJsZSA9IHZhcmlhYmxlO1xuICB9XG5cbiAgZ2V0VmFyaWFibGUoKSB7XG4gICAgcmV0dXJuIHRoaXMudmFyaWFibGU7XG4gIH1cblxuICBhc3NlcnQocHJvb2ZDb250ZXh0KSB7XG4gICAgcHJvb2ZDb250ZXh0LmFkZFZhcmlhYmxlKHRoaXMudmFyaWFibGUpO1xuICB9XG5cbiAgc3RhdGljIGZyb21WYXJpYWJsZSh2YXJpYWJsZSkge1xuICAgIGNvbnN0IHR5cGVBc3NlcnRpb24gPSBuZXcgVHlwZUFzc2VydGlvbih2YXJpYWJsZSk7XG5cbiAgICByZXR1cm4gdHlwZUFzc2VydGlvbjtcbiAgfVxufVxuIiwiUmVhY3QuY3JlYXRlRWxlbWVudCJdLCJuYW1lcyI6WyJUeXBlQXNzZXJ0aW9uIiwidmFyaWFibGUiLCJnZXRWYXJpYWJsZSIsImFzc2VydCIsInByb29mQ29udGV4dCIsImFkZFZhcmlhYmxlIiwiZnJvbVZhcmlhYmxlIiwidHlwZUFzc2VydGlvbiJdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7Ozs7ZUFFcUJBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQU4sSUFBQSxBQUFNQSw4QkFBTjthQUFNQSxjQUNQQyxRQUFROzhCQURERDtRQUVqQixJQUFJLENBQUNDLFFBQVEsR0FBR0E7O2lCQUZDRDs7WUFLbkJFLEtBQUFBO21CQUFBQSxTQUFBQSxjQUFjO2dCQUNaLE9BQU8sSUFBSSxDQUFDRCxRQUFRO1lBQ3RCOzs7WUFFQUUsS0FBQUE7bUJBQUFBLFNBQUFBLE9BQU9DLFlBQVksRUFBRTtnQkFDbkJBLGFBQWFDLFdBQVcsQ0FBQyxJQUFJLENBQUNKLFFBQVE7WUFDeEM7Ozs7WUFFT0ssS0FBQUE7bUJBQVAsU0FBT0EsYUFBYUwsUUFBUSxFQUFFO2dCQUM1QixJQUFNTSxnQkFBZ0IsSUFkTFAsY0FjdUJDO2dCQUV4QyxPQUFPTTtZQUNUOzs7V0FqQm1CUCJ9
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return _default;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
var _node = require("../../utilities/node");
|
|
12
|
-
var equalityStatementString = "n=m";
|
|
13
|
-
var equalityStatementNode = (0, _node.statementNodeFromStatementString)(equalityStatementString);
|
|
14
|
-
var _default = equalityStatementNode;
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9ub2RlL3N0YXRlbWVudC9lcXVhbGl0eS5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJcInVzZSBzdHJpY3RcIjtcblxuaW1wb3J0IHsgc3RhdGVtZW50Tm9kZUZyb21TdGF0ZW1lbnRTdHJpbmcgfSBmcm9tIFwiLi4vLi4vdXRpbGl0aWVzL25vZGVcIjtcblxuY29uc3QgZXF1YWxpdHlTdGF0ZW1lbnRTdHJpbmcgPSBcIm49bVwiO1xuXG5jb25zdCBlcXVhbGl0eVN0YXRlbWVudE5vZGUgPSBzdGF0ZW1lbnROb2RlRnJvbVN0YXRlbWVudFN0cmluZyhlcXVhbGl0eVN0YXRlbWVudFN0cmluZyk7XG5cbmV4cG9ydCBkZWZhdWx0IGVxdWFsaXR5U3RhdGVtZW50Tm9kZTtcblxuIl0sIm5hbWVzIjpbImVxdWFsaXR5U3RhdGVtZW50U3RyaW5nIiwiZXF1YWxpdHlTdGF0ZW1lbnROb2RlIiwic3RhdGVtZW50Tm9kZUZyb21TdGF0ZW1lbnRTdHJpbmciXSwibWFwcGluZ3MiOiJBQUFBOzs7OytCQVFBOzs7ZUFBQTs7O29CQU5pRDtBQUVqRCxJQUFNQSwwQkFBMEI7QUFFaEMsSUFBTUMsd0JBQXdCQyxJQUFBQSxzQ0FBZ0MsRUFBQ0Y7SUFFL0QsV0FBZUMifQ==
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { statementNodeFromStatementString } from "../../utilities/node";
|
|
4
|
-
|
|
5
|
-
const equalityStatementString = "n=m";
|
|
6
|
-
|
|
7
|
-
const equalityStatementNode = statementNodeFromStatementString(equalityStatementString);
|
|
8
|
-
|
|
9
|
-
export default equalityStatementNode;
|
|
10
|
-
|