occam-verify-cli 0.0.697 → 0.0.698

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