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.
Files changed (125) hide show
  1. package/bin/action/verify.js +14 -4
  2. package/lib/conclusion.js +10 -5
  3. package/lib/consequent.js +8 -3
  4. package/lib/context/file.js +74 -4
  5. package/lib/context/release.js +7 -2
  6. package/lib/equality.js +16 -16
  7. package/lib/premise.js +12 -7
  8. package/lib/supposition.js +9 -4
  9. package/lib/type.js +3 -8
  10. package/lib/utilities/string.js +26 -13
  11. package/lib/verifier/node/metastatement.js +173 -0
  12. package/lib/verifier/node/statementAsCombinator.js +186 -0
  13. package/lib/verifier/node/termAsConstructor.js +224 -0
  14. package/lib/verifier/node.js +158 -0
  15. package/lib/verifier/{metastatementForMetavariable → nodes/metastatementForMetavariable}/conclusion.js +13 -12
  16. package/lib/verifier/{metastatementForMetavariable → nodes/metastatementForMetavariable}/premise.js +13 -12
  17. package/lib/verifier/nodes/metastatementForMetavariable.js +198 -0
  18. package/lib/verifier/nodes/statement.js +199 -0
  19. package/lib/verifier/{statementForMetavariable → nodes/statementForMetavariable}/conclusion.js +13 -12
  20. package/lib/verifier/{statementForMetavariable → nodes/statementForMetavariable}/premise.js +13 -12
  21. package/lib/verifier/nodes/statementForMetavariable.js +203 -0
  22. package/lib/verifier/nodes/term.js +212 -0
  23. package/lib/verifier/{termForVariable/supposition.js → nodes/termForVariable/consequent.js} +13 -12
  24. package/lib/verifier/{termForVariable/consequent.js → nodes/termForVariable/supposition.js} +13 -12
  25. package/lib/verifier/nodes/termForVariable.js +209 -0
  26. package/lib/verifier/nodes.js +175 -0
  27. package/lib/verify/assertion/type.js +20 -10
  28. package/lib/verify/axiom.js +3 -3
  29. package/lib/verify/conclusion.js +3 -3
  30. package/lib/verify/conjecture.js +3 -3
  31. package/lib/verify/consequent.js +3 -3
  32. package/lib/verify/declaration/combinator.js +7 -2
  33. package/lib/verify/declaration/constructor.js +8 -2
  34. package/lib/verify/declaration/metavariable.js +7 -2
  35. package/lib/verify/declaration/type.js +7 -2
  36. package/lib/verify/declaration/variable.js +8 -2
  37. package/lib/verify/file.js +3 -3
  38. package/lib/verify/label.js +9 -4
  39. package/lib/verify/lemma.js +3 -3
  40. package/lib/verify/metastatement/qualified.js +5 -6
  41. package/lib/verify/metastatement/unqualified.js +9 -7
  42. package/lib/verify/metastatement.js +34 -157
  43. package/lib/verify/metavariable.js +6 -4
  44. package/lib/verify/premise.js +3 -3
  45. package/lib/verify/release.js +3 -3
  46. package/lib/verify/rule.js +3 -3
  47. package/lib/verify/statement/qualified.js +5 -6
  48. package/lib/verify/statement/unqualified.js +9 -7
  49. package/lib/verify/statement.js +112 -317
  50. package/lib/verify/statementAsCombinator.js +8 -82
  51. package/lib/verify/supposition.js +3 -3
  52. package/lib/verify/term.js +69 -213
  53. package/lib/verify/termAsConstructor.js +15 -89
  54. package/lib/verify/theorem.js +3 -3
  55. package/lib/verify/type.js +7 -5
  56. package/lib/verify/typeInference.js +5 -5
  57. package/lib/verify/variable.js +7 -5
  58. package/package.json +5 -5
  59. package/src/conclusion.js +5 -4
  60. package/src/consequent.js +3 -2
  61. package/src/context/file.js +11 -4
  62. package/src/context/release.js +9 -2
  63. package/src/equality.js +10 -10
  64. package/src/premise.js +7 -6
  65. package/src/supposition.js +4 -3
  66. package/src/type.js +3 -8
  67. package/src/utilities/string.js +34 -23
  68. package/src/verifier/node/metastatement.js +57 -0
  69. package/src/verifier/node/statementAsCombinator.js +80 -0
  70. package/src/verifier/node/termAsConstructor.js +124 -0
  71. package/src/verifier/node.js +85 -0
  72. package/src/verifier/nodes/metastatementForMetavariable/conclusion.js +11 -0
  73. package/src/verifier/nodes/metastatementForMetavariable/premise.js +11 -0
  74. package/src/verifier/{metastatementForMetavariable.js → nodes/metastatementForMetavariable.js} +6 -6
  75. package/src/verifier/nodes/statement.js +98 -0
  76. package/src/verifier/nodes/statementForMetavariable/conclusion.js +11 -0
  77. package/src/verifier/nodes/statementForMetavariable/premise.js +11 -0
  78. package/src/verifier/{statementForMetavariable.js → nodes/statementForMetavariable.js} +10 -10
  79. package/src/verifier/nodes/term.js +111 -0
  80. package/src/verifier/nodes/termForVariable/consequent.js +11 -0
  81. package/src/verifier/nodes/termForVariable/supposition.js +11 -0
  82. package/src/verifier/{termForVariable.js → nodes/termForVariable.js} +9 -9
  83. package/src/verifier/nodes.js +111 -0
  84. package/src/verify/assertion/type.js +25 -9
  85. package/src/verify/axiom.js +2 -2
  86. package/src/verify/conclusion.js +2 -2
  87. package/src/verify/conjecture.js +2 -2
  88. package/src/verify/consequent.js +2 -2
  89. package/src/verify/declaration/combinator.js +9 -1
  90. package/src/verify/declaration/constructor.js +15 -1
  91. package/src/verify/declaration/metavariable.js +9 -1
  92. package/src/verify/declaration/type.js +14 -1
  93. package/src/verify/declaration/variable.js +15 -1
  94. package/src/verify/file.js +2 -2
  95. package/src/verify/label.js +10 -2
  96. package/src/verify/lemma.js +4 -4
  97. package/src/verify/metastatement/qualified.js +4 -6
  98. package/src/verify/metastatement/unqualified.js +9 -7
  99. package/src/verify/metastatement.js +32 -57
  100. package/src/verify/metavariable.js +6 -3
  101. package/src/verify/premise.js +2 -2
  102. package/src/verify/release.js +2 -2
  103. package/src/verify/rule.js +2 -2
  104. package/src/verify/statement/qualified.js +4 -6
  105. package/src/verify/statement/unqualified.js +9 -7
  106. package/src/verify/statement.js +159 -283
  107. package/src/verify/statementAsCombinator.js +9 -129
  108. package/src/verify/supposition.js +2 -2
  109. package/src/verify/term.js +94 -159
  110. package/src/verify/termAsConstructor.js +20 -135
  111. package/src/verify/theorem.js +2 -2
  112. package/src/verify/type.js +7 -4
  113. package/src/verify/typeInference.js +4 -4
  114. package/src/verify/variable.js +7 -4
  115. package/lib/verifier/metastatementForMetavariable.js +0 -198
  116. package/lib/verifier/statementForMetavariable.js +0 -203
  117. package/lib/verifier/termForVariable.js +0 -209
  118. package/lib/verifier.js +0 -138
  119. package/src/verifier/metastatementForMetavariable/conclusion.js +0 -9
  120. package/src/verifier/metastatementForMetavariable/premise.js +0 -9
  121. package/src/verifier/statementForMetavariable/conclusion.js +0 -9
  122. package/src/verifier/statementForMetavariable/premise.js +0 -9
  123. package/src/verifier/termForVariable/consequent.js +0 -9
  124. package/src/verifier/termForVariable/supposition.js +0 -9
  125. package/src/verifier.js +0 -74
