occam-verify-cli 0.0.443 → 0.0.444

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/src/axiom.js CHANGED
@@ -71,43 +71,38 @@ export default class Axiom {
71
71
  return json;
72
72
  }
73
73
 
74
- static fromJSON(json, callback) {
75
- let axiom = null;
76
-
74
+ static fromJSON(json, releaseContext) {
77
75
  let { labels } = json;
78
76
 
79
- const { statement, consequent, supposition } = json;
77
+ const labelsJSON = labels; ///
80
78
 
81
- labels = labels.reduce((labels, label) => {
82
- if (labels !== null) {
83
- const json = label; ///
79
+ labels = labelsJSON.map((labelJSON) => {
80
+ const json = labelJSON, ///
81
+ label = Label.fromJSON(json, releaseContext);
84
82
 
85
- label = Label.fromJSON(json, callback); ///
83
+ return label;
84
+ });
86
85
 
87
- if (label !== null) {
88
- labels.push(label);
89
- } else {
90
- labels = null;
91
- }
92
- }
86
+ const { statement, consequent, supposition } = json;
93
87
 
94
- return labels;
95
- }, []);
88
+ let axiom;
96
89
 
97
- if (statement !== null) {
90
+ if (false) {
91
+ ///
92
+ } else if (statement !== null) {
98
93
  const ruleName = UNQUALIFIED_STATEMENT_RULE_NAME,
99
94
  content = `${statement}
100
95
  `,
101
- unqualifiedStatementNode = callback(content, ruleName),
96
+ node = releaseContext.nodeFromContentAndRuleName(content, ruleName),
97
+ unqualifiedStatementNode = node, ///
102
98
  statementNode = statementNodeQuery(unqualifiedStatementNode),
103
99
  consequentNode = null,
104
100
  suppositionNode = null;
105
101
 
106
102
  axiom = new Axiom(labels, statementNode, consequentNode, suppositionNode);
107
- }
108
-
109
- if ((consequent !== null) && (supposition !== null)) {
110
- let content,
103
+ } else if ((consequent !== null) && (supposition !== null)) {
104
+ let node,
105
+ content,
111
106
  statementNode,
112
107
  unqualifiedStatementNode;
113
108
 
@@ -116,7 +111,9 @@ export default class Axiom {
116
111
  content = `${consequent}
117
112
  `;
118
113
 
119
- unqualifiedStatementNode = callback(content, ruleName);
114
+ node = releaseContext.nodeFromContentAndRuleName(content, ruleName);
115
+
116
+ unqualifiedStatementNode = node; ///
120
117
 
121
118
  statementNode = statementNodeQuery(unqualifiedStatementNode);
122
119
 
@@ -125,7 +122,9 @@ export default class Axiom {
125
122
  content = `${supposition}
126
123
  `;
127
124
 
128
- unqualifiedStatementNode = callback(content, ruleName);
125
+ node = releaseContext.nodeFromContentAndRuleName(content, ruleName);
126
+
127
+ unqualifiedStatementNode = node; ///
129
128
 
130
129
  statementNode = statementNodeQuery(unqualifiedStatementNode);
131
130
 
package/src/combinator.js CHANGED
@@ -34,12 +34,13 @@ export default class Combinator {
34
34
  return json;
35
35
  }
36
36
 
37
- static fromJSON(json, callback) {
37
+ static fromJSON(json, releaseContext) {
38
38
  const { statement } = json,
39
39
  ruleName = COMBINATOR_DECLARATION_RULE_NAME,
40
40
  content = `Combinator ${statement}
41
41
  `,
42
- combinatorDeclarationNode = callback(content, ruleName),
42
+ node = releaseContext.nodeFromContentAndRuleName(content, ruleName),
43
+ combinatorDeclarationNode = node, ///
43
44
  statementNode = statementNodeQuery(combinatorDeclarationNode),
44
45
  combinator = new Combinator(statementNode);
45
46
 
package/src/conclusion.js CHANGED
@@ -36,19 +36,15 @@ export default class Conclusion {
36
36
  return json;
37
37
  }
38
38
 
39
- static fromJSON(json, callback) {
40
- let conclusion = null;
41
-
39
+ static fromJSON(json, releaseContext) {
42
40
  const { metastatement } = json,
43
41
  ruleName = UNQUALIFIED_METASTATEMENT_RULE_NAME,
44
42
  content = `${metastatement}
45
43
  `,
46
- unqualifiedMetastatementNode = callback(content, ruleName),
47
- metastatementNode = metastatementNodeQuery(unqualifiedMetastatementNode);
48
-
49
- if (metastatementNode !== null) {
50
- conclusion = new Conclusion(metastatementNode);
51
- }
44
+ node = releaseContext.nodeFromContentAndRuleName(content, ruleName),
45
+ unqualifiedMetastatementNode = node, ///
46
+ metastatementNode = metastatementNodeQuery(unqualifiedMetastatementNode),
47
+ conclusion = new Conclusion(metastatementNode);
52
48
 
53
49
  return conclusion;
54
50
  }
@@ -57,19 +57,31 @@ export default class Constructor {
57
57
  return json;
58
58
  }
59
59
 
60
- static fromJSON(json, callback) {
61
- let { type } = json;
62
-
60
+ static fromJSON(json, releaseContext) {
63
61
  const { term } = json,
64
62
  ruleName = CONSTRUCTOR_DECLARATION_RULE_NAME,
65
63
  content = `Constructor ${term}
66
64
  `,
67
- constructorDeclarationNode = callback(content, ruleName),
65
+ node = releaseContext.nodeFromContentAndRuleName(content, ruleName),
66
+ constructorDeclarationNode = node, ///
68
67
  termNode = statementNodeQuery(constructorDeclarationNode);
69
68
 
70
- json = type; ///
69
+ let { type } = json;
70
+
71
+ const typeJSON = type; ///
72
+
73
+ json = typeJSON; ///
74
+
75
+ type = Type.fromJSON(json, releaseContext);
76
+
77
+ const typeName = type.getName(),
78
+ typePresent = releaseContext.isTypePresentByTypeName(typeName);
79
+
80
+ if (!typePresent) {
81
+ throw new Error(`The '${content}' constructor cannot be instantiated because its '${typeName} is not present.'`);
82
+ }
71
83
 
72
- type = Type.fromJSON(json);
84
+ type = releaseContext.findTypeByTypeName(typeName); ///
73
85
 
74
86
  const constructor = new Constructor(termNode, type);
75
87
 
@@ -6,13 +6,13 @@ import { push } from "../utilities/array";
6
6
  import { leastLineIndexFromNodeAndTokens, greatestLineIndexFromNodeAndTokens } from "../utilities/tokens";
7
7
 
8
8
  export default class FileContext {
9
- constructor(releaseContext, filePath, tokens, node, rules, types, axioms, variables, combinators, constructors) {
9
+ constructor(releaseContext, filePath, tokens, node, types, rules, axioms, variables, combinators, constructors) {
10
10
  this.releaseContext = releaseContext;
11
11
  this.filePath = filePath;
12
12
  this.tokens = tokens;
13
13
  this.node = node;
14
- this.rules = rules;
15
14
  this.types = types;
15
+ this.rules = rules;
16
16
  this.axioms = axioms;
17
17
  this.variables = variables;
18
18
  this.combinators = combinators;
@@ -63,32 +63,32 @@ export default class FileContext {
63
63
  return labels;
64
64
  }
65
65
 
66
- getRules(includeRelease = true) {
67
- const rules = []
66
+ getTypes(includeRelease = true) {
67
+ const types = [];
68
68
 
69
- push(rules, this.rules);
69
+ push(types, this.types);
70
70
 
71
71
  if (includeRelease) {
72
- const releaseContextRules = this.releaseContext.getRules();
72
+ const releaseContextTypes = this.releaseContext.getTypes();
73
73
 
74
- push(rules, releaseContextRules);
74
+ push(types, releaseContextTypes);
75
75
  }
76
76
 
77
- return rules;
77
+ return types;
78
78
  }
79
79
 
80
- getTypes(includeRelease = true) {
81
- const types = [];
80
+ getRules(includeRelease = true) {
81
+ const rules = []
82
82
 
83
- push(types, this.types);
83
+ push(rules, this.rules);
84
84
 
85
85
  if (includeRelease) {
86
- const releaseContextTypes = this.releaseContext.getTypes();
86
+ const releaseContextRules = this.releaseContext.getRules();
87
87
 
88
- push(types, releaseContextTypes);
88
+ push(rules, releaseContextRules);
89
89
  }
90
90
 
91
- return types;
91
+ return rules;
92
92
  }
93
93
 
94
94
  getAxioms(includeRelease = true) {
@@ -295,18 +295,18 @@ export default class FileContext {
295
295
  toJSON() {
296
296
  const json = [];
297
297
 
298
- this.rules.forEach((rule) => {
299
- const ruleJSON = rule.toJSON();
300
-
301
- json.push(ruleJSON);
302
- });
303
-
304
298
  this.types.forEach((type) => {
305
299
  const typeJSON = type.toJSON();
306
300
 
307
301
  json.push(typeJSON);
308
302
  });
309
303
 
304
+ this.rules.forEach((rule) => {
305
+ const ruleJSON = rule.toJSON();
306
+
307
+ json.push(ruleJSON);
308
+ });
309
+
310
310
  this.axioms.forEach((axiom) => {
311
311
  const axiomJSON = axiom.toJSON();
312
312
 
@@ -336,13 +336,13 @@ export default class FileContext {
336
336
 
337
337
  rewriteNodes(node);
338
338
 
339
- const rules = [],
340
- types = [],
339
+ const types = [],
340
+ rules = [],
341
341
  axioms = [],
342
342
  variables = [],
343
343
  combinators = [],
344
344
  constructors = [],
345
- fileContext = new FileContext(releaseContext, filePath, tokens, node, rules, types, axioms, variables, combinators, constructors);
345
+ fileContext = new FileContext(releaseContext, filePath, tokens, node, types, rules, axioms, variables, combinators, constructors);
346
346
 
347
347
  return fileContext;
348
348
  }
@@ -154,73 +154,65 @@ export default class FileReleaseContext extends ReleaseContext {
154
154
  return constructors;
155
155
  }
156
156
 
157
- initialise(dependencyReleaseContexts) {
158
- super.initialise(dependencyReleaseContexts);
157
+ nodeFromContentAndRuleName(content, ruleName) {
158
+ const ruleMap = this.florenceParser.getRuleMap(),
159
+ rule = ruleMap[ruleName],
160
+ tokens = this.florenceLexer.tokenise(content),
161
+ node = this.florenceParser.parse(tokens, rule);
162
+
163
+ if (node !== null) {
164
+ rewriteNodes(node);
165
+ }
159
166
 
160
- const jsonArray = this.contextJSON, ///
161
- callback = (content, ruleName) => {
162
- const ruleMap = this.florenceParser.getRuleMap(),
163
- tokens = this.florenceLexer.tokenise(content),
164
- rule = ruleMap[ruleName],
165
- node = this.florenceParser.parse(tokens, rule);
167
+ return node;
168
+ }
166
169
 
167
- if (node !== null) {
168
- rewriteNodes(node);
169
- }
170
+ initialise(dependencyReleaseContexts) {
171
+ super.initialise(dependencyReleaseContexts);
170
172
 
171
- return node;
172
- };
173
+ const jsonArray = this.contextJSON,
174
+ releaseContext = this; ///
173
175
 
174
176
  jsonArray.forEach((json) => {
175
177
  const { kind } = json;
176
178
 
177
179
  switch (kind) {
178
180
  case TYPE_KIND: {
179
- const type = Type.fromJSON(json);
181
+ const type = Type.fromJSON(json, releaseContext);
180
182
 
181
- if (type !== null) {
182
- this.types.push(type);
183
- }
183
+ this.types.push(type);
184
184
 
185
185
  break;
186
186
  }
187
187
 
188
188
  case RULE_KIND: {
189
- const rule = Rule.fromJSON(json, callback);
189
+ const rule = Rule.fromJSON(json, releaseContext);
190
190
 
191
- if (rule !== null) {
192
- this.rules.push(rule);
193
- }
191
+ this.rules.push(rule);
194
192
 
195
193
  break;
196
194
  }
197
195
 
198
196
  case AXIOM_KIND: {
199
- const axiom = Axiom.fromJSON(json, callback);
197
+ const axiom = Axiom.fromJSON(json, releaseContext);
200
198
 
201
- if (axiom !== null) {
202
- this.axioms.push(axiom);
203
- }
199
+ this.axioms.push(axiom);
204
200
 
205
201
  break;
206
202
  }
207
203
 
208
204
  case COMBINATOR_KIND: {
209
- const combinator = Combinator.fromJSON(json, callback);
205
+ const combinator = Combinator.fromJSON(json, releaseContext);
210
206
 
211
- if (combinator !== null) {
212
- this.combinators.push(combinator);
213
- }
207
+ this.combinators.push(combinator);
214
208
 
215
209
  break;
216
210
  }
217
211
 
218
212
  case CONSTRUCTOR_KIND: {
219
- const constructor = Constructor.fromJSON(json, callback);
213
+ const constructor = Constructor.fromJSON(json, releaseContext);
220
214
 
221
- if (constructor !== null) {
222
- this.constructors.push(constructor);
223
- }
215
+ this.constructors.push(constructor);
224
216
 
225
217
  break;
226
218
  }
@@ -56,6 +56,26 @@ export default class ReleaseContext {
56
56
  return this.dependencyReleaseContexts;
57
57
  }
58
58
 
59
+ findTypeByTypeName(typeName) {
60
+ const types = this.getTypes(),
61
+ type = types.find((type) => {
62
+ const matches = type.matchTypeName(typeName);
63
+
64
+ if (matches) {
65
+ return true;
66
+ }
67
+ }) || null;
68
+
69
+ return type;
70
+ }
71
+
72
+ isTypePresentByTypeName(typeName) {
73
+ const type = this.findTypeByTypeName(typeName),
74
+ typePresent = (type !== null);
75
+
76
+ return typePresent;
77
+ }
78
+
59
79
  getReleaseName() {
60
80
  const name = this.getName(),
61
81
  releaseName = name; ///
package/src/label.js CHANGED
@@ -34,16 +34,11 @@ export default class Label {
34
34
  return json;
35
35
  }
36
36
 
37
- static fromJSON(json, callback) {
38
- let label = null;
39
-
37
+ static fromJSON(json, releaseContext) {
40
38
  const content = json, ///
41
39
  ruleName = LABEL_RULE_NAME,
42
- node = callback(content, ruleName);
43
-
44
- if (node !== null) {
45
- label = new Label(node);
46
- }
40
+ node = releaseContext.nodeFromContentAndRuleName(content, ruleName),
41
+ label = new Label(node);
47
42
 
48
43
  return label;
49
44
  }
package/src/premise.js CHANGED
@@ -71,19 +71,15 @@ export default class Premise {
71
71
  return json;
72
72
  }
73
73
 
74
- static fromJSON(json, callback) {
75
- let premise = null;
76
-
74
+ static fromJSON(json, releaseContext) {
77
75
  const { metastatement } = json,
78
76
  ruleName = UNQUALIFIED_METASTATEMENT_RULE_NAME,
79
77
  content = `${metastatement}
80
78
  `,
81
- unqualifiedMetastatementNode = callback(content, ruleName),
82
- metastatementNode = metastatementNodeQuery(unqualifiedMetastatementNode);
83
-
84
- if (metastatementNode !== null) {
85
- premise = new Premise(metastatementNode);
86
- }
79
+ node = releaseContext.nodeFromContentAndRuleName(content, ruleName),
80
+ unqualifiedMetastatementNode = node, ///
81
+ metastatementNode = metastatementNodeQuery(unqualifiedMetastatementNode),
82
+ premise = new Premise(metastatementNode);
87
83
 
88
84
  return premise;
89
85
  }
package/src/rule.js CHANGED
@@ -91,50 +91,40 @@ export default class Rule {
91
91
  return json;
92
92
  }
93
93
 
94
- static fromJSON(json, callback) {
95
- let rule = null;
94
+ static fromJSON(json, releaseContext) {
95
+ let rule;
96
96
 
97
- let { labels, premises, conclusion } = json;
97
+ let { labels } = json;
98
98
 
99
- labels = labels.reduce((labels, label) => {
100
- if (labels !== null) {
101
- const json = label; ///
99
+ const labelsJSON = labels; ///
102
100
 
103
- label = Label.fromJSON(json, callback); ///
101
+ labels = labelsJSON.map((labelJSON) => {
102
+ const json = labelJSON, ///
103
+ label = Label.fromJSON(json, releaseContext);
104
104
 
105
- if (label !== null) {
106
- labels.push(label);
107
- } else {
108
- labels = null;
109
- }
110
- }
105
+ return label;
106
+ });
111
107
 
112
- return labels;
113
- }, []);
108
+ let { premises } = json;
114
109
 
115
- premises = premises.reduce((premises, premise) => {
116
- if (premises !== null) {
117
- const json = premise; ///
110
+ const premisesJSON = premises; ///
118
111
 
119
- premise = Premise.fromJSON(json, callback); ///
112
+ premises = premisesJSON.map((premiseJSON) => {
113
+ const json = premiseJSON, ///
114
+ premise = Premise.fromJSON(json, releaseContext);
120
115
 
121
- if (premise !== null) {
122
- premises.push(premise);
123
- } else {
124
- premises = null;
125
- }
126
- }
116
+ return premise;
117
+ });
127
118
 
128
- return premises;
129
- }, []);
119
+ let { conclusion } = json;
130
120
 
131
- json = conclusion; ///
121
+ const conclusionJSON = conclusion; ///
132
122
 
133
- conclusion = Conclusion.fromJSON(json, callback);
123
+ json = conclusionJSON; ///
134
124
 
135
- if ((labels !== null) && (premises !== null) && (conclusion !== null)) {
136
- rule = new Rule(labels, premises, conclusion);
137
- }
125
+ conclusion = Conclusion.fromJSON(json, releaseContext);
126
+
127
+ rule = new Rule(labels, premises, conclusion);
138
128
 
139
129
  return rule;
140
130
  }
package/src/type.js CHANGED
@@ -119,15 +119,28 @@ export default class Type {
119
119
  return json;
120
120
  }
121
121
 
122
- static fromJSON(json) {
122
+ static fromJSON(json, releaseContext) {
123
123
  const { name } = json;
124
124
 
125
125
  let { superType } = json;
126
126
 
127
127
  if (superType !== null) {
128
- json = superType; ///
128
+ const superTypeJSON = superType; ///
129
129
 
130
- superType = Type.fromJSON(json);
130
+ json = superTypeJSON; ///
131
+
132
+ superType = Type.fromJSON(json, releaseContext);
133
+
134
+ const superTypeName = superType.getName(),
135
+ superTypePresent = releaseContext.isTypePresentByTypeName(superTypeName);
136
+
137
+ if (!superTypePresent) {
138
+ const typeName = name; ///
139
+
140
+ throw new Error(`The '${typeName}' type cannot be instantiated because its '${superTypeName}' super type is not present.`);
141
+ }
142
+
143
+ superType = releaseContext.findTypeByTypeName(superTypeName); ///
131
144
  }
132
145
 
133
146
  const type = new Type(name, superType);