occam-verify-cli 0.0.333 → 0.0.335

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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { labelsAsString } from "./utilities/string";
3
+ import {nodeAsString} from "./utilities/string";
4
4
 
5
5
  export default class Axiom {
6
6
  constructor(labels, statementNode, suppositionStatementNode, consequentStatementNode) {
@@ -26,10 +26,46 @@ export default class Axiom {
26
26
  return this.consequentStatementNode;
27
27
  }
28
28
 
29
- asString() {
30
- const string = labelsAsString(this.labels);
29
+ matchLabelName(labelName) {
30
+ const matchesLabelName = this.labels.some((label) => {
31
+ const name = labelName, ///
32
+ labelMatchesName = label.matchName(name);
31
33
 
32
- return string;
34
+ if (labelMatchesName) {
35
+ return true;
36
+ }
37
+ });
38
+
39
+ return matchesLabelName;
40
+ }
41
+
42
+ toString() {
43
+ const labelsJSON = this.labels.map((label) => {
44
+ const labelJSON = label.asJSON();
45
+
46
+ return labelJSON;
47
+ }),
48
+ statementString = (this.statementNode === null) ?
49
+ null :
50
+ nodeAsString(this.statementNode),
51
+ consequentStatementString = (this.consequentStatementNode === null) ?
52
+ null :
53
+ nodeAsString(this.consequentStatementNode),
54
+ suppositionStatementString = (this.suppositionStatementNode === null) ?
55
+ null :
56
+ nodeAsString(this.suppositionStatementNode),
57
+ labels = labelsJSON, ///
58
+ statement = statementString, ///
59
+ consequent = consequentStatementString, ///
60
+ supposition = suppositionStatementString, ///
61
+ json = {
62
+ labels,
63
+ statement,
64
+ consequent,
65
+ supposition
66
+ };
67
+
68
+ return json;
33
69
  }
34
70
 
35
71
  static fromStatementNodeAndLabels(statementNode, labels) {
package/src/combinator.js CHANGED
@@ -17,6 +17,16 @@ export default class Combinator {
17
17
  return string;
18
18
  }
19
19
 
20
+ toJSON() {
21
+ const statementString = nodeAsString(this.statementNode),
22
+ statement = statementString, ///
23
+ json = {
24
+ statement
25
+ };
26
+
27
+ return json;
28
+ }
29
+
20
30
  static fromStatementNode(statementNode) {
21
31
  const combinator = new Combinator(statementNode);
22
32
 
package/src/conclusion.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  import { first } from "./utilities/array";
4
+ import { nodeAsString } from "./utilities/string";
4
5
  import { metavariableNameFromMetavariableNode } from "./utilities/query";
5
6
  import { METAVARIABLE_RULE_NAME, METASTATEMENT_RULE_NAME } from "./ruleNames";
6
7
 
@@ -22,6 +23,16 @@ export default class Conclusion {
22
23
  return metastatementNodeMatches;
23
24
  }
24
25
 
26
+ toJSON() {
27
+ const metastatementString = nodeAsString(this.metastatementNode),
28
+ metastatement = metastatementString, ///
29
+ json = {
30
+ metastatement
31
+ };
32
+
33
+ return json;
34
+ }
35
+
25
36
  static fromMetastatementNode(metastatementNode) {
26
37
  const conclusion = new Conclusion(metastatementNode);
27
38
 
@@ -33,6 +33,21 @@ export default class Constructor {
33
33
  return string;
34
34
  }
35
35
 
36
+ toJSON() {
37
+ const termString = nodeAsString(this.termNode),
38
+ typeJSON = (this.type === null) ?
39
+ null :
40
+ this.type.toJSON(),
41
+ term = termString, ///
42
+ type = typeJSON, ///
43
+ json = {
44
+ term,
45
+ type
46
+ };
47
+
48
+ return json;
49
+ }
50
+
36
51
  static fromTermNodeAndType(termNode, type) {
37
52
  const constructor = new Constructor(termNode, type);
38
53
 
@@ -41,6 +41,27 @@ class FileContext {
41
41
  return this.variables;
42
42
  }
43
43
 
44
+ getLabels() {
45
+ const labels = [];
46
+
47
+ const rules = this.getRules(),
48
+ axioms = this.getAxioms();
49
+
50
+ rules.forEach((rule) => {
51
+ const ruleLabels = rule.getLabels();
52
+
53
+ push(labels, ruleLabels);
54
+ });
55
+
56
+ axioms.forEach((axiom) => {
57
+ const axiomLabels = axiom.getLabels();
58
+
59
+ push(labels, axiomLabels);
60
+ });
61
+
62
+ return labels;
63
+ }
64
+
44
65
  getRules(bubble = true) {
45
66
  const rules = [
46
67
  ...this.rules
@@ -136,14 +157,27 @@ class FileContext {
136
157
  return type;
137
158
  }
138
159
 
160
+ findLabelByLabelName(labelName) {
161
+ const name = labelName, ///
162
+ labels = this.getLabels(),
163
+ label = labels.find((label) => {
164
+ const matches = label.matchName(name);
165
+
166
+ if (matches) {
167
+ return true;
168
+ }
169
+ }) || null;
170
+
171
+ return label;
172
+ }
173
+
139
174
  findRuleByReferenceName(referenceName) {
140
- const label = referenceName, ///
175
+ const labelName = referenceName, ///
141
176
  rules = this.getRules(),
142
177
  rule = rules.find((rule) => {
143
- const ruleLabels = rule.getLabels(),
144
- ruleLabelsIncludesLabel = ruleLabels.includes(label);
178
+ const ruleMatchesLabelName = rule.matchLabelName(labelName);
145
179
 
146
- if (ruleLabelsIncludesLabel) {
180
+ if (ruleMatchesLabelName) {
147
181
  return true;
148
182
  }
149
183
  }) || null;
@@ -152,13 +186,12 @@ class FileContext {
152
186
  }
153
187
 
154
188
  findAxiomByReferenceName(referenceName) {
155
- const label = referenceName, ///
189
+ const labelName = referenceName, ///
156
190
  axioms = this.getAxioms(),
157
191
  axiom = axioms.find((axiom) => {
158
- const axiomLabels = axiom.getLabels(),
159
- axiomLabelsIncludesLabel = axiomLabels.includes(label);
192
+ const axiomMatchesLabelName = axiom.matchLabelName(labelName);
160
193
 
161
- if (axiomLabelsIncludesLabel) {
194
+ if (axiomMatchesLabelName) {
162
195
  return true;
163
196
  }
164
197
  }) || null;
@@ -180,14 +213,6 @@ class FileContext {
180
213
  return variable;
181
214
  }
182
215
 
183
- isLabelPresent(label) {
184
- const labels = this.getLabels(),
185
- labelsIncludesLabel = labels.includes(label),
186
- labelPresent = labelsIncludesLabel; ///
187
-
188
- return labelPresent;
189
- }
190
-
191
216
  isTypePresentByTypeName(typeName) {
192
217
  const type = this.findTypeByTypeName(typeName),
193
218
  typePresent = (type !== null);
@@ -195,24 +220,18 @@ class FileContext {
195
220
  return typePresent;
196
221
  }
197
222
 
198
- isVariablePresentByVariableName(variableName) {
199
- const variable = this.findVariableByVariableName(variableName),
200
- variablePresent = (variable !== null);
223
+ isLabelPresentByLabelName(labelName) {
224
+ const label = this.findLabelByLabelName(labelName),
225
+ labelPresent = (label !== null);
201
226
 
202
- return variablePresent;
227
+ return labelPresent;
203
228
  }
204
229
 
205
- getLabels() {
206
- const axioms = this.getAxioms(),
207
- labels = axioms.reduce((labels, axiom) => {
208
- const axiomLabels = axiom.getLabels();
209
-
210
- push(labels, axiomLabels);
211
-
212
- return labels;
213
- }, []);
230
+ isVariablePresentByVariableName(variableName) {
231
+ const variable = this.findVariableByVariableName(variableName),
232
+ variablePresent = (variable !== null);
214
233
 
215
- return labels;
234
+ return variablePresent;
216
235
  }
217
236
 
218
237
  addType(type) {
@@ -260,6 +279,51 @@ class FileContext {
260
279
  this.context.complete(this.filePath, leastLineIndex, greatestLineIndex);
261
280
  }
262
281
 
282
+ toJSON() {
283
+ const filePath = this.getFilePath(),
284
+ rulesJSON = this.rules.map((rule) => {
285
+ const ruleJSON = rule.toJSON(this.tokens);
286
+
287
+ return ruleJSON;
288
+ }),
289
+ typesJSON = this.types.map((type) => {
290
+ const typeJSON = type.toJSON(this.tokens);
291
+
292
+ return typeJSON;
293
+ }),
294
+ axiomsJSON = this.axioms.map((axiom) => {
295
+ const axiomJSON = axiom.toJSON(this.tokens);
296
+
297
+ return axiomJSON;
298
+ }),
299
+ combinatorsJSON = this.combinators.map((combinator) => {
300
+ const combinatorJSON = combinator.toJSON(this.tokens);
301
+
302
+ return combinatorJSON;
303
+ }),
304
+ constructorsJSON = this.constructors.map((constructor) => {
305
+ const constructorJSON = constructor.toJSON(this.tokens);
306
+
307
+ return constructorJSON;
308
+ }),
309
+ path = filePath, ///
310
+ rules = rulesJSON, ///
311
+ types = typesJSON, ///
312
+ axioms = axiomsJSON, ///
313
+ combinators = combinatorsJSON, ///
314
+ constructors = constructorsJSON, ///
315
+ json = {
316
+ path,
317
+ rules,
318
+ types,
319
+ axioms,
320
+ combinators,
321
+ constructors
322
+ };
323
+
324
+ return json;
325
+ }
326
+
263
327
  static fromReleaseContextAndFilePath(releaseContext, filePath) {
264
328
  const file = releaseContext.getFile(filePath),
265
329
  content = file.getContent(),
@@ -247,6 +247,20 @@ export default class ReleaseContext {
247
247
  this.releaseContexts = releaseContexts;
248
248
  }
249
249
 
250
+ toJSON() {
251
+ const fileContextsJSON = this.fileContexts.map((fileContext) => {
252
+ const fileContextJSON = fileContext.toJSON();
253
+
254
+ return fileContextJSON;
255
+ }),
256
+ files = fileContextsJSON, ///
257
+ json = {
258
+ files
259
+ };
260
+
261
+ return json;
262
+ }
263
+
250
264
  static fromLogReleaseAndCallbacks(log, release, callbacks, ...remainingArguments) {
251
265
  const verified = false,
252
266
  customGrammar = customGrammarFromRelease(release),
package/src/label.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ import { nodeAsString } from "./utilities/string";
4
+ import { labelNameFromLabelNode } from "./utilities/query";
5
+
6
+ export default class Label {
7
+ constructor(node) {
8
+ this.node = node;
9
+ }
10
+
11
+ getNode() {
12
+ return this.node;
13
+ }
14
+
15
+ matchName(name) {
16
+ const labelNode = this.node,
17
+ labelName = labelNameFromLabelNode(labelNode),
18
+ matchesName = (labelName === name);
19
+
20
+ return matchesName;
21
+ }
22
+
23
+ asString() {
24
+ const string = nodeAsString(this.node);
25
+
26
+ return string;
27
+ }
28
+
29
+ toJSON() {
30
+ const string = nodeAsString(this.node),
31
+ json = string; ///
32
+
33
+ return json;
34
+ }
35
+
36
+ static fromLabelNode(labelNode) {
37
+ const node = labelNode, ///
38
+ variable = new Label(node);
39
+
40
+ return variable;
41
+ }
42
+ }
package/src/premise.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import MetaSubstitution from "./metaSubstitution";
4
4
 
5
+ import { nodeAsString } from "./utilities/string";
5
6
  import { first, second } from "./utilities/array";
6
7
  import { nodeQuery, nodesQuery } from "./utilities/query";
7
8
  import { metavariableNameFromMetavariableNode } from "./utilities/query";
@@ -59,6 +60,16 @@ export default class Premise {
59
60
  return metastatementNodeMatches;
60
61
  }
61
62
 
63
+ toJSON() {
64
+ const metastatementString = nodeAsString(this.metastatementNode),
65
+ metastatement = metastatementString, ///
66
+ json = {
67
+ metastatement
68
+ };
69
+
70
+ return json;
71
+ }
72
+
62
73
  static fromMetastatementNode(metastatementNode) {
63
74
  const premise = new Premise(metastatementNode);
64
75
 
package/src/rule.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { prune } from "./utilities/array";
4
4
  import { someSubArray } from "./utilities/array";
5
- import { labelsAsString } from "./utilities/string";
5
+ import { lineIndexFromLabelsAndTokens } from "./utilities/tokens";
6
6
 
7
7
  export default class Rule {
8
8
  constructor(labels, premises, conclusion) {
@@ -23,6 +23,19 @@ export default class Rule {
23
23
  return this.conclusion;
24
24
  }
25
25
 
26
+ matchLabelName(labelName) {
27
+ const matchesLabelName = this.labels.some((label) => {
28
+ const name = labelName, ///
29
+ labelMatchesName = label.matchName(name);
30
+
31
+ if (labelMatchesName) {
32
+ return true;
33
+ }
34
+ });
35
+
36
+ return matchesLabelName;
37
+ }
38
+
26
39
  matchMetastatement(metastatementNode, metaproofContext) {
27
40
  let metastatementNatches;
28
41
 
@@ -48,13 +61,33 @@ export default class Rule {
48
61
  return metastatementNatches;
49
62
  }
50
63
 
51
- asString() {
52
- const string = labelsAsString(this.labels);
53
-
54
- return string;
64
+ toJSON(tokens) {
65
+ const lineIndex = lineIndexFromLabelsAndTokens(this.labels, tokens),
66
+ labelsJSON = this.labels.map((label) => {
67
+ const labelJSON = label.toJSON();
68
+
69
+ return labelJSON;
70
+ }),
71
+ premisesJSON = this.premises.map((premise) => {
72
+ const premiseJSON = premise.toJSON();
73
+
74
+ return premiseJSON;
75
+ }),
76
+ conclusionJSON = this.conclusion.toJSON(),
77
+ labels = labelsJSON, ///
78
+ premises = premisesJSON, ///
79
+ conclusion = conclusionJSON, ///
80
+ json = {
81
+ lineIndex,
82
+ labels,
83
+ premises,
84
+ conclusion
85
+ };
86
+
87
+ return json;
55
88
  }
56
89
 
57
- static fromPremisesConclusionAndLabels(premises, conclusion, labels) {
90
+ static fromLabelsPremisesAndConclusion(labels, premises, conclusion) {
58
91
  const rule = new Rule(labels, premises, conclusion);
59
92
 
60
93
  return rule;
package/src/type.js CHANGED
@@ -101,6 +101,20 @@ export default class Type {
101
101
  return string;
102
102
  }
103
103
 
104
+ toJSON() {
105
+ const superTypeJSON = (this.superType === null) ?
106
+ null :
107
+ this.superType.toJSON(),
108
+ name = this.name,
109
+ superType = superTypeJSON, ///
110
+ json = {
111
+ name,
112
+ superType
113
+ };
114
+
115
+ return json;
116
+ }
117
+
104
118
  static fromTypeName(typeName) {
105
119
  const name = typeName, ///
106
120
  superType = null,
@@ -37,9 +37,3 @@ export function nodesAsString(nodes) {
37
37
 
38
38
  return string;
39
39
  }
40
-
41
- export function labelsAsString(labels) {
42
- const labelsString = labels.join(COMMA);
43
-
44
- return labelsString;
45
- }
@@ -1,5 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ import { arrayUtilities } from "necessary";
4
+
5
+ const { first } = arrayUtilities;
6
+
7
+ export function lineIndexFromLabelsAndTokens(labels, tokens) {
8
+ const firstLabel = first(labels),
9
+ label = firstLabel, ///
10
+ node = label.getNode(),
11
+ leastLineIndex = leastLineIndexFromNodeAndTokens(node, tokens),
12
+ lineIndex = leastLineIndex; ///
13
+
14
+ return lineIndex;
15
+ }
16
+
3
17
  export function leastLineIndexFromNodeAndTokens(node, tokens) {
4
18
  let leastLineIndex = undefined; ///
5
19
 
@@ -2,13 +2,25 @@
2
2
 
3
3
  import verifyFile from "../verify/file";
4
4
 
5
- import { leftDifference } from "../utilities/array";
5
+ import { filePathUtilities } from "occam-file-system";
6
+
7
+ import { filter, leftDifference } from "../utilities/array";
8
+
9
+ const { isFilePathFlorenceFilePath } = filePathUtilities;
6
10
 
7
11
  export default function verifyFiles(releaseContext) {
8
12
  let filesVerified = false;
9
13
 
10
14
  const filePaths = releaseContext.getFilePaths();
11
15
 
16
+ filter(filePaths, (filePath) => {
17
+ const filePathFlorenceFilePath = isFilePathFlorenceFilePath(filePath);
18
+
19
+ if (filePathFlorenceFilePath) {
20
+ return true;
21
+ }
22
+ })
23
+
12
24
  for (;;) {
13
25
  const filePathsLength = filePaths.length;
14
26
 
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
 
3
+ import Label from "../label";
4
+
5
+ import { nodesAsString } from "../utilities/string";
3
6
  import { labelNameFromLabelNode } from "../utilities/query";
4
7
 
5
8
  export default function verifyLabel(labelNode, labels, fileContext) {
@@ -8,12 +11,15 @@ export default function verifyLabel(labelNode, labels, fileContext) {
8
11
  fileContext.begin(labelNode);
9
12
 
10
13
  const labelName = labelNameFromLabelNode(labelNode),
11
- label = labelName, ///
12
- labelPresent = fileContext.isLabelPresent(label);
14
+ labelPresent = fileContext.isLabelPresentByLabelName(labelName);
13
15
 
14
16
  if (labelPresent) {
15
- fileContext.error(`The label ${label} is already present`, labelNode);
17
+ const labelString = nodesAsString(labelNode);
18
+
19
+ fileContext.error(`The label ${labelString} is already present`, labelNode);
16
20
  } else {
21
+ const label = Label.fromLabelNode(labelNode);
22
+
17
23
  labels.push(label);
18
24
 
19
25
  labelVerified = true;
@@ -59,7 +59,7 @@ export default function verifyRule(ruleNode, fileContext) {
59
59
  }
60
60
 
61
61
  if (metaproofVerified) {
62
- const rule = Rule.fromPremisesConclusionAndLabels(premises, conclusion, labels);
62
+ const rule = Rule.fromLabelsPremisesAndConclusion(labels, premises, conclusion);
63
63
 
64
64
  fileContext.addRule(rule);
65
65