@@ -1,22 +1,22 @@
1
1
  "use strict";
2
2
 
3
3
  import Combinator from "../combinator";
4
- import verifyTerm from "../verify/term";
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.debug(`Verifying the '${statementString}' combinator....`, statementNode);
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.info(`Verified the '${statementString}' combinator.`, statementNode);
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.debug(`Verifying the '${suppositionString}' supposition...`, suppositionNode);
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.info(`Verified the '${suppositionString}' supposition.`, suppositionNode);
41
+ proofContext.debug(`...verified the '${suppositionString}' supposition.`, suppositionNode);
42
42
  }
43
43
 
44
44
  return suppositionVerified;
@@ -1,222 +1,157 @@
1
1
  "use strict";
2
2
 
3
- import Verifier from "../verifier";
3
+ import termNodesVerifier from "../verifier/nodes/term";
4
4
 
5
5
  import { first } from "../utilities/array";
6
- import { objectType } from "../type";
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 termNodeQuery = nodeQuery("/argument/term!"),
12
- typeNodeQuery = nodeQuery("/argument/type!"),
13
- variableNodeQuery = nodeQuery("/term/variable!");
8
+ const variableNodeQuery = nodeQuery("/term/variable!");
14
9
 
15
- class TermVerifier extends Verifier {
16
- verifyTerminalNode(terminalNode, constructorTerminalNode, context) {
17
- let terminalNodeVerified = false;
10
+ function verifyTerm(termNode, types, context, verifyAhead) {
11
+ let termVerified;
18
12
 
19
- const matches = terminalNode.match(constructorTerminalNode);
13
+ const termString = context.nodeAsString(termNode);
20
14
 
21
- if (matches) {
22
- terminalNodeVerified = true;
23
- }
15
+ context.trace(`Verifying the '${termString}' term...`, termNode);
24
16
 
25
- return terminalNodeVerified;
26
- }
17
+ const verifyTermFunctions = [
18
+ verifyTermAsStandaloneVariable,
19
+ verifyTermAgainstConstructors
20
+ ];
27
21
 
28
- verifyNonTerminalNode(nonTerminalNode, constructorNonTerminalNode, context) {
29
- let nonTerminalNodeVerified = false;
22
+ termVerified = verifyTermFunctions.some((verifyTermFunction) => {
23
+ const termVerified = verifyTermFunction(termNode, types, context, verifyAhead);
30
24
 
31
- const ruleName = nonTerminalNode.getRuleName(), ///
32
- constructorRuleName = constructorNonTerminalNode.getRuleName(); ///
25
+ if (termVerified) {
26
+ return true;
27
+ }
28
+ });
33
29
 
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);
30
+ if (termVerified) {
31
+ const firstType = first(types),
32
+ type = firstType, ///
33
+ typeName = type.getName();
40
34
 
41
- nonTerminalNodeVerified = argumentNodeVerified; ///
35
+ context.debug(`...verified the '${termString}' term, which has been given the '${typeName}' type.`, termNode);
36
+ }
42
37
 
43
- break;
44
- }
38
+ return termVerified;
39
+ }
45
40
 
