occam-verify-cli 0.0.677 → 0.0.679
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/bin/action/verify.js +14 -4
- package/lib/conclusion.js +10 -5
- package/lib/consequent.js +8 -3
- package/lib/context/file.js +74 -4
- package/lib/context/release.js +7 -2
- package/lib/equality.js +16 -16
- package/lib/premise.js +12 -7
- package/lib/supposition.js +9 -4
- package/lib/type.js +3 -8
- package/lib/utilities/string.js +26 -13
- package/lib/verifier/node/metastatement.js +173 -0
- package/lib/verifier/node/statementAsCombinator.js +186 -0
- package/lib/verifier/node/termAsConstructor.js +224 -0
- package/lib/verifier/node.js +158 -0
- package/lib/verifier/{metastatementForMetavariable → nodes/metastatementForMetavariable}/conclusion.js +13 -12
- package/lib/verifier/{metastatementForMetavariable → nodes/metastatementForMetavariable}/premise.js +13 -12
- package/lib/verifier/nodes/metastatementForMetavariable.js +198 -0
- package/lib/verifier/nodes/statement.js +199 -0
- package/lib/verifier/{statementForMetavariable → nodes/statementForMetavariable}/conclusion.js +13 -12
- package/lib/verifier/{statementForMetavariable → nodes/statementForMetavariable}/premise.js +13 -12
- package/lib/verifier/nodes/statementForMetavariable.js +203 -0
- package/lib/verifier/nodes/term.js +212 -0
- package/lib/verifier/{termForVariable/supposition.js → nodes/termForVariable/consequent.js} +13 -12
- package/lib/verifier/{termForVariable/consequent.js → nodes/termForVariable/supposition.js} +13 -12
- package/lib/verifier/nodes/termForVariable.js +209 -0
- package/lib/verifier/nodes.js +175 -0
- package/lib/verify/assertion/type.js +20 -10
- package/lib/verify/axiom.js +3 -3
- package/lib/verify/conclusion.js +3 -3
- package/lib/verify/conjecture.js +3 -3
- package/lib/verify/consequent.js +3 -3
- package/lib/verify/declaration/combinator.js +7 -2
- package/lib/verify/declaration/constructor.js +8 -2
- package/lib/verify/declaration/metavariable.js +7 -2
- package/lib/verify/declaration/type.js +7 -2
- package/lib/verify/declaration/variable.js +8 -2
- package/lib/verify/file.js +3 -3
- package/lib/verify/label.js +9 -4
- package/lib/verify/lemma.js +3 -3
- package/lib/verify/metastatement/qualified.js +5 -6
- package/lib/verify/metastatement/unqualified.js +9 -7
- package/lib/verify/metastatement.js +34 -157
- package/lib/verify/metavariable.js +6 -4
- package/lib/verify/premise.js +3 -3
- package/lib/verify/release.js +3 -3
- package/lib/verify/rule.js +3 -3
- package/lib/verify/statement/qualified.js +5 -6
- package/lib/verify/statement/unqualified.js +9 -7
- package/lib/verify/statement.js +112 -317
- package/lib/verify/statementAsCombinator.js +8 -82
- package/lib/verify/supposition.js +3 -3
- package/lib/verify/term.js +69 -213
- package/lib/verify/termAsConstructor.js +15 -89
- package/lib/verify/theorem.js +3 -3
- package/lib/verify/type.js +7 -5
- package/lib/verify/typeInference.js +5 -5
- package/lib/verify/variable.js +7 -5
- package/package.json +5 -5
- package/src/conclusion.js +5 -4
- package/src/consequent.js +3 -2
- package/src/context/file.js +11 -4
- package/src/context/release.js +9 -2
- package/src/equality.js +10 -10
- package/src/premise.js +7 -6
- package/src/supposition.js +4 -3
- package/src/type.js +3 -8
- package/src/utilities/string.js +34 -23
- package/src/verifier/node/metastatement.js +57 -0
- package/src/verifier/node/statementAsCombinator.js +80 -0
- package/src/verifier/node/termAsConstructor.js +124 -0
- package/src/verifier/node.js +85 -0
- package/src/verifier/nodes/metastatementForMetavariable/conclusion.js +11 -0
- package/src/verifier/nodes/metastatementForMetavariable/premise.js +11 -0
- package/src/verifier/{metastatementForMetavariable.js → nodes/metastatementForMetavariable.js} +6 -6
- package/src/verifier/nodes/statement.js +98 -0
- package/src/verifier/nodes/statementForMetavariable/conclusion.js +11 -0
- package/src/verifier/nodes/statementForMetavariable/premise.js +11 -0
- package/src/verifier/{statementForMetavariable.js → nodes/statementForMetavariable.js} +10 -10
- package/src/verifier/nodes/term.js +111 -0
- package/src/verifier/nodes/termForVariable/consequent.js +11 -0
- package/src/verifier/nodes/termForVariable/supposition.js +11 -0
- package/src/verifier/{termForVariable.js → nodes/termForVariable.js} +9 -9
- package/src/verifier/nodes.js +111 -0
- package/src/verify/assertion/type.js +25 -9
- package/src/verify/axiom.js +2 -2
- package/src/verify/conclusion.js +2 -2
- package/src/verify/conjecture.js +2 -2
- package/src/verify/consequent.js +2 -2
- package/src/verify/declaration/combinator.js +9 -1
- package/src/verify/declaration/constructor.js +15 -1
- package/src/verify/declaration/metavariable.js +9 -1
- package/src/verify/declaration/type.js +14 -1
- package/src/verify/declaration/variable.js +15 -1
- package/src/verify/file.js +2 -2
- package/src/verify/label.js +10 -2
- package/src/verify/lemma.js +4 -4
- package/src/verify/metastatement/qualified.js +4 -6
- package/src/verify/metastatement/unqualified.js +9 -7
- package/src/verify/metastatement.js +32 -57
- package/src/verify/metavariable.js +6 -3
- package/src/verify/premise.js +2 -2
- package/src/verify/release.js +2 -2
- package/src/verify/rule.js +2 -2
- package/src/verify/statement/qualified.js +4 -6
- package/src/verify/statement/unqualified.js +9 -7
- package/src/verify/statement.js +159 -283
- package/src/verify/statementAsCombinator.js +9 -129
- package/src/verify/supposition.js +2 -2
- package/src/verify/term.js +94 -159
- package/src/verify/termAsConstructor.js +20 -135
- package/src/verify/theorem.js +2 -2
- package/src/verify/type.js +7 -4
- package/src/verify/typeInference.js +4 -4
- package/src/verify/variable.js +7 -4
- package/lib/verifier/metastatementForMetavariable.js +0 -198
- package/lib/verifier/statementForMetavariable.js +0 -203
- package/lib/verifier/termForVariable.js +0 -209
- package/lib/verifier.js +0 -138
- package/src/verifier/metastatementForMetavariable/conclusion.js +0 -9
- package/src/verifier/metastatementForMetavariable/premise.js +0 -9
- package/src/verifier/statementForMetavariable/conclusion.js +0 -9
- package/src/verifier/statementForMetavariable/premise.js +0 -9
- package/src/verifier/termForVariable/consequent.js +0 -9
- package/src/verifier/termForVariable/supposition.js +0 -9
- package/src/verifier.js +0 -74
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Combinator from "../combinator";
|
|
4
|
-
import
|
|
5
|
-
import verifyStatement from "../verify/statement";
|
|
6
|
-
|
|
7
|
-
import { typeNameFromTypeNode } from "../utilities/query";
|
|
8
|
-
import { TYPE_RULE_NAME, TERM_RULE_NAME, STATEMENT_RULE_NAME } from "../ruleNames";
|
|
4
|
+
import statementAsCombinatorNodeVerifier from "../verifier/node/statementAsCombinator";
|
|
9
5
|
|
|
10
6
|
export default function verifyStatementAsCombinator(statementNode, fileContext) {
|
|
11
7
|
let statementVerifiedAsCombinator = false;
|
|
12
8
|
|
|
13
9
|
const statementString = fileContext.nodeAsString(statementNode);
|
|
14
10
|
|
|
15
|
-
fileContext.
|
|
11
|
+
fileContext.trace(`Verifying the '${statementString}' statement as a combinator....`, statementNode);
|
|
16
12
|
|
|
17
|
-
const nonTerminalNode = statementNode,
|
|
13
|
+
const nonTerminalNode = statementNode, ///
|
|
18
14
|
childNodes = nonTerminalNode.getChildNodes(),
|
|
19
|
-
childNodesVerified = verifyChildNodes(childNodes, fileContext)
|
|
15
|
+
childNodesVerified = statementAsCombinatorNodeVerifier.verifyChildNodes(childNodes, fileContext, () => {
|
|
16
|
+
const verifiedAhead = true;
|
|
17
|
+
|
|
18
|
+
return verifiedAhead;
|
|
19
|
+
});
|
|
20
20
|
|
|
21
21
|
if (childNodesVerified) {
|
|
22
22
|
const tokens = fileContext.getTokens(),
|
|
@@ -28,128 +28,8 @@ export default function verifyStatementAsCombinator(statementNode, fileContext)
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (statementVerifiedAsCombinator) {
|
|
31
|
-
fileContext.
|
|
31
|
+
fileContext.debug(`...verified the '${statementString}' statement as a combinator.`, statementNode);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
return statementVerifiedAsCombinator;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
function verifyNode(node, fileContext) {
|
|
38
|
-
let nodeVerified;
|
|
39
|
-
|
|
40
|
-
const nodeTerminalNode = node.isTerminalNode();
|
|
41
|
-
|
|
42
|
-
if (nodeTerminalNode) {
|
|
43
|
-
const terminalNode = node, ///
|
|
44
|
-
terminalNodeVerified = verifyTerminalNode(terminalNode, fileContext);
|
|
45
|
-
|
|
46
|
-
nodeVerified = terminalNodeVerified; ///
|
|
47
|
-
} else {
|
|
48
|
-
const nonTerminalNode = node, ///
|
|
49
|
-
nonTerminalNodeVerified = verifyNonTerminalNode(nonTerminalNode, fileContext);
|
|
50
|
-
|
|
51
|
-
nodeVerified = nonTerminalNodeVerified; ///
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return nodeVerified;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function verifyChildNodes(childNodes, fileContext) {
|
|
58
|
-
const childNodesVerified = childNodes.every((childNode) => {
|
|
59
|
-
const node = childNode, ///
|
|
60
|
-
nodeVerified = verifyNode(node, fileContext);
|
|
61
|
-
|
|
62
|
-
if (nodeVerified) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return childNodesVerified;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function verifyTerminalNode(terminalNode, fileContext) {
|
|
71
|
-
const terminalNodeVerified = true;
|
|
72
|
-
|
|
73
|
-
return terminalNodeVerified;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function verifyNonTerminalNode(nonTerminalNode, fileContext) {
|
|
77
|
-
let nonTerminalNodeVerified;
|
|
78
|
-
|
|
79
|
-
const ruleName = nonTerminalNode.getRuleName();
|
|
80
|
-
|
|
81
|
-
switch (ruleName) {
|
|
82
|
-
case TYPE_RULE_NAME: {
|
|
83
|
-
const typeNode = nonTerminalNode, ///
|
|
84
|
-
typeNodeVerified = verifyTypeNode(typeNode, fileContext);
|
|
85
|
-
|
|
86
|
-
nonTerminalNodeVerified = typeNodeVerified; ///
|
|
87
|
-
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
case TERM_RULE_NAME: {
|
|
92
|
-
const termNode = nonTerminalNode, ///
|
|
93
|
-
termNodeVerified = verifyTermNode(termNode, fileContext);
|
|
94
|
-
|
|
95
|
-
nonTerminalNodeVerified = termNodeVerified; ///
|
|
96
|
-
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
case STATEMENT_RULE_NAME: {
|
|
101
|
-
const statmentNode = nonTerminalNode, ///
|
|
102
|
-
statmentNodeVerified = verifyStatementNode(statmentNode, fileContext);
|
|
103
|
-
|
|
104
|
-
nonTerminalNodeVerified = statmentNodeVerified; ///
|
|
105
|
-
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
default: {
|
|
110
|
-
const childNodes = nonTerminalNode.getChildNodes(),
|
|
111
|
-
childNodesVerified = verifyChildNodes(childNodes, fileContext);
|
|
112
|
-
|
|
113
|
-
nonTerminalNodeVerified = childNodesVerified; ///
|
|
114
|
-
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return nonTerminalNodeVerified;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function verifyTypeNode(typeNode, fileContext) {
|
|
123
|
-
let typeNodeVerified = false;
|
|
124
|
-
|
|
125
|
-
const typeName = typeNameFromTypeNode(typeNode),
|
|
126
|
-
typePresent = fileContext.isTypePresentByTypeName(typeName);
|
|
127
|
-
|
|
128
|
-
if (!typePresent) {
|
|
129
|
-
fileContext.error(`The type '${typeName}' not present.`, typeNode);
|
|
130
|
-
} else {
|
|
131
|
-
typeNodeVerified = true;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return typeNodeVerified;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function verifyTermNode(termNode, fileContext) {
|
|
138
|
-
const types = [],
|
|
139
|
-
context = fileContext, ///
|
|
140
|
-
termVerified = verifyTerm(termNode, types, context),
|
|
141
|
-
termNodeVerified = termVerified; ///
|
|
142
|
-
|
|
143
|
-
return termNodeVerified;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function verifyStatementNode(statementNode, fileContext) {
|
|
147
|
-
const context = fileContext, ///
|
|
148
|
-
derived = false,
|
|
149
|
-
assignments = [],
|
|
150
|
-
statementVerified = verifyStatement(statementNode, assignments, derived, context),
|
|
151
|
-
statementNodeVerified = statementVerified; ///
|
|
152
|
-
|
|
153
|
-
return statementNodeVerified;
|
|
154
|
-
}
|
|
155
|
-
|
|
@@ -14,7 +14,7 @@ export default function verifySupposition(suppositionNode, suppositions, proofCo
|
|
|
14
14
|
|
|
15
15
|
const suppositionString = proofContext.nodeAsString(suppositionNode);
|
|
16
16
|
|
|
17
|
-
proofContext.
|
|
17
|
+
proofContext.trace(`Verifying the '${suppositionString}' supposition...`, suppositionNode);
|
|
18
18
|
|
|
19
19
|
const derived = false,
|
|
20
20
|
assignments = [],
|
|
@@ -38,7 +38,7 @@ export default function verifySupposition(suppositionNode, suppositions, proofCo
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (suppositionVerified) {
|
|
41
|
-
proofContext.
|
|
41
|
+
proofContext.debug(`...verified the '${suppositionString}' supposition.`, suppositionNode);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
return suppositionVerified;
|
package/src/verify/term.js
CHANGED
|
@@ -1,222 +1,157 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import termNodesVerifier from "../verifier/nodes/term";
|
|
4
4
|
|
|
5
5
|
import { first } from "../utilities/array";
|
|
6
|
-
import {
|
|
7
|
-
import { OBJECT_TYPE_NAME } from "../typeNames";
|
|
8
|
-
import { ARGUMENT_RULE_NAME } from "../ruleNames";
|
|
9
|
-
import { nodeQuery, typeNameFromTypeNode, variableNameFromVariableNode } from "../utilities/query";
|
|
6
|
+
import { nodeQuery, variableNameFromVariableNode } from "../utilities/query";
|
|
10
7
|
|
|
11
|
-
const
|
|
12
|
-
typeNodeQuery = nodeQuery("/argument/type!"),
|
|
13
|
-
variableNodeQuery = nodeQuery("/term/variable!");
|
|
8
|
+
const variableNodeQuery = nodeQuery("/term/variable!");
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let terminalNodeVerified = false;
|
|
10
|
+
function verifyTerm(termNode, types, context, verifyAhead) {
|
|
11
|
+
let termVerified;
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
const termString = context.nodeAsString(termNode);
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
terminalNodeVerified = true;
|
|
23
|
-
}
|
|
15
|
+
context.trace(`Verifying the '${termString}' term...`, termNode);
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const verifyTermFunctions = [
|
|
18
|
+
verifyTermAsStandaloneVariable,
|
|
19
|
+
verifyTermAgainstConstructors
|
|
20
|
+
];
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
termVerified = verifyTermFunctions.some((verifyTermFunction) => {
|
|
23
|
+
const termVerified = verifyTermFunction(termNode, types, context, verifyAhead);
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
if (termVerified) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
constructorArgumentNode = constructorNonTerminalNode, ///
|
|
39
|
-
argumentNodeVerified = this.verifyArgumentNode(argumentNode, constructorArgumentNode, context);
|
|
30
|
+
if (termVerified) {
|
|
31
|
+
const firstType = first(types),
|
|
32
|
+
type = firstType, ///
|
|
33
|
+
typeName = type.getName();
|
|
40
34
|
|
|
41
|
-
|
|
35
|
+
context.debug(`...verified the '${termString}' term, which has been given the '${typeName}' type.`, termNode);
|
|
36
|
+
}
|
|
42
37
|
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
return termVerified;
|
|
39
|
+
}
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
nodes = childNodes, ///
|
|
50
|
-
constructorNodes = constructorChildNodes, ///
|
|
51
|
-
nodesVerified = this.verifyNodes(nodes, constructorNodes, context);
|
|
41
|
+
Object.assign(termNodesVerifier, {
|
|
42
|
+
verifyTerm
|
|
43
|
+
});
|
|
52
44
|
|
|
53
|
-
|
|
45
|
+
export default verifyTerm;
|
|
54
46
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}
|
|
47
|
+
export function verifyTermAgainstConstructors(termNode, types, context, verifyAhead) {
|
|
48
|
+
let termVerifiedAgainstConstructors;
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
}
|
|
50
|
+
const constructors = context.getConstructors();
|
|
62
51
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (typeNode !== null) {
|
|
69
|
-
const argumentString = context.nodeAsString(argumentNode);
|
|
70
|
-
|
|
71
|
-
context.error(`The '${argumentString}' argument should be a term, not a type`, argumentNode);
|
|
72
|
-
} else {
|
|
73
|
-
const termNode = termNodeQuery(argumentNode),
|
|
74
|
-
constructorTermNode = termNodeQuery(constructorArgumentNode),
|
|
75
|
-
constructorTypeNode = typeNodeQuery(constructorArgumentNode);
|
|
76
|
-
|
|
77
|
-
if (false) {
|
|
78
|
-
///
|
|
79
|
-
} else if (constructorTermNode !== null) {
|
|
80
|
-
const node = termNode, ///
|
|
81
|
-
constructorNode = constructorTermNode, ///
|
|
82
|
-
nodeVerified = this.verifyNode(node, constructorNode, context);
|
|
83
|
-
|
|
84
|
-
argumentNodeVerified = nodeVerified; ///
|
|
85
|
-
} else if (constructorTypeNode !== null) {
|
|
86
|
-
const types = [],
|
|
87
|
-
termVerified = verifyTerm(termNode, types, context);
|
|
88
|
-
|
|
89
|
-
if (termVerified) {
|
|
90
|
-
const constructorTypeName = typeNameFromTypeNode(constructorTypeNode),
|
|
91
|
-
firstType = first(types),
|
|
92
|
-
termType = firstType, ///
|
|
93
|
-
termTypeName = termType.getName(),
|
|
94
|
-
constructorType = (constructorTypeName === OBJECT_TYPE_NAME) ?
|
|
95
|
-
objectType :
|
|
96
|
-
context.findTypeByTypeName(constructorTypeName),
|
|
97
|
-
termTypeEqualToOrSubTypeOfType = termType.isEqualToOrSubTypeOf(constructorType);
|
|
98
|
-
|
|
99
|
-
if (termTypeEqualToOrSubTypeOfType) {
|
|
100
|
-
const termString = context.nodeAsString(termNode);
|
|
101
|
-
|
|
102
|
-
context.trace(`The '${termTypeName}' type of the '${termString}' term is equal to or a sub-type of the '${constructorTypeName}' type in the constructor.`, argumentNode);
|
|
103
|
-
|
|
104
|
-
argumentNodeVerified = true;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
52
|
+
termVerifiedAgainstConstructors = constructors.some((constructor) => {
|
|
53
|
+
const termVerifiedAgainstConstructor = verifyTermAgainstConstructor(termNode, types, constructor, context, verifyAhead);
|
|
54
|
+
|
|
55
|
+
if (termVerifiedAgainstConstructor) {
|
|
56
|
+
return true;
|
|
108
57
|
}
|
|
58
|
+
});
|
|
109
59
|
|
|
110
|
-
|
|
111
|
-
}
|
|
60
|
+
return termVerifiedAgainstConstructors;
|
|
112
61
|
}
|
|
113
62
|
|
|
114
|
-
export
|
|
115
|
-
|
|
116
|
-
export default function verifyTerm(termNode, types, context) {
|
|
117
|
-
let termVerified = false;
|
|
63
|
+
export function verifyTermAsVariable(termNode, variables, context, verifyAhead) {
|
|
64
|
+
let termVerifiedAsVariable = false;
|
|
118
65
|
|
|
119
66
|
const termString = context.nodeAsString(termNode);
|
|
120
67
|
|
|
121
|
-
context.
|
|
68
|
+
context.trace(`Verifying the '${termString}' term as a variable...`, termNode);
|
|
122
69
|
|
|
123
|
-
|
|
124
|
-
const variables = [],
|
|
125
|
-
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context);
|
|
70
|
+
const variableNode = variableNodeQuery(termNode);
|
|
126
71
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
type = variable.getType();
|
|
72
|
+
if (variableNode !== null) {
|
|
73
|
+
const variableName = variableNameFromVariableNode(variableNode),
|
|
74
|
+
variablePresent = context.isVariablePresentByVariableName(variableName);
|
|
131
75
|
|
|
132
|
-
|
|
76
|
+
if (variablePresent) {
|
|
77
|
+
let verifiedAhead;
|
|
133
78
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
79
|
+
const variable = context.findVariableByVariableName(variableName);
|
|
80
|
+
|
|
81
|
+
variables.push(variable);
|
|
137
82
|
|
|
138
|
-
|
|
139
|
-
const termVerifiedAgainstConstructors = verifyTermAgainstConstructors(termNode, types, context);
|
|
83
|
+
verifiedAhead = verifyAhead();
|
|
140
84
|
|
|
141
|
-
|
|
142
|
-
termVerified = true;
|
|
85
|
+
termVerifiedAsVariable = verifiedAhead; ///
|
|
143
86
|
}
|
|
144
87
|
}
|
|
145
88
|
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
type = firstType, ///
|
|
149
|
-
typeName = type.getName();
|
|
150
|
-
|
|
151
|
-
context.debug(`Verified the '${termString}' term, which has type '${typeName}'.`, termNode);
|
|
89
|
+
if (termVerifiedAsVariable) {
|
|
90
|
+
context.debug(`...verified the '${termString}' term as a variable.`, termNode);
|
|
152
91
|
}
|
|
153
92
|
|
|
154
|
-
return
|
|
93
|
+
return termVerifiedAsVariable;
|
|
155
94
|
}
|
|
156
95
|
|
|
157
|
-
|
|
158
|
-
let
|
|
159
|
-
|
|
160
|
-
const termString = context.nodeAsString(termNode);
|
|
96
|
+
function verifyTermAgainstConstructor(termNode, types, constructor, context, verifyAhead) {
|
|
97
|
+
let termVerifiedAgainstConstructor;
|
|
161
98
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const constructors = context.getConstructors(),
|
|
165
|
-
constructor = constructors.find((constructor) => {
|
|
166
|
-
const termVerifiedAgainstConstructor = verifyTermAgainstConstructor(termNode, constructor, context);
|
|
99
|
+
const termString = context.nodeAsString(termNode),
|
|
100
|
+
constructorString = constructor.getString();
|
|
167
101
|
|
|
168
|
-
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
}) || null;
|
|
102
|
+
context.trace(`Verifying the '${termString}' term against the '${constructorString}' constructor...`, termNode);
|
|
172
103
|
|
|
173
|
-
|
|
174
|
-
|
|
104
|
+
const constructorTermNode = constructor.getTermNode(),
|
|
105
|
+
nonTerminalNNdeA = termNode, ///
|
|
106
|
+
nonTerminalNodeB = constructorTermNode, ///
|
|
107
|
+
nodeVerified = termNodesVerifier.verifyNonTerminalNode(nonTerminalNNdeA, nonTerminalNodeB, context, () => {
|
|
108
|
+
let verifiedAhead;
|
|
175
109
|
|
|
176
|
-
|
|
110
|
+
const type = constructor.getType();
|
|
177
111
|
|
|
178
|
-
|
|
179
|
-
}
|
|
112
|
+
types.push(type);
|
|
180
113
|
|
|
181
|
-
|
|
182
|
-
}
|
|
114
|
+
verifiedAhead = verifyAhead();
|
|
183
115
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
constructorString = constructor.getString();
|
|
116
|
+
return verifiedAhead;
|
|
117
|
+
});
|
|
187
118
|
|
|
188
|
-
|
|
119
|
+
termVerifiedAgainstConstructor = nodeVerified; ///
|
|
189
120
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
nodeVerified = termVerifier.verifyNonTerminalNode(nonTerminalNNdeA, nonTerminalNodeB, context),
|
|
194
|
-
termVerifiedAgainstConstructor = nodeVerified; ///
|
|
121
|
+
if (termVerifiedAgainstConstructor) {
|
|
122
|
+
context.debug(`...verified the '${termString}' term against the '${constructorString}' constructor.`, termNode);
|
|
123
|
+
}
|
|
195
124
|
|
|
196
125
|
return termVerifiedAgainstConstructor;
|
|
197
126
|
}
|
|
198
127
|
|
|
199
|
-
|
|
200
|
-
let
|
|
128
|
+
function verifyTermAsStandaloneVariable(termNode, types, context, verifyAhead) {
|
|
129
|
+
let termVerifiedAsStandaloneVariable;
|
|
201
130
|
|
|
202
131
|
const termString = context.nodeAsString(termNode);
|
|
203
132
|
|
|
204
|
-
context.trace(`Verifying the '${termString}' term as a variable...`, termNode);
|
|
133
|
+
context.trace(`Verifying the '${termString}' term as a standalone variable...`, termNode);
|
|
205
134
|
|
|
206
|
-
const
|
|
135
|
+
const variables = [],
|
|
136
|
+
termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context, () => {
|
|
137
|
+
let verifiedAhead;
|
|
207
138
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
139
|
+
const firstVariable = first(variables),
|
|
140
|
+
variable = firstVariable, ///
|
|
141
|
+
type = variable.getType();
|
|
211
142
|
|
|
212
|
-
|
|
213
|
-
const variable = context.findVariableByVariableName(variableName);
|
|
143
|
+
types.push(type);
|
|
214
144
|
|
|
215
|
-
|
|
145
|
+
verifiedAhead = verifyAhead();
|
|
216
146
|
|
|
217
|
-
|
|
218
|
-
|
|
147
|
+
return verifiedAhead;
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
termVerifiedAsStandaloneVariable = termVerifiedAsVariable; ///
|
|
151
|
+
|
|
152
|
+
if (termVerifiedAsStandaloneVariable) {
|
|
153
|
+
context.debug(`...verified the '${termString}' term as a standalone variable.`, termNode);
|
|
219
154
|
}
|
|
220
155
|
|
|
221
|
-
return
|
|
156
|
+
return termVerifiedAsStandaloneVariable;
|
|
222
157
|
}
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import verifyTerm from "../verify/term";
|
|
4
3
|
import Constructor from "../constructor";
|
|
4
|
+
import termAsConstructorNodeVerifier from "../verifier/node/termAsConstructor";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import { nodeQuery, typeNameFromTypeNode } from "../utilities/query";
|
|
8
|
-
import { TERM_RULE_NAME, ARGUMENT_RULE_NAME } from "../ruleNames";
|
|
9
|
-
|
|
10
|
-
const typeNodeQuery = nodeQuery("/argument/type"),
|
|
11
|
-
termNodeQuery = nodeQuery("/argument/term");
|
|
6
|
+
import { typeNameFromTypeNode } from "../utilities/query";
|
|
12
7
|
|
|
13
8
|
export default function verifyTermAsConstructor(termNode, typeNode, fileContext) {
|
|
14
9
|
let termVerifiedAsConstructor = false;
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
const termString = fileContext.nodeAsString(termNode);
|
|
12
|
+
|
|
13
|
+
fileContext.debug(`Verifying the '${termString}' term as a constructor...`, termNode);
|
|
17
14
|
|
|
18
|
-
const nonTerminalNode = termNode,
|
|
19
|
-
|
|
15
|
+
const nonTerminalNode = termNode, ///
|
|
16
|
+
childNodes = nonTerminalNode.getChildNodes(),
|
|
17
|
+
childNodesVerified = termAsConstructorNodeVerifier.verifyChildNodes(childNodes, fileContext, () => {
|
|
18
|
+
const verifiedAhead = true;
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
return verifiedAhead;
|
|
21
|
+
});
|
|
23
22
|
|
|
24
23
|
if (childNodesVerified) {
|
|
24
|
+
let type = null;
|
|
25
|
+
|
|
25
26
|
if (typeNode === null) {
|
|
26
27
|
termVerifiedAsConstructor = true;
|
|
27
28
|
} else {
|
|
@@ -32,137 +33,21 @@ export default function verifyTermAsConstructor(termNode, typeNode, fileContext)
|
|
|
32
33
|
if (type !== null) {
|
|
33
34
|
termVerifiedAsConstructor = true;
|
|
34
35
|
} else {
|
|
35
|
-
fileContext.
|
|
36
|
+
fileContext.info(`The '${termString}' constructor's '${typeName}' type is not present.`, termNode);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
if (termVerifiedAsConstructor) {
|
|
41
|
+
const tokens = fileContext.getTokens(),
|
|
42
|
+
constructor = Constructor.fromTermNodeTypeAndTokens(termNode, type, tokens);
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
fileContext.addConstructor(constructor);
|
|
45
|
+
}
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
if (termVerifiedAsConstructor) {
|
|
48
|
-
fileContext.
|
|
49
|
+
fileContext.debug(`...verified the '${termString}' term as a constructor.`, termNode);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
return termVerifiedAsConstructor;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
function verifyNode(node, fileContext) {
|
|
55
|
-
let nodeVerified;
|
|
56
|
-
|
|
57
|
-
const nodeTerminalNode = node.isTerminalNode();
|
|
58
|
-
|
|
59
|
-
if (nodeTerminalNode) {
|
|
60
|
-
const terminalNode = node, ///
|
|
61
|
-
terminalNodeVerified = verifyTerminalNode(terminalNode, fileContext);
|
|
62
|
-
|
|
63
|
-
nodeVerified = terminalNodeVerified; ///
|
|
64
|
-
} else {
|
|
65
|
-
const nonTerminalNode = node, ///
|
|
66
|
-
nonTerminalNodeVerified = verifyNonTerminalNode(nonTerminalNode, fileContext);
|
|
67
|
-
|
|
68
|
-
nodeVerified = nonTerminalNodeVerified; ///
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return nodeVerified;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function verifyChildNodes(childNodes, fileContext) {
|
|
75
|
-
const childNodesVerified = childNodes.every((childNode) => {
|
|
76
|
-
const node = childNode, ///
|
|
77
|
-
nodeVerified = verifyNode(node, fileContext);
|
|
78
|
-
|
|
79
|
-
if (nodeVerified) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return childNodesVerified;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function verifyTerminalNode(terminalNode, fileContext) {
|
|
88
|
-
const terminalNodeVerified = true;
|
|
89
|
-
|
|
90
|
-
return terminalNodeVerified;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function verifyNonTerminalNode(nonTerminalNode, fileContext) {
|
|
94
|
-
let nonTerminalNodeVerified;
|
|
95
|
-
|
|
96
|
-
const ruleName = nonTerminalNode.getRuleName();
|
|
97
|
-
|
|
98
|
-
switch (ruleName) {
|
|
99
|
-
case ARGUMENT_RULE_NAME: {
|
|
100
|
-
const argumentNode = nonTerminalNode, ///
|
|
101
|
-
argumentNodeVerified = verifyArgumentNode(argumentNode, fileContext);
|
|
102
|
-
|
|
103
|
-
nonTerminalNodeVerified = argumentNodeVerified; ///
|
|
104
|
-
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
case TERM_RULE_NAME: {
|
|
109
|
-
const termNode = nonTerminalNode, ///
|
|
110
|
-
types = [],
|
|
111
|
-
context = fileContext, ///
|
|
112
|
-
termVerified = verifyTerm(termNode, types, context);
|
|
113
|
-
|
|
114
|
-
if (termVerified) {
|
|
115
|
-
const firstType = first(types),
|
|
116
|
-
type = firstType; ///
|
|
117
|
-
|
|
118
|
-
if (type !== null) {
|
|
119
|
-
const termString = fileContext.nodeAsString(termNode);
|
|
120
|
-
|
|
121
|
-
fileContext.error(`The type of the constructor's compound '${termString}' term node is not null.`, termNode);
|
|
122
|
-
} else {
|
|
123
|
-
nonTerminalNodeVerified = true; ///
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
default: {
|
|
131
|
-
const childNodes = nonTerminalNode.getChildNodes(),
|
|
132
|
-
childNodesVerified = verifyChildNodes(childNodes, fileContext);
|
|
133
|
-
|
|
134
|
-
nonTerminalNodeVerified = childNodesVerified; ///
|
|
135
|
-
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return nonTerminalNodeVerified;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function verifyArgumentNode(argumentNode, fileContext) {
|
|
144
|
-
let argumentNodeVerified = false;
|
|
145
|
-
|
|
146
|
-
const typeNode = typeNodeQuery(argumentNode),
|
|
147
|
-
termNode = termNodeQuery(argumentNode);
|
|
148
|
-
|
|
149
|
-
if (false) {
|
|
150
|
-
///
|
|
151
|
-
} else if (typeNode !== null) {
|
|
152
|
-
const typeName = typeNameFromTypeNode(typeNode),
|
|
153
|
-
typePresent = fileContext.isTypePresentByTypeName(typeName);
|
|
154
|
-
|
|
155
|
-
if (!typePresent) {
|
|
156
|
-
fileContext.error(`The type '${typeName}' is not present.`, argumentNode);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
argumentNodeVerified = typePresent; ///
|
|
160
|
-
} else if (termNode !== null) {
|
|
161
|
-
const node = termNode, ///
|
|
162
|
-
nodeVerified = verifyNode(node, fileContext);
|
|
163
|
-
|
|
164
|
-
argumentNodeVerified = nodeVerified; ///
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return argumentNodeVerified;
|
|
168
|
-
}
|