occam-verify-cli 0.0.1002 → 0.0.1005

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 (184) hide show
  1. package/README.md +0 -2
  2. package/bin/abbreviations.js +1 -3
  3. package/bin/action/help.js +0 -2
  4. package/bin/action/verify.js +4 -24
  5. package/bin/defaults.js +0 -2
  6. package/bin/main.js +3 -4
  7. package/bin/options.js +0 -2
  8. package/lib/assertion/subproof.js +106 -0
  9. package/lib/assignment/metavariable.js +2 -2
  10. package/lib/combinator.js +50 -16
  11. package/lib/conclusion.js +73 -14
  12. package/lib/context/file.js +191 -31
  13. package/lib/context/local.js +37 -49
  14. package/lib/context/release.js +42 -35
  15. package/lib/context/release.other.js +605 -0
  16. package/lib/declaration/combinator.js +83 -0
  17. package/lib/derivation.js +86 -0
  18. package/lib/equality.js +3 -11
  19. package/lib/index.js +1 -1
  20. package/lib/judgement.js +3 -10
  21. package/lib/label.js +58 -16
  22. package/lib/log.js +3 -11
  23. package/lib/metaType.js +31 -19
  24. package/lib/metavariable.js +39 -12
  25. package/lib/mixins/statement/qualified/unify.js +118 -0
  26. package/lib/mixins/statement/unify.js +57 -0
  27. package/lib/mixins/statement/verify.js +184 -0
  28. package/lib/node/statement/combinator/bracketed.js +15 -11
  29. package/lib/ocmbinator/bracketed.js +52 -8
  30. package/lib/premise.js +109 -56
  31. package/lib/proof.js +91 -0
  32. package/lib/proofStep.js +78 -25
  33. package/lib/reference.js +62 -16
  34. package/lib/rule.js +146 -26
  35. package/lib/ruleNames.js +5 -5
  36. package/lib/statement/qualified.js +127 -0
  37. package/lib/statement/unqualified.js +89 -0
  38. package/lib/statement.js +176 -0
  39. package/lib/subDerivation.js +86 -0
  40. package/lib/subproof.js +155 -0
  41. package/lib/substitution/frameForMetavariable.js +14 -15
  42. package/lib/substitution/statementForMetavariable.js +23 -24
  43. package/lib/substitution/termForVariable.js +11 -12
  44. package/lib/substitution.js +9 -2
  45. package/lib/substitutions.js +14 -14
  46. package/lib/supposition.js +92 -60
  47. package/lib/unifier/statementWithCombinator.js +3 -3
  48. package/lib/unify/metavariableWithFrame.js +2 -2
  49. package/lib/unify/metavariableWithStatement.js +2 -2
  50. package/lib/unify/metavariableWithStatementGivenSubstitution.js +2 -2
  51. package/lib/unify/variableWithTerm.js +2 -2
  52. package/lib/utilities/node.js +13 -11
  53. package/lib/utilities/releaseContext.js +3 -3
  54. package/lib/utilities/string.js +8 -2
  55. package/lib/utilities/subproof.js +5 -5
  56. package/lib/utilities/tokens.js +10 -10
  57. package/lib/variable.js +1 -10
  58. package/lib/verifier/metaLevel.js +2 -2
  59. package/lib/verifier/topLevel.js +5 -5
  60. package/lib/verify/axiom.js +3 -5
  61. package/lib/verify/conjecture.js +4 -7
  62. package/lib/verify/consequent.js +2 -3
  63. package/lib/verify/declaration/combinator.js +2 -14
  64. package/lib/verify/declaration/metavariable.js +9 -10
  65. package/lib/verify/files.js +4 -4
  66. package/lib/verify/frame.js +12 -12
  67. package/lib/verify/lemma.js +4 -7
  68. package/lib/verify/metaLemma.js +4 -7
  69. package/lib/verify/metatheorem.js +4 -7
  70. package/lib/verify/proofStep.js +2 -31
  71. package/lib/verify/theorem.js +4 -7
  72. package/package.json +4 -4
  73. package/src/assertion/subproof.js +84 -0
  74. package/src/assignment/metavariable.js +2 -2
  75. package/src/combinator.js +45 -15
  76. package/src/conclusion.js +83 -13
  77. package/src/context/file.js +223 -11
  78. package/src/context/local.js +12 -16
  79. package/src/context/release.js +57 -39
  80. package/src/context/release.other.js +547 -0
  81. package/src/declaration/combinator.js +44 -0
  82. package/src/derivation.js +50 -0
  83. package/src/equality.js +2 -9
  84. package/src/index.js +0 -1
  85. package/src/judgement.js +2 -8
  86. package/src/label.js +56 -13
  87. package/src/log.js +2 -9
  88. package/src/metaType.js +26 -14
  89. package/src/metavariable.js +57 -9
  90. package/src/mixins/statement/qualified/unify.js +186 -0
  91. package/src/mixins/statement/unify.js +70 -0
  92. package/src/mixins/statement/verify.js +274 -0
  93. package/src/node/statement/combinator/bracketed.js +4 -3
  94. package/src/ocmbinator/bracketed.js +15 -12
  95. package/src/premise.js +136 -44
  96. package/src/proof.js +58 -0
  97. package/src/proofStep.js +92 -22
  98. package/src/reference.js +58 -12
  99. package/src/rule.js +199 -30
  100. package/src/ruleNames.js +1 -1
  101. package/src/statement/qualified.js +104 -0
  102. package/src/statement/unqualified.js +60 -0
  103. package/src/statement.js +179 -0
  104. package/src/subDerivation.js +52 -0
  105. package/src/subproof.js +99 -0
  106. package/src/substitution/frameForMetavariable.js +20 -17
  107. package/src/substitution/statementForMetavariable.js +31 -29
  108. package/src/substitution/termForVariable.js +15 -14
  109. package/src/substitution.js +8 -0
  110. package/src/substitutions.js +12 -13
  111. package/src/supposition.js +94 -44
  112. package/src/unifier/statementWithCombinator.js +6 -3
  113. package/src/unify/metavariableWithFrame.js +1 -1
  114. package/src/unify/metavariableWithStatement.js +1 -1
  115. package/src/unify/metavariableWithStatementGivenSubstitution.js +1 -1
  116. package/src/unify/variableWithTerm.js +1 -1
  117. package/src/utilities/node.js +18 -12
  118. package/src/utilities/releaseContext.js +2 -2
  119. package/src/utilities/string.js +6 -2
  120. package/src/utilities/subproof.js +2 -2
  121. package/src/utilities/tokens.js +7 -7
  122. package/src/variable.js +0 -10
  123. package/src/verifier/metaLevel.js +3 -2
  124. package/src/verifier/topLevel.js +6 -4
  125. package/src/verify/axiom.js +1 -2
  126. package/src/verify/conjecture.js +2 -3
  127. package/src/verify/consequent.js +1 -1
  128. package/src/verify/declaration/combinator.js +0 -20
  129. package/src/verify/declaration/metavariable.js +8 -12
  130. package/src/verify/files.js +3 -3
  131. package/src/verify/frame.js +11 -11
  132. package/src/verify/lemma.js +2 -3
  133. package/src/verify/metaLemma.js +2 -3
  134. package/src/verify/metatheorem.js +2 -3
  135. package/src/verify/proofStep.js +0 -41
  136. package/src/verify/theorem.js +2 -3
  137. package/lib/tokens/combinatorStatement/bracketed.js +0 -17
  138. package/lib/unify/premiseWithProofStep.js +0 -41
  139. package/lib/unify/premisesWithProofSteps.js +0 -31
  140. package/lib/unify/qualifiedStatement.js +0 -136
  141. package/lib/unify/statementWithBracketedCombinator.js +0 -30
  142. package/lib/unify/statementWithCombinator.js +0 -29
  143. package/lib/unify/statementWithCombinators.js +0 -31
  144. package/lib/unify/statementWithMetaType.js +0 -24
  145. package/lib/verify/conclusion.js +0 -39
  146. package/lib/verify/derivation.js +0 -31
  147. package/lib/verify/label.js +0 -37
  148. package/lib/verify/labels.js +0 -28
  149. package/lib/verify/premise.js +0 -45
  150. package/lib/verify/premises.js +0 -28
  151. package/lib/verify/proof.js +0 -34
  152. package/lib/verify/rule.js +0 -56
  153. package/lib/verify/statement/qualified.js +0 -41
  154. package/lib/verify/statement/unqualified.js +0 -45
  155. package/lib/verify/statement.js +0 -219
  156. package/lib/verify/statementAsCombinator.js +0 -33
  157. package/lib/verify/statementGivenMetaType.js +0 -52
  158. package/lib/verify/subproof.js +0 -34
  159. package/lib/verify/supposition.js +0 -45
  160. package/lib/verify/suppositions.js +0 -28
  161. package/src/tokens/combinatorStatement/bracketed.js +0 -10
  162. package/src/unify/premiseWithProofStep.js +0 -54
  163. package/src/unify/premisesWithProofSteps.js +0 -23
  164. package/src/unify/qualifiedStatement.js +0 -208
  165. package/src/unify/statementWithBracketedCombinator.js +0 -22
  166. package/src/unify/statementWithCombinator.js +0 -22
  167. package/src/unify/statementWithCombinators.js +0 -23
  168. package/src/unify/statementWithMetaType.js +0 -14
  169. package/src/verify/conclusion.js +0 -40
  170. package/src/verify/derivation.js +0 -23
  171. package/src/verify/label.js +0 -34
  172. package/src/verify/labels.js +0 -17
  173. package/src/verify/premise.js +0 -49
  174. package/src/verify/premises.js +0 -17
  175. package/src/verify/proof.js +0 -31
  176. package/src/verify/rule.js +0 -71
  177. package/src/verify/statement/qualified.js +0 -40
  178. package/src/verify/statement/unqualified.js +0 -49
  179. package/src/verify/statement.js +0 -312
  180. package/src/verify/statementAsCombinator.js +0 -27
  181. package/src/verify/statementGivenMetaType.js +0 -52
  182. package/src/verify/subproof.js +0 -32
  183. package/src/verify/supposition.js +0 -49
  184. package/src/verify/suppositions.js +0 -17