46
- default: {
47
- const childNodes = nonTerminalNode.getChildNodes(),
48
- constructorChildNodes = constructorNonTerminalNode.getChildNodes(),
49
- nodes = childNodes, ///
50
- constructorNodes = constructorChildNodes, ///
51
- nodesVerified = this.verifyNodes(nodes, constructorNodes, context);
41
+ Object.assign(termNodesVerifier, {
42
+ verifyTerm
43
+ });
52
44
 
53
- nonTerminalNodeVerified = nodesVerified; ///
45
+ export default verifyTerm;
54
46
 
55
- break;
56
- }
57
- }
58
- }
47
+ export function verifyTermAgainstConstructors(termNode, types, context, verifyAhead) {
48
+ let termVerifiedAgainstConstructors;
59
49
 
60
- return nonTerminalNodeVerified;
61
- }
50
+ const constructors = context.getConstructors();
62
51
 
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
- 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
- return argumentNodeVerified;
111
- }
60
+ return termVerifiedAgainstConstructors;
112
61
  }
113
62
 
114
- export const termVerifier = new TermVerifier();
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.debug(`Verifying the '${termString}' term...`, termNode);
68
+ context.trace(`Verifying the '${termString}' term as a variable...`, termNode);
122
69
 
123
- if (!termVerified) {
124
- const variables = [],
125
- termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context);
70
+ const variableNode = variableNodeQuery(termNode);
126
71
 
