occam-verify-cli 0.0.613 → 0.0.615
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/README.md +79 -78
- package/lib/log.js +2 -2
- package/lib/verify/metastatement.js +12 -4
- package/lib/verify/statement.js +30 -23
- package/lib/verify/term.js +187 -88
- package/lib/verify/termAsConstructor.js +12 -11
- package/package.json +2 -2
- package/src/log.js +2 -2
- package/src/verify/metastatement.js +1 -1
- package/src/verify/statement.js +42 -35
- package/src/verify/term.js +114 -139
- package/src/verify/termAsConstructor.js +16 -11
package/src/verify/term.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import Verifier from "../verifier";
|
|
4
|
+
|
|
3
5
|
import { first } from "../utilities/array";
|
|
4
6
|
import { objectType } from "../type";
|
|
5
7
|
import { OBJECT_TYPE_NAME } from "../typeNames";
|
|
@@ -10,6 +12,103 @@ const termNodeQuery = nodeQuery("/argument/term!"),
|
|
|
10
12
|
typeNodeQuery = nodeQuery("/argument/type!"),
|
|
11
13
|
variableNodeQuery = nodeQuery("/term/variable!");
|
|
12
14
|
|
|
15
|
+
class TermVerifier extends Verifier {
|
|
16
|
+
verifyTerminalNode(terminalNode, constructorTerminalNode, context) {
|
|
17
|
+
let terminalNodeVerified = false;
|
|
18
|
+
|
|
19
|
+
const matches = terminalNode.match(constructorTerminalNode);
|
|
20
|
+
|
|
21
|
+
if (matches) {
|
|
22
|
+
terminalNodeVerified = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return terminalNodeVerified;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
verifyNonTerminalNode(nonTerminalNode, constructorNonTerminalNode, context) {
|
|
29
|
+
let nonTerminalNodeVerified = false;
|
|
30
|
+
|
|
31
|
+
const ruleName = nonTerminalNode.getRuleName(), ///
|
|
32
|
+
constructorRuleName = constructorNonTerminalNode.getRuleName(); ///
|
|
33
|
+
|
|
34
|
+
if (ruleName === constructorRuleName) {
|
|
35
|
+
switch (ruleName) {
|
|
36
|
+
case ARGUMENT_RULE_NAME: {
|
|
37
|
+
const argumentNode = nonTerminalNode, ///
|
|
38
|
+
constructorArgumentNode = constructorNonTerminalNode, ///
|
|
39
|
+
argumentNodeVerified = this.verifyArgumentNode(argumentNode, constructorArgumentNode, context);
|
|
40
|
+
|
|
41
|
+
nonTerminalNodeVerified = argumentNodeVerified; ///
|
|
42
|
+
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
default: {
|
|
47
|
+
const childNodes = nonTerminalNode.getChildNodes(),
|
|
48
|
+
constructorChildNodes = constructorNonTerminalNode.getChildNodes(),
|
|
49
|
+
nodes = childNodes, ///
|
|
50
|
+
constructorNodes = constructorChildNodes, ///
|
|
51
|
+
nodesVerified = this.verifyNodes(nodes, constructorNodes, context);
|
|
52
|
+
|
|
53
|
+
nonTerminalNodeVerified = nodesVerified; ///
|
|
54
|
+
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return nonTerminalNodeVerified;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
verifyArgumentNode(argumentNode, constructorArgumentNode, context) {
|
|
64
|
+
let argumentNodeVerified = false;
|
|
65
|
+
|
|
66
|
+
const typeNode = typeNodeQuery(argumentNode);
|
|
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
|
+
constructorType = (constructorTypeName === OBJECT_TYPE_NAME) ?
|
|
92
|
+
objectType :
|
|
93
|
+
context.findTypeByTypeName(constructorTypeName),
|
|
94
|
+
firstType = first(types),
|
|
95
|
+
termType = firstType, ///
|
|
96
|
+
type = constructorType, ///
|
|
97
|
+
termTypeEqualToOrSubTypeOfType = termType.isEqualToOrSubTypeOf(type);
|
|
98
|
+
|
|
99
|
+
if (termTypeEqualToOrSubTypeOfType) {
|
|
100
|
+
argumentNodeVerified = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return argumentNodeVerified;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const termVerifier = new TermVerifier();
|
|
111
|
+
|
|
13
112
|
export default function verifyTerm(termNode, types, context) {
|
|
14
113
|
let termVerified = false;
|
|
15
114
|
|
|
@@ -47,27 +146,6 @@ export default function verifyTerm(termNode, types, context) {
|
|
|
47
146
|
return termVerified;
|
|
48
147
|
}
|
|
49
148
|
|
|
50
|
-
export function verifyTermAsVariable(termNode, variables, context) {
|
|
51
|
-
let termVerifiedAsVariable = false;
|
|
52
|
-
|
|
53
|
-
const variableNode = variableNodeQuery(termNode);
|
|
54
|
-
|
|
55
|
-
if (variableNode !== null) {
|
|
56
|
-
const variableName = variableNameFromVariableNode(variableNode),
|
|
57
|
-
variablePresent = context.isVariablePresentByVariableName(variableName);
|
|
58
|
-
|
|
59
|
-
if (variablePresent) {
|
|
60
|
-
const variable = context.findVariableByVariableName(variableName);
|
|
61
|
-
|
|
62
|
-
variables.push(variable);
|
|
63
|
-
|
|
64
|
-
termVerifiedAsVariable = true;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return termVerifiedAsVariable;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
149
|
export function verifyTermAgainstConstructors(termNode, types, context) {
|
|
72
150
|
let termVerifiedAgainstConstructors = false;
|
|
73
151
|
|
|
@@ -91,136 +169,33 @@ export function verifyTermAgainstConstructors(termNode, types, context) {
|
|
|
91
169
|
return termVerifiedAgainstConstructors;
|
|
92
170
|
}
|
|
93
171
|
|
|
94
|
-
function verifyTermAgainstConstructor(termNode, constructor, context) {
|
|
172
|
+
export function verifyTermAgainstConstructor(termNode, constructor, context) {
|
|
95
173
|
const constructorTermNode = constructor.getTermNode(),
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
nodeVerified =
|
|
174
|
+
nonTerminalNNdeA = termNode, ///
|
|
175
|
+
nonTerminalNodeB = constructorTermNode, ///
|
|
176
|
+
nodeVerified = termVerifier.verifyNonTerminalNode(nonTerminalNNdeA, nonTerminalNodeB, context),
|
|
99
177
|
termVerifiedAgainstConstructor = nodeVerified; ///
|
|
100
178
|
|
|
101
179
|
return termVerifiedAgainstConstructor;
|
|
102
180
|
}
|
|
103
181
|
|
|
104
|
-
function
|
|
105
|
-
let
|
|
106
|
-
|
|
107
|
-
const nodeTerminalNode = node.isTerminalNode(),
|
|
108
|
-
constructorNodeTerminalNode = constructorNode.isTerminalNode();
|
|
109
|
-
|
|
110
|
-
if (nodeTerminalNode === constructorNodeTerminalNode) {
|
|
111
|
-
if (nodeTerminalNode) {
|
|
112
|
-
const terminalNode = node, ///
|
|
113
|
-
constructorTerminalNode = constructorNode, ///
|
|
114
|
-
terminalNodeVerified = verifyTerminalNode(terminalNode, constructorTerminalNode, context);
|
|
115
|
-
|
|
116
|
-
nodeVerified = terminalNodeVerified; ///
|
|
117
|
-
} else {
|
|
118
|
-
const nonTerminalNode = node, ///
|
|
119
|
-
constructorNonTerminalNode = constructorNode, ///
|
|
120
|
-
nonTerminalNodeVerified = verifyNonTerminalNode(nonTerminalNode, constructorNonTerminalNode, context);
|
|
121
|
-
|
|
122
|
-
nodeVerified = nonTerminalNodeVerified; ///
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return nodeVerified;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function verifyNodes(nodes, constructorNodes, context) {
|
|
130
|
-
let nodesVerified = false;
|
|
131
|
-
|
|
132
|
-
const nodesLength = nodes.length,
|
|
133
|
-
constructorNodesLength = constructorNodes.length;
|
|
134
|
-
|
|
135
|
-
if (nodesLength === constructorNodesLength) {
|
|
136
|
-
nodesVerified = nodes.every((node, index) => {
|
|
137
|
-
const constructorNode = constructorNodes[index],
|
|
138
|
-
nodeVerified = verifyNode(node, constructorNode, context);
|
|
139
|
-
|
|
140
|
-
if (nodeVerified) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return nodesVerified;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function verifyTerminalNode(terminalNode, constructorTerminalNode, context) {
|
|
150
|
-
let terminalNodeVerified = false;
|
|
151
|
-
|
|
152
|
-
const matches = terminalNode.match(constructorTerminalNode);
|
|
153
|
-
|
|
154
|
-
if (matches) {
|
|
155
|
-
terminalNodeVerified = true;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return terminalNodeVerified;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function verifyNonTerminalNode(nonTerminalNode, constructorNonTerminalNode, context) {
|
|
162
|
-
let nonTerminalNodeVerified = false;
|
|
163
|
-
|
|
164
|
-
const ruleName = nonTerminalNode.getRuleName(), ///
|
|
165
|
-
constructorRuleName = constructorNonTerminalNode.getRuleName(); ///
|
|
166
|
-
|
|
167
|
-
if (ruleName === constructorRuleName) {
|
|
168
|
-
switch (ruleName) {
|
|
169
|
-
case ARGUMENT_RULE_NAME: {
|
|
170
|
-
const argumentNode = nonTerminalNode, ///
|
|
171
|
-
constructorArgumentNode = constructorNonTerminalNode, ///
|
|
172
|
-
argumentNodeVerified = verifyArgumentNode(argumentNode, constructorArgumentNode, context);
|
|
173
|
-
|
|
174
|
-
nonTerminalNodeVerified = argumentNodeVerified; ///
|
|
175
|
-
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
default: {
|
|
180
|
-
const childNodes = nonTerminalNode.getChildNodes(),
|
|
181
|
-
constructorChildNodes = constructorNonTerminalNode.getChildNodes(),
|
|
182
|
-
nodes = childNodes, ///
|
|
183
|
-
constructorNodes = constructorChildNodes, ///
|
|
184
|
-
nodesVerified = verifyNodes(nodes, constructorNodes, context);
|
|
185
|
-
|
|
186
|
-
nonTerminalNodeVerified = nodesVerified; ///
|
|
187
|
-
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return nonTerminalNodeVerified;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function verifyArgumentNode(argumentNode, constructorArgumentNode, context) {
|
|
197
|
-
let argumentNodeVerified = false;
|
|
182
|
+
export function verifyTermAsVariable(termNode, variables, context) {
|
|
183
|
+
let termVerifiedAsVariable = false;
|
|
198
184
|
|
|
199
|
-
const
|
|
185
|
+
const variableNode = variableNodeQuery(termNode);
|
|
200
186
|
|
|
201
|
-
if (
|
|
202
|
-
const
|
|
187
|
+
if (variableNode !== null) {
|
|
188
|
+
const variableName = variableNameFromVariableNode(variableNode),
|
|
189
|
+
variablePresent = context.isVariablePresentByVariableName(variableName);
|
|
203
190
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const types = [],
|
|
207
|
-
termVerified = verifyTerm(termNode, types, context);
|
|
191
|
+
if (variablePresent) {
|
|
192
|
+
const variable = context.findVariableByVariableName(variableName);
|
|
208
193
|
|
|
209
|
-
|
|
210
|
-
const firstType = first(types),
|
|
211
|
-
termType = firstType, ///
|
|
212
|
-
typeNode = typeNodeQuery(constructorArgumentNode),
|
|
213
|
-
typeName = typeNameFromTypeNode(typeNode),
|
|
214
|
-
type = (typeName === OBJECT_TYPE_NAME) ?
|
|
215
|
-
objectType : ///
|
|
216
|
-
context.findTypeByTypeName(typeName),
|
|
217
|
-
termTypeEqualToOrSubTypeOfType = termType.isEqualToOrSubTypeOf(type);
|
|
194
|
+
variables.push(variable);
|
|
218
195
|
|
|
219
|
-
|
|
220
|
-
argumentNodeVerified = true;
|
|
221
|
-
}
|
|
196
|
+
termVerifiedAsVariable = true;
|
|
222
197
|
}
|
|
223
198
|
}
|
|
224
199
|
|
|
225
|
-
return
|
|
200
|
+
return termVerifiedAsVariable;
|
|
226
201
|
}
|
|
@@ -7,7 +7,8 @@ import { first } from "../utilities/array";
|
|
|
7
7
|
import { nodeQuery, typeNameFromTypeNode } from "../utilities/query";
|
|
8
8
|
import { TERM_RULE_NAME, ARGUMENT_RULE_NAME } from "../ruleNames";
|
|
9
9
|
|
|
10
|
-
const typeNodeQuery = nodeQuery("/argument/type")
|
|
10
|
+
const typeNodeQuery = nodeQuery("/argument/type"),
|
|
11
|
+
termNodeQuery = nodeQuery("/argument/term");
|
|
11
12
|
|
|
12
13
|
export default function verifyTermAsConstructor(termNode, typeNode, fileContext) {
|
|
13
14
|
let termVerifiedAsConstructor = false;
|
|
@@ -139,24 +140,28 @@ function verifyNonTerminalNode(nonTerminalNode, fileContext) {
|
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
function verifyArgumentNode(argumentNode, fileContext) {
|
|
142
|
-
let
|
|
143
|
+
let argumentNodeVerified = false;
|
|
143
144
|
|
|
144
|
-
const typeNode = typeNodeQuery(argumentNode)
|
|
145
|
+
const typeNode = typeNodeQuery(argumentNode),
|
|
146
|
+
termNode = termNodeQuery(argumentNode);
|
|
145
147
|
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
fileContext.error(`The ${argumentString} argument should be a type.`, argumentNode);
|
|
150
|
-
} else {
|
|
148
|
+
if (false) {
|
|
149
|
+
///
|
|
150
|
+
} else if (typeNode !== null) {
|
|
151
151
|
const typeName = typeNameFromTypeNode(typeNode),
|
|
152
152
|
typePresent = fileContext.isTypePresentByTypeName(typeName);
|
|
153
153
|
|
|
154
154
|
if (!typePresent) {
|
|
155
155
|
fileContext.error(`The type '${typeName}' is not present.`, argumentNode);
|
|
156
|
-
} else {
|
|
157
|
-
typeNodeVerified = true;
|
|
158
156
|
}
|
|
157
|
+
|
|
158
|
+
argumentNodeVerified = typePresent; ///
|
|
159
|
+
} else if (termNode !== null) {
|
|
160
|
+
const node = termNode, ///
|
|
161
|
+
nodeVerified = verifyNode(node, fileContext);
|
|
162
|
+
|
|
163
|
+
argumentNodeVerified = nodeVerified; ///
|
|
159
164
|
}
|
|
160
165
|
|
|
161
|
-
return
|
|
166
|
+
return argumentNodeVerified;
|
|
162
167
|
}
|