package/src/proofStep.js CHANGED
@@ -1,45 +1,115 @@
1
1
  "use strict";
2
2
 
3
- import unifyStatementWithStatementGivenEquivalences from "./unify/statementWithSttaemetnGivenEquivalences";
3
+ import shim from "./shim";
4
+ import Subproof from "./subproof";
5
+ import QualifiedStatement from "./statement/qualified";
6
+ import UnqualifiedStatement from "./statement/unqualified";
4
7
 
5
- export default class ProofStep {
6
- constructor(subproofNode, statementNode) {
7
- this.subproofNode = subproofNode;
8
- this.statementNode = statementNode;
8
+ import { nodeQuery } from "./utilities/query";
9
+
10
+ const subproofNodeQuery = nodeQuery("/proofStep|lastProofStep/subproof"),
11
+ qualifiedStatementNodeQuery = nodeQuery("/proofStep|lastProofStep/qualifiedStatement"),
12
+ unqualifiedStatementNodeQuery = nodeQuery("/proofStep|lastProofStep/unqualifiedStatement");
13
+
14
+ class ProofStep {
15
+ constructor(subproof, qualifiedStatement, unqualifiedStatement) {
16
+ this.subproof = subproof;
17
+ this.qualifiedStatement = qualifiedStatement;
18
+ this.unqualifiedStatement = unqualifiedStatement;
9
19
  }
10
20
 
11
- getSubproofNode() {
12
- return this.subproofNode;
21
+ getSubproof() {
22
+ return this.subproof;
13
23
  }
14
24
 
15
- getStatementNode() {
16
- return this.statementNode;
25
+ getQualifiedStatement() {
26
+ return this.qualifiedStatement;
17
27
  }
18
28
 
19
- unifyStatement(statementNodeB, equivalences, localContextA, localContextB) {
20
- let statementUnified = false;
29
+ getUnqualifiedStatement() {
30
+ return this.unqualifiedStatement;
31
+ }
21
32
 
22
- if (this.statementNode !== null) {
23
- const statementNodeA = this.statementNode, ///
24
- statementUnifiedWithStatement = unifyStatementWithStatementGivenEquivalences(statementNodeA, statementNodeB, equivalences, localContextA, localContextB);
33
+ getStatement() {
34
+ let statement = null;
35
+
36
+ if (this.qualifiedStatement !== null) {
37
+ statement = this.qualifiedStatement.getStatement();
38
+ }
25
39
 
26
- statementUnified = statementUnifiedWithStatement; ///
40
+ if (this.unqualifiedStatement !== null) {
41
+ statement = this.unqualifiedStatement.getStatement();
27
42
  }
28
43
 
29
- return statementUnified;
44
+ return statement;
30
45
  }
31
46
 
32
- static fromSubproofNode(subproofNode) {
33
- const statementNode = null,
34
- proofStep = new ProofStep(subproofNode, statementNode);
47
+ // unifyStatement(statementB, equivalences, localContextA, localContextB) {
48
+ // let statementUnified = false;
49
+ //
50
+ // if (this.statement !== null) {
51
+ // const statementA = this.statement, ///
52
+ // statementUnifiedWithStatement = unifyStatementWithStatementGivenEquivalences(statementA, statementB, equivalences, localContextA, localContextB);
53
+ //
54
+ // statementUnified = statementUnifiedWithStatement; ///
55
+ // }
56
+ //
57
+ // return statementUnified;
58
+ // }
59
+
60
+ verify(substitutions, localContext) {
61
+ let verified = false;
62
+
63
+ if (false) {
64
+ ///
65
+ } else if (this.subproof !== null) {
66
+ const subproofVerified = this.subproof.verify(substitutions, localContext);
67
+
68
+ verified = subproofVerified; ///
69
+ } else if (this.qualifiedStatement !== null) {
70
+ const qualifiedStatementVerified = this.qualifiedStatement.verify(substitutions, localContext);
71
+
72
+ verified = qualifiedStatementVerified; ///
73
+ } else if (this.unqualifiedStatement !== null) {
74
+ const stated = true,
75
+ assignments = [],
76
+ unqualifiedStatementVerified = this.unqualifiedStatement.verify(stated, assignments, localContext);
77
+
78
+ verified = unqualifiedStatementVerified; ///
79
+ }
80
+
81
+ if (verified) {
82
+ const proofStep = this; ///
83
+
84
+ localContext.addProofStep(proofStep);
85
+ }
86
+
87
+ return verified;
88
+ }
89
+
90
+ static fromProofStepNode(proofStepNode, fileContext) {
91
+ const subproofNode = subproofNodeQuery(proofStepNode),
92
+ qualifiedStatementNode = qualifiedStatementNodeQuery(proofStepNode),
93
+ unqualifiedStatementNode = unqualifiedStatementNodeQuery(proofStepNode),
94
+ subproof = Subproof.fromSubproofNode(subproofNode, fileContext),
95
+ qualifiedStatement = QualifiedStatement.fromQualifiedStatementNode(qualifiedStatementNode, fileContext),
96
+ unqualifiedStatement = UnqualifiedStatement.fromUnqualifiedStatementNode(unqualifiedStatementNode, fileContext),
97
+ proofStep = new ProofStep(subproof, qualifiedStatement, unqualifiedStatement);
35
98
 
36
99
  return proofStep;
37
100
  }
38
101
 
39
- static fromStatementNode(statementNode) {
40
- const subproofNode = null,
41
- proofStep = new ProofStep(subproofNode, statementNode);
102
+ static fromUnqualifiedStatement(unqualifiedStatement) {
103
+ const subproof = null,
104
+ qualifiedStatement = null,
105
+ proofStep = new ProofStep(subproof, qualifiedStatement, unqualifiedStatement);
42
106
 
43
107
  return proofStep;
44
108
  }
45
109
  }
110
+
111
+ Object.assign(shim, {
112
+ ProofStep
113
+ });
114
+
115
+ export default ProofStep;
package/src/reference.js CHANGED
@@ -1,30 +1,76 @@
1
1
  "use strict";
2
2
 
3
- import { nodeAsString } from "./utilities/string";
3
+ import Metavariable from "./metavariable";
4
+
5
+ import { nodeQuery } from "./utilities/query";
6
+
7
+ const metavariableNodeQuery = nodeQuery("//reference/metavariable");
4
8
 
5
9
  export default class Reference {
6
- constructor(metavariableNode) {
7
- this.metavariableNode = metavariableNode;
10
+ constructor(metavariable) {
11
+ this.metavariable = metavariable;
8
12
  }
9
13
 
14
+ getMetavariable() {
15
+ return this.metavariable;
16
+ }
17
+
18
+ getString() { return this.metavariable.getString(); }
19
+
20
+ matchMetavariableNode(metavariableNode) { return this.metavariable.matchMetavariableNode(metavariableNode); }
21
+
10
22
  getMetavariableNode() {
11
- return this.metavariableNode;
23
+ const metavariableNode = this.metavariable.getNode();
24
+
25
+ return metavariableNode;
12
26
  }
13
27
 
14
- matchMetavariableNode(metavariableNode) {
15
- const metavariableNodeMatches = this.metavariableNode.match(metavariableNode);
28
+ verify(fileContext) {
29
+ let verified;
30
+
31
+ const referenceString = this.getString(); ///
32
+
33
+ fileContext.trace(`Verifying the '${referenceString}' reference...`);
34
+
35
+ verified = true;
16
36
 
17
- return metavariableNodeMatches;
37
+ if (verified) {
38
+ fileContext.debug(`...verified the '${referenceString}' reference.`);
39
+ }
40
+
41
+ return verified;
18
42
  }
19
43
 
20
- asString(tokens) {
21
- const string = nodeAsString(this.metavariableNode, tokens);
44
+ toJSON() {
45
+ const metavariableJSON = this.metavariable.toJSON(),
46
+ metavariable = metavariableJSON, ///
47
+ string = this.string,
48
+ json = {
49
+ string,
50
+ metavariable
51
+ };
52
+
53
+ return json;
54
+ }
55
+
56
+ static fromJSON(json, fileContext) {
57
+ const { string } = json;
58
+
59
+ let { metavariable } = json;
22
60
 
23
- return string;
61
+ json = metavariable; ///
62
+
63
+ metavariable = Metavariable.fromJSON(json, fileContext);
64
+
65
+ const reference = new Reference(string, metavariable);
66
+
67
+ return reference;
24
68
  }
25
69
 
26
- static fromMetavariableNode(metavariableNode) {
27
- const reference = new Reference(metavariableNode);
70
+ static fromReferenceNode(referenceNode, fileContext) {
71
+ const metavariableNode = metavariableNodeQuery(referenceNode),
72
+ metavariable = Metavariable.fromMetavariableNode(metavariableNode, fileContext),
73
+ reference = new Reference(metavariable);
28
74
 
29
75
  return reference;
30
76
  }
package/src/rule.js CHANGED
@@ -1,16 +1,31 @@
1
1
  "use strict";
2
2
 
3
+ import Label from "./label";
4
+ import Proof from "./proof";
5
+ import Premise from "./premise";
6
+ import Conclusion from "./conclusion";
7
+ import LocalContext from "./context/local";
3
8
  import Substitutions from "./substitutions";
4
- import resolveSubstitutions from "./resolve/substitutions";
5
- import unifyPremisesWithProofSteps from "./unify/premisesWithProofSteps";
6
- import unifyConclusionWithStatement from "./unify/conclusionWithStatement";
9
+
10
+ import { reverse, correlate } from "./utilities/array";
11
+ import { nodeQuery, nodesQuery } from "./utilities/query";
12
+
13
+ const proofNodeQuery = nodeQuery("/rule/proof"),
14
+ labelNodesQuery = nodesQuery("/rule/label"),
15
+ premiseNodesQuery = nodesQuery("/rule/premise"),
16
+ conclusionNodeQuery = nodeQuery("/rule/conclusion");
7
17
 
8
18
  export default class Rule {
9
- constructor(labels, premises, conclusion, fileContext) {
19
+ constructor(fileContext, labels, premises, conclusion, proof) {
20
+ this.fileContext = fileContext;
10
21
  this.labels = labels;
11
22
  this.premises = premises;
12
23
  this.conclusion = conclusion;
13
- this.fileContext = fileContext;
24
+ this.proof = proof;
25
+ }
26
+
27
+ getFileContext() {
28
+ return this.fileContext;
14
29
  }
15
30
 
16
31
  getLabels() {
@@ -25,50 +40,204 @@ export default class Rule {
25
40
  return this.conclusion;
26
41
  }
27
42
 
28
- getFileContext() {
29
- return this.fileContext;
43
+ getProof() {
44
+ return this.proof;
30
45
  }
31
46
 
32
- unifyStatement(statementNode, localContext) {
33
- let statementUnified = false;
47
+ matchMetavariableNode(metavariableNode) {
48
+ const metavariableNodeMatches = this.labels.some((label) => {
49
+ const metavariableNodeMatches = label.matchMetavariableNode(metavariableNode);
50
+
51
+ if (metavariableNodeMatches) {
52
+ return true;
53
+ }
54
+ });
34
55
 
35
- const substitutions = Substitutions.fromNothing(),
36
- proofSteps = localContext.getProofSteps(),
37
- premisesA = this.premises,
38
- proofStepsB = proofSteps, ///
39
- fileContextA = this.fileContext, ///
40
- localContextB = localContext, ///
41
- premisesUnified = unifyPremisesWithProofSteps(premisesA, proofStepsB, substitutions, fileContextA, localContextB);
56
+ return metavariableNodeMatches;
57
+ }
42
58
 
43
- if (premisesUnified) {
44
- const conclusionA = this.conclusion, ///
45
- conclusionUnified = unifyConclusionWithStatement(conclusionA, statementNode, substitutions, fileContextA, localContextB);
59
+ unifyStatement(statement, localContext) {
60
+ let statementUnified = false;
46
61
 
47
- if (conclusionUnified) {
48
- const substitutionsResolved = resolveSubstitutions(substitutions, fileContextA, localContextB);
62
+ const proofSteps = localContext.getProofSteps(),
63
+ substitutions = Substitutions.fromNothing(),
64
+ proofStepsUnified = this.unifyProofSteps(proofSteps, substitutions, localContext);
49
65
 
50
- statementUnified = substitutionsResolved; ///
51
- }
66
+ if (proofStepsUnified) {
67
+ statementUnified = this.conclusion.unifyStatement(statement, substitutions, localContext);
52
68
  }
53
69
 
54
70
  return statementUnified;
55
71
  }
56
72
 
57
- matchMetavariableNode(metavariableNode) {
58
- const metavariableNodeMatches = this.labels.some((label) => {
59
- const metavariableNodeMatches = label.matchMetavariableNode(metavariableNode);
73
+ unifyProofSteps(proofSteps, substitutions, localContext) {
74
+ let proofStepsUnified;
60
75
 
61
- if (metavariableNodeMatches) {
76
+ let premises = this.premises;
77
+
78
+ premises = reverse(premises); ///
79
+
80
+ proofSteps = reverse(proofSteps); ///
81
+
82
+ proofStepsUnified = correlate(premises, proofSteps, (premise, proofStep) => {
83
+ const proofStepUnified = premise.unifyProofStep(proofStep, substitutions, localContext);
84
+
85
+ if (proofStepUnified) {
62
86
  return true;
63
87
  }
64
88
  });
65
89
 
66
- return metavariableNodeMatches;
90
+ return proofStepsUnified;
91
+ }
92
+
93
+ verify(fileContext) {
94
+ let verified = false;
95
+
96
+ const labelsString = labelsStringFromLabels(this.labels);
97
+
98
+ fileContext.trace(`Verifying the '${labelsString}' rule...`);
99
+
100
+ const labelsVerified = this.labels.every((label) => {
101
+ const labelVVerified = label.verify(fileContext);
102
+
103
+ if (labelVVerified) {
104
+ return true;
105
+ }
106
+ });
107
+
108
+ if (labelsVerified) {
109
+ const localContext = LocalContext.fromFileContext(fileContext),
110
+ premisesVerified = this.premises.every((premise) => {
111
+ const premiseVerified = premise.verify(localContext);
112
+
113
+ if (premiseVerified) {
114
+ return true;
115
+ }
116
+ });
117
+
118
+ if (premisesVerified) {
119
+ const conclusionVerified = this.conclusion.verify(localContext);
120
+
121
+ if (conclusionVerified) {
122
+ let proofVerified = true; ///
123
+
124
+ if (this.proof !== null) {
125
+ const substitutions = Substitutions.fromNothing();
126
+
127
+ proofVerified = this.proof.verify(substitutions, this.conclusion, localContext);
128
+ }
129
+
130
+ if (proofVerified) {
131
+ const rule = this; ///
132
+
133
+ fileContext.addRule(rule);
134
+
135
+ verified = true;
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ if (verified) {
142
+ fileContext.debug(`...verified the '${labelsString}' rule.`);
143
+ }
144
+
145
+ return verified;
146
+ }
147
+
148
+ toJSON() {
149
+ const labelsJSON = this.labels.map((label) => {
150
+ const labelJSON = label.toJSON();
151
+
152
+ return labelJSON;
153
+ }),
154
+ premisesJSON = this.premises.map((premise) => {
155
+ const premiseJSON = premise.toJSON();
156
+
157
+ return premiseJSON;
158
+ }),
159
+ conclusionJSON = this.conclusion.toJSON(),
160
+ labels = labelsJSON, ///
161
+ premises = premisesJSON, ///
162
+ conclusion = conclusionJSON, ///
163
+ json = {
164
+ labels,
165
+ premises,
166
+ conclusion
167
+ };
168
+
169
+ return json;
170
+ }
171
+
172
+ static fromJSON(json, fileContext) {
173
+ let rule;
174
+
175
+ let { labels } = json;
176
+
177
+ const labelsJSON = labels; ///
178
+
179
+ labels = labelsJSON.map((labelJSON) => {
180
+ const json = labelJSON, ///
181
+ label = Label.fromJSON(json, fileContext);
182
+
183
+ return label;
184
+ });
185
+
186
+ let { premises } = json;
187
+
188
+ const premisesJSON = premises; ///
189
+
190
+ premises = premisesJSON.map((premiseJSON) => {
191
+ const json = premiseJSON, ///
192
+ premise = Premise.fromJSON(json, fileContext);
193
+
194
+ return premise;
195
+ });
196
+
197
+ let { conclusion } = json;
198
+
199
+ const conclusionJSON = conclusion; ///
200
+
201
+ json = conclusionJSON; ///
202
+
203
+ conclusion = Conclusion.fromJSON(json, fileContext);
204
+
205
+ const proof = null;
206
+
207
+ rule = new Rule(fileContext, labels, premises, conclusion, proof);
208
+
209
+ return rule;
67
210
  }
68
211
 
69
- static fromLabelsPremisesConclusionAndFileContext(labels, premises, conclusion, fileContext) {
70
- const rule = new Rule(labels, premises, conclusion, fileContext);
212
+ static fromRuleNode(ruleNode, fileContext) {
213
+ const proofNode = proofNodeQuery(ruleNode),
214
+ labelNodes = labelNodesQuery(ruleNode),
215
+ premiseNodes = premiseNodesQuery(ruleNode),
216
+ conclusionNode = conclusionNodeQuery(ruleNode),
217
+ labels = labelNodes.map((labelNode) => {
218
+ const label = Label.fromLabelNode(labelNode, fileContext);
219
+
220
+ return label;
221
+ }),
222
+ premises = premiseNodes.map((premiseNode) => {
223
+ const premise = Premise.fromPremiseNode(premiseNode, fileContext);
224
+
225
+ return premise;
226
+ }),
227
+ conclusion = Conclusion.fromConclusionNode(conclusionNode, fileContext),
228
+ proof = Proof.fromProofNode(proofNode, fileContext),
229
+ rule = new Rule(fileContext, labels, premises, conclusion, proof);
71
230
 
72
231
  return rule;
73
232
  }
74
233
  }
234
+
235
+ function labelsStringFromLabels(labels) {
236
+ const labelsString = labels.map((label) => {
237
+ const labelString = label.getString();
238
+
239
+ return labelString;
240
+ });
241
+
242
+ return labelsString;
243
+ }
package/src/ruleNames.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
 
3
3
  export const TERM_RULE_NAME = "term";
4
- export const STATEMENT_RULE_NAME = "statement";
4
+ export const UNQUALIFIED_STATEMENT_RULE_NAME = "unqualifiedStatement";
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ import Statement from "../statement";
4
+ import Reference from "../reference";
5
+ import unifyMixins from "../mixins/statement/qualified/unify";
6
+ import LocalContext from "../context/local";
7
+
8
+ import { trim } from "../utilities/string";
9
+ import { nodeQuery } from "../utilities/query";
10
+ import { assignAssignments } from "../utilities/assignments";
11
+
12
+ const statementNodeQuery = nodeQuery("/qualifiedStatement/statement"),
13
+ referenceNodeQuery = nodeQuery("/qualifiedStatement/reference");
14
+
15
+ export default class QualifiedStatement {
16
+ constructor(string, statement, reference) {
17
+ this.string = string;
18
+ this.statement = statement;
19
+ this.reference = reference;
20
+ }
21
+
22
+ getString() {
23
+ return this.string;
24
+ }
25
+
26
+ getStatement() {
27
+ return this.statement;
28
+ }
29
+
30
+ getReference() {
31
+ return this.reference;
32
+ }
33
+
34
+ getMetavariableNode() { return this.reference.getMetavariableNode(); }
35
+
36
+ verify(substitutions, localContext) {
37
+ let verified;
38
+
39
+ const qualifiedStatementString = trim(this.string); ///
40
+
41
+ localContext.trace(`Verifying the '${qualifiedStatementString}' qualified statement...`);
42
+
43
+ const stated = true,
44
+ assignments = [],
45
+ statementVerified = this.statement.verify(assignments, stated, localContext);
46
+
47
+ if (statementVerified) {
48
+ const unified = this.unify(substitutions, localContext);
49
+
50
+ if (unified) {
51
+ const assignmentsAssigned = assignAssignments(assignments, localContext);
52
+
53
+ verified = assignmentsAssigned; ///
54
+ }
55
+ }
56
+
57
+ if (verified) {
58
+ localContext.debug(`...verified the '${qualifiedStatementString}' qualified statement.`);
59
+ }
60
+
61
+ return verified;
62
+ }
63
+
64
+ unify(substitutions, localContext) {
65
+ let unified;
66
+
67
+ const qualifiedStatement = this, ///
68
+ qualifiedStatementString = trim(this.string); ///
69
+
70
+ localContext.trace(`Unifying the '${qualifiedStatementString}' qualified statement...`);
71
+
72
+ unified = unifyMixins.some((unifyMixin) => {
73
+ const unified = unifyMixin(qualifiedStatement, substitutions, localContext);
74
+
75
+ return unified;
76
+ });
77
+
78
+ if (unified) {
79
+ localContext.debug(`...unified the '${qualifiedStatementString}' qualified statement.`);
80
+ }
81
+
82
+ return unified;
83
+ }
84
+
85
+ static fromQualifiedStatementNode(qualifiedStatementNode, fileContext) {
86
+ let qualifiedStatement = null;
87
+
88
+ if (qualifiedStatementNode !== null) {
89
+ const statementNode = statementNodeQuery(qualifiedStatementNode),
90
+ referenceNode = referenceNodeQuery(qualifiedStatementNode),
91
+ localContext = LocalContext.fromFileContext(fileContext),
92
+ statement = (statementNode !== null) ?
93
+ Statement.fromStatementNode(statementNode, localContext) :
94
+ null,
95
+ reference = Reference.fromReferenceNode(referenceNode, fileContext),
96
+ node = qualifiedStatementNode, ///
97
+ string = fileContext.nodeAsString(node);
98
+
99
+ qualifiedStatement = new QualifiedStatement(string, statement, reference);
100
+ }
101
+
102
+ return qualifiedStatement;
103
+ }
104
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ import Statement from "../statement";
4
+ import LocalContext from "../context/local";
5
+
6
+ import { trim } from "../utilities/string";
7
+ import { nodeQuery } from "../utilities/query";
8
+
9
+ const statementNodeQuery = nodeQuery("/unqualifiedStatement/statement");
10
+
11
+ export default class UnqualifiedStatement {
12
+ constructor(string, statement) {
13
+ this.string = string;
14
+ this.statement = statement;
15
+ }
16
+
17
+ getString() {
18
+ return this.string;
19
+ }
20
+
21
+ getStatement() {
22
+ return this.statement;
23
+ }
24
+
25
+ verify(assignments, stated, localContext) {
26
+ let verified;
27
+
28
+ const unqualifiedStatementString = trim(this.string); ///
29
+
30
+ localContext.trace(`Verifying the '${unqualifiedStatementString}' unqualified statement...`);
31
+
32
+ const statementVerified = this.statement.verify(assignments, stated, localContext);
33
+
34
+ verified = statementVerified; ///
35
+
36
+ if (verified) {
37
+ localContext.debug(`...verified the '${unqualifiedStatementString}' unqualified statement.`);
38
+ }
39
+
40
+ return verified;
41
+ }
42
+
43
+ static fromUnqualifiedStatementNode(unqualifiedStatementNode, fileContext) {
44
+ let unqualifiedStatement = null;
45
+
46
+ if (unqualifiedStatementNode !== null) {
47
+ const statementNode = statementNodeQuery(unqualifiedStatementNode),
48
+ localContext = LocalContext.fromFileContext(fileContext),
49
+ statement = (statementNode !== null) ?
50
+ Statement.fromStatementNode(statementNode, localContext) :
51
+ null,
52
+ node = unqualifiedStatementNode, ///
53
+ string = fileContext.nodeAsString(node);
54
+
55
+ unqualifiedStatement = new UnqualifiedStatement(string, statement);
56
+ }
57
+
58
+ return unqualifiedStatement;
59
+ }
60
+ }