127
- if (termVerifiedAsVariable) {
128
- const firstVariable = first(variables),
129
- variable = firstVariable, ///
130
- type = variable.getType();
72
+ if (variableNode !== null) {
73
+ const variableName = variableNameFromVariableNode(variableNode),
74
+ variablePresent = context.isVariablePresentByVariableName(variableName);
131
75
 
132
- types.push(type);
76
+ if (variablePresent) {
77
+ let verifiedAhead;
133
78
 
134
- termVerified = true;
135
- }
136
- }
79
+ const variable = context.findVariableByVariableName(variableName);
80
+
81
+ variables.push(variable);
137
82
 
138
- if (!termVerified) {
139
- const termVerifiedAgainstConstructors = verifyTermAgainstConstructors(termNode, types, context);
83
+ verifiedAhead = verifyAhead();
140
84
 
141
- if (termVerifiedAgainstConstructors) {
142
- termVerified = true;
85
+ termVerifiedAsVariable = verifiedAhead; ///
143
86
  }
144
87
  }
145
88
 
146
- if (termVerified) {
147
- const firstType = first(types),
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 termVerified;
93
+ return termVerifiedAsVariable;
155
94
  }
156
95
 
157
- export function verifyTermAgainstConstructors(termNode, types, context) {
158
- let termVerifiedAgainstConstructors = false;
159
-
160
- const termString = context.nodeAsString(termNode);
96
+ function verifyTermAgainstConstructor(termNode, types, constructor, context, verifyAhead) {
97
+ let termVerifiedAgainstConstructor;
161
98
 
162
- context.trace(`Verifying the '${termString}' term against constructors...`, termNode);
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
- if (termVerifiedAgainstConstructor) {
169
- return true;
170
- }
171
- }) || null;
102
+ context.trace(`Verifying the '${termString}' term against the '${constructorString}' constructor...`, termNode);
172
103
 
173
- if (constructor !== null) {
174
- const type = constructor.getType();
104
+ const constructorTermNode = constructor.getTermNode(),
105
+ nonTerminalNNdeA = termNode, ///
106
+ nonTerminalNodeB = constructorTermNode, ///
107
+ nodeVerified = termNodesVerifier.verifyNonTerminalNode(nonTerminalNNdeA, nonTerminalNodeB, context, () => {
108
+ let verifiedAhead;
175
109
 
176
- types.push(type);
110
+ const type = constructor.getType();
177
111
 
178
- termVerifiedAgainstConstructors = true;
179
- }
112
+ types.push(type);
180
113
 
181
- return termVerifiedAgainstConstructors;
182
- }
114
+ verifiedAhead = verifyAhead();
183
115
 
184
- export function verifyTermAgainstConstructor(termNode, constructor, context) {
185
- const termString = context.nodeAsString(termNode),
186
- constructorString = constructor.getString();
116
+ return verifiedAhead;
117
+ });
187
118
 
188
- context.trace(`Verifying the '${termString}' term against the '${constructorString}' constructor.`, termNode);
119
+ termVerifiedAgainstConstructor = nodeVerified; ///
189
120
 
190
- const constructorTermNode = constructor.getTermNode(),
191
- nonTerminalNNdeA = termNode, ///
192
- nonTerminalNodeB = constructorTermNode, ///
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
- export function verifyTermAsVariable(termNode, variables, context) {
200
- let termVerifiedAsVariable = false;
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 variableNode = variableNodeQuery(termNode);
135
+ const variables = [],
136
+ termVerifiedAsVariable = verifyTermAsVariable(termNode, variables, context, () => {
137
+ let verifiedAhead;
207
138
 
208
- if (variableNode !== null) {
209
- const variableName = variableNameFromVariableNode(variableNode),
210
- variablePresent = context.isVariablePresentByVariableName(variableName);
139
+ const firstVariable = first(variables),
140
+ variable = firstVariable, ///
141
+ type = variable.getType();
211
142
 
212
- if (variablePresent) {
213
- const variable = context.findVariableByVariableName(variableName);
143
+ types.push(type);
214
144
 
215
- variables.push(variable);
145
+ verifiedAhead = verifyAhead();
216
146
 
217
- termVerifiedAsVariable = true;
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 termVerifiedAsVariable;
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 { first } from "../utilities/array";
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
- let type = null;
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
- termString = fileContext.nodeAsString(termNode);
15
+ const nonTerminalNode = termNode, ///
16
+ childNodes = nonTerminalNode.getChildNodes(),
17
+ childNodesVerified = termAsConstructorNodeVerifier.verifyChildNodes(childNodes, fileContext, () => {
18
+ const verifiedAhead = true;
20
19
 
21
- const childNodes = nonTerminalNode.getChildNodes(),
22
- childNodesVerified = verifyChildNodes(childNodes, fileContext);
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.error(`The '${termString}' constructor's '${typeName}' type is not present.`, termNode);
36
+ fileContext.info(`The '${termString}' constructor's '${typeName}' type is not present.`, termNode);
36
37
  }
37
38
  }
38
- }
39
39
 
40
- if (termVerifiedAsConstructor) {
41
- const tokens = fileContext.getTokens(),
42
- constructor = Constructor.fromTermNodeTypeAndTokens(termNode, type, tokens);
40
+ if (termVerifiedAsConstructor) {
41
+ const tokens = fileContext.getTokens(),
42
+ constructor = Constructor.fromTermNodeTypeAndTokens(termNode, type, tokens);
43
43
 
44
- fileContext.addConstructor(constructor);
44
+ fileContext.addConstructor(constructor);
45
+ }
45
46
  }
46
47
 
47
48
  if (termVerifiedAsConstructor) {
48
- fileContext.info(`Verified the '${termString}' constructor.`, termNode);
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
- }