occam-verify-cli 1.0.448 → 1.0.472

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 (222) hide show
  1. package/lib/constants.js +13 -5
  2. package/lib/context/ephemeral.js +270 -0
  3. package/lib/context/file.js +136 -128
  4. package/lib/context/liminal.js +120 -0
  5. package/lib/context/literal.js +92 -0
  6. package/lib/context/nominal.js +15 -1
  7. package/lib/context/release.js +68 -9
  8. package/lib/context/scoped.js +322 -0
  9. package/lib/context/synthetic.js +133 -0
  10. package/lib/element/assertion/contained.js +66 -66
  11. package/lib/element/assertion/defined.js +32 -32
  12. package/lib/element/assertion/property.js +39 -39
  13. package/lib/element/assertion/satisfies.js +22 -22
  14. package/lib/element/assumption.js +71 -87
  15. package/lib/element/combinator/bracketed.js +1 -10
  16. package/lib/element/conclusion.js +19 -15
  17. package/lib/element/constructor/bracketed.js +1 -10
  18. package/lib/element/constructor.js +2 -2
  19. package/lib/element/declaration/combinator.js +1 -2
  20. package/lib/element/declaration/metavariable.js +3 -3
  21. package/lib/element/declaration/variable.js +3 -3
  22. package/lib/element/deduction.js +26 -20
  23. package/lib/element/derivation.js +3 -3
  24. package/lib/element/equality.js +5 -5
  25. package/lib/element/equivalence.js +112 -107
  26. package/lib/element/equivalences.js +24 -10
  27. package/lib/element/error.js +3 -3
  28. package/lib/element/frame.js +73 -62
  29. package/lib/element/hypothesis.js +2 -2
  30. package/lib/element/judgement.js +40 -60
  31. package/lib/element/metaType.js +4 -4
  32. package/lib/element/metavariable.js +49 -38
  33. package/lib/element/parameter.js +13 -5
  34. package/lib/element/procedureCall.js +16 -16
  35. package/lib/element/proof.js +14 -13
  36. package/lib/element/proofAssertion/premise.js +319 -0
  37. package/lib/element/proofAssertion/step.js +309 -0
  38. package/lib/element/proofAssertion/supposition.js +333 -0
  39. package/lib/element/proofAssertion.js +20 -10
  40. package/lib/element/propertyRelation.js +2 -2
  41. package/lib/element/reference.js +72 -30
  42. package/lib/element/rule.js +26 -28
  43. package/lib/element/section.js +5 -5
  44. package/lib/element/signature.js +9 -6
  45. package/lib/element/statement.js +44 -36
  46. package/lib/element/subproof.js +18 -17
  47. package/lib/element/substitution/frame.js +86 -49
  48. package/lib/element/substitution/reference.js +101 -19
  49. package/lib/element/substitution/statement.js +128 -105
  50. package/lib/element/substitution/term.js +93 -57
  51. package/lib/element/substitution.js +20 -69
  52. package/lib/element/substitutions.js +49 -34
  53. package/lib/element/term.js +41 -30
  54. package/lib/element/topLevelAssertion/axiom.js +331 -0
  55. package/lib/element/{conjecture.js → topLevelAssertion/conjecture.js} +10 -10
  56. package/lib/element/{lemma.js → topLevelAssertion/lemma.js} +9 -9
  57. package/lib/element/{theorem.js → topLevelAssertion/theorem.js} +8 -8
  58. package/lib/element/topLevelAssertion.js +434 -0
  59. package/lib/element/{metaLemma.js → topLevelMetaAssertion/metaLemma.js} +8 -8
  60. package/lib/element/{metatheorem.js → topLevelMetaAssertion/metatheorem.js} +8 -8
  61. package/lib/element/topLevelMetaAssertion.js +293 -0
  62. package/lib/element/type.js +4 -4
  63. package/lib/element/variable.js +48 -40
  64. package/lib/index.js +3 -3
  65. package/lib/main.js +3 -3
  66. package/lib/metaTypes.js +18 -15
  67. package/lib/node/frame.js +2 -2
  68. package/lib/node/metavariable.js +4 -4
  69. package/lib/node/parameter.js +28 -7
  70. package/lib/node/proofAssertion/premise.js +116 -0
  71. package/lib/node/proofAssertion/step.js +152 -0
  72. package/lib/node/proofAssertion/supposition.js +116 -0
  73. package/lib/node/{premise.js → proofAssertion.js} +11 -18
  74. package/lib/node/statement.js +2 -2
  75. package/lib/node/substitution/frame.js +9 -31
  76. package/lib/node/substitution/reference.js +137 -0
  77. package/lib/node/substitution/statement.js +9 -31
  78. package/lib/node/substitution/term.js +9 -23
  79. package/lib/node/{axiom.js → topLevelAssertion/axiom.js} +7 -7
  80. package/lib/node/{conjecture.js → topLevelAssertion/conjecture.js} +7 -7
  81. package/lib/node/{lemma.js → topLevelAssertion/lemma.js} +7 -7
  82. package/lib/node/{theorem.js → topLevelAssertion/theorem.js} +7 -7
  83. package/lib/node/{axiomLemmaTheoremConjecture.js → topLevelAssertion.js} +9 -9
  84. package/lib/node/{metaLemma.js → topLevelMetaAssertion/metaLemma.js} +7 -7
  85. package/lib/node/{metatheorem.js → topLevelMetaAssertion/metatheorem.js} +7 -7
  86. package/lib/node/{metaLemmaMetaTheorem.js → topLevelMetaAssertion.js} +9 -9
  87. package/lib/nonTerminalNodeMap.js +15 -14
  88. package/lib/preamble.js +10 -10
  89. package/lib/process/instantiate.js +6 -21
  90. package/lib/process/unify.js +11 -10
  91. package/lib/tokenTypes.js +22 -0
  92. package/lib/types.js +3 -3
  93. package/lib/utilities/bnf.js +5 -5
  94. package/lib/utilities/context.js +63 -0
  95. package/lib/utilities/element.js +235 -408
  96. package/lib/utilities/instance.js +12 -34
  97. package/lib/utilities/json.js +3 -2
  98. package/lib/utilities/string.js +56 -21
  99. package/lib/utilities/unification.js +38 -32
  100. package/lib/utilities/validation.js +47 -50
  101. package/package.json +2 -2
  102. package/src/constants.js +12 -1
  103. package/src/context/ephemeral.js +257 -0
  104. package/src/context/file.js +108 -116
  105. package/src/context/liminal.js +67 -0
  106. package/src/context/literal.js +51 -0
  107. package/src/context/nominal.js +12 -0
  108. package/src/context/release.js +48 -8
  109. package/src/context/{local.js → scoped.js} +43 -125
  110. package/src/context/synthetic.js +60 -0
  111. package/src/element/assertion/contained.js +49 -47
  112. package/src/element/assertion/defined.js +29 -27
  113. package/src/element/assertion/property.js +35 -35
  114. package/src/element/assertion/satisfies.js +19 -18
  115. package/src/element/assumption.js +71 -93
  116. package/src/element/combinator/bracketed.js +0 -7
  117. package/src/element/conclusion.js +25 -24
  118. package/src/element/constructor/bracketed.js +0 -7
  119. package/src/element/constructor.js +1 -1
  120. package/src/element/declaration/combinator.js +0 -1
  121. package/src/element/declaration/metavariable.js +2 -2
  122. package/src/element/declaration/variable.js +5 -5
  123. package/src/element/deduction.js +33 -31
  124. package/src/element/derivation.js +2 -2
  125. package/src/element/equality.js +4 -4
  126. package/src/element/equivalence.js +115 -135
  127. package/src/element/equivalences.js +9 -7
  128. package/src/element/error.js +4 -2
  129. package/src/element/frame.js +80 -65
  130. package/src/element/hypothesis.js +1 -1
  131. package/src/element/judgement.js +42 -62
  132. package/src/element/metaType.js +3 -4
  133. package/src/element/metavariable.js +59 -56
  134. package/src/element/parameter.js +10 -5
  135. package/src/element/procedureCall.js +20 -18
  136. package/src/element/proof.js +14 -16
  137. package/src/element/{premise.js → proofAssertion/premise.js} +57 -53
  138. package/src/element/{step.js → proofAssertion/step.js} +59 -62
  139. package/src/element/{supposition.js → proofAssertion/supposition.js} +67 -56
  140. package/src/element/proofAssertion.js +24 -13
  141. package/src/element/propertyRelation.js +1 -1
  142. package/src/element/reference.js +87 -37
  143. package/src/element/rule.js +31 -37
  144. package/src/element/section.js +5 -5
  145. package/src/element/signature.js +8 -8
  146. package/src/element/statement.js +52 -48
  147. package/src/element/subproof.js +16 -18
  148. package/src/element/substitution/frame.js +104 -50
  149. package/src/element/substitution/reference.js +120 -20
  150. package/src/element/substitution/statement.js +169 -130
  151. package/src/element/substitution/term.js +104 -63
  152. package/src/element/substitution.js +16 -58
  153. package/src/element/substitutions.js +43 -41
  154. package/src/element/term.js +47 -41
  155. package/src/element/{axiom.js → topLevelAssertion/axiom.js} +22 -20
  156. package/src/element/{conjecture.js → topLevelAssertion/conjecture.js} +5 -6
  157. package/src/element/{lemma.js → topLevelAssertion/lemma.js} +5 -6
  158. package/src/element/{theorem.js → topLevelAssertion/theorem.js} +5 -5
  159. package/src/element/{axiomLemmaTheoremConjecture.js → topLevelAssertion.js} +37 -33
  160. package/src/element/{metaLemma.js → topLevelMetaAssertion/metaLemma.js} +5 -6
  161. package/src/element/{metatheorem.js → topLevelMetaAssertion/metatheorem.js} +5 -6
  162. package/src/element/{metaLemmaMetatheorem.js → topLevelMetaAssertion.js} +19 -17
  163. package/src/element/type.js +2 -4
  164. package/src/element/variable.js +47 -48
  165. package/src/index.js +2 -1
  166. package/src/main.js +2 -1
  167. package/src/metaTypes.js +25 -9
  168. package/src/node/frame.js +1 -1
  169. package/src/node/metavariable.js +3 -3
  170. package/src/node/parameter.js +32 -5
  171. package/src/node/proofAssertion/premise.js +16 -0
  172. package/src/node/{step.js → proofAssertion/step.js} +4 -18
  173. package/src/node/proofAssertion/supposition.js +16 -0
  174. package/src/node/proofAssertion.js +23 -0
  175. package/src/node/statement.js +1 -1
  176. package/src/node/substitution/frame.js +6 -32
  177. package/src/node/substitution/reference.js +38 -0
  178. package/src/node/substitution/statement.js +6 -32
  179. package/src/node/substitution/term.js +6 -22
  180. package/src/node/topLevelAssertion/axiom.js +13 -0
  181. package/src/node/topLevelAssertion/conjecture.js +13 -0
  182. package/src/node/topLevelAssertion/lemma.js +13 -0
  183. package/src/node/topLevelAssertion/theorem.js +13 -0
  184. package/src/node/{axiomLemmaTheoremConjecture.js → topLevelAssertion.js} +1 -1
  185. package/src/node/topLevelMetaAssertion/metaLemma.js +13 -0
  186. package/src/node/topLevelMetaAssertion/metatheorem.js +13 -0
  187. package/src/node/{metaLemmaMetaTheorem.js → topLevelMetaAssertion.js} +1 -1
  188. package/src/nonTerminalNodeMap.js +15 -12
  189. package/src/preamble.js +9 -9
  190. package/src/process/instantiate.js +27 -36
  191. package/src/process/unify.js +10 -9
  192. package/src/tokenTypes.js +4 -0
  193. package/src/types.js +4 -2
  194. package/src/utilities/bnf.js +3 -2
  195. package/src/utilities/context.js +46 -0
  196. package/src/utilities/element.js +302 -509
  197. package/src/utilities/instance.js +19 -42
  198. package/src/utilities/json.js +3 -1
  199. package/src/utilities/string.js +69 -28
  200. package/src/utilities/unification.js +41 -38
  201. package/src/utilities/validation.js +66 -75
  202. package/lib/context/local.js +0 -605
  203. package/lib/context/temporary.js +0 -752
  204. package/lib/element/axiom.js +0 -329
  205. package/lib/element/axiomLemmaTheoremConjecture.js +0 -427
  206. package/lib/element/metaLemmaMetatheorem.js +0 -289
  207. package/lib/element/premise.js +0 -307
  208. package/lib/element/step.js +0 -311
  209. package/lib/element/supposition.js +0 -320
  210. package/lib/log.js +0 -150
  211. package/lib/node/step.js +0 -166
  212. package/lib/node/supposition.js +0 -130
  213. package/src/context/temporary.js +0 -476
  214. package/src/log.js +0 -118
  215. package/src/node/axiom.js +0 -13
  216. package/src/node/conjecture.js +0 -13
  217. package/src/node/lemma.js +0 -13
  218. package/src/node/metaLemma.js +0 -13
  219. package/src/node/metatheorem.js +0 -13
  220. package/src/node/premise.js +0 -30
  221. package/src/node/supposition.js +0 -30
  222. package/src/node/theorem.js +0 -13
@@ -4,100 +4,190 @@ import elements from "../../elements";
4
4
  import Substitution from "../substitution";
5
5
 
6
6
  import { define } from "../../elements";
7
+ import { literally } from "../../utilities/context";
7
8
  import { unifySubstitution } from "../../process/unify";
8
9
  import { stripBracketsFromStatement } from "../../utilities/brackets";
9
10
  import { instantiateStatementSubstitution } from "../../process/instantiate";
10
11
  import { statementSubstitutionFromStatementSubstitutionNode } from "../../utilities/element";
11
- import { statementFromJSON, statementToStatementJSON, metavariableFromJSON, metavariableToMetavariableJSON } from "../../utilities/json";
12
+ import { statementToStatementJSON, metavariableToMetavariableJSON } from "../../utilities/json";
13
+ import { statementSubstitutionStringFromStatementAndMetavariable, statementSubstitutionStringFromStatementMetavariableAndSubstitution } from "../../utilities/string";
12
14
 
13
15
  export default define(class StatementSubstitution extends Substitution {
14
- constructor(context, string, node, resolved, statement, metavariable, substitution) {
16
+ constructor(context, string, node, resolved, substitution, targetStatement, replacementStatement) {
15
17
  super(context, string, node);
16
18
 
17
19
  this.resolved = resolved;
18
- this.statement = statement;
19
- this.metavariable = metavariable;
20
20
  this.substitution = substitution;
21
+ this.targetStatement = targetStatement;
22
+ this.replacementStatement = replacementStatement;
21
23
  }
22
24
 
23
25
  isResolved() {
24
26
  return this.resolved;
25
27
  }
26
28
 
27
- getStatement() {
28
- return this.statement;
29
+ getSubstitution() {
30
+ return this.substitution;
29
31
  }
30
32
 
31
- getMetavariable() {
32
- return this.metavariable;
33
+ getTargetStatement() {
34
+ return this.targetStatement;
33
35
  }
34
36
 
35
- getSubstitution() {
36
- return this.substitution;
37
+ getReplacementStatement() {
38
+ return this.replacementStatement;
39
+ }
40
+
41
+ getTargetNode() {
42
+ const targetStatementNode = this.targetStatement.getNode(),
43
+ targetNode = targetStatementNode; ///
44
+
45
+ return targetNode;
37
46
  }
38
47
 
39
48
  getReplacementNode() {
40
- const statementNode = this.statement.getNode(),
41
- replacementNode = statementNode; ///
49
+ const replacementStatementNode = this.replacementStatement.getNode(),
50
+ replacementNode = replacementStatementNode; ///
42
51
 
43
52
  return replacementNode;
44
53
  }
45
54
 
46
- setStatement(statement) {
47
- this.statement = statement;
55
+ isSimple() {
56
+ const simple = (this.substitution === null);
57
+
58
+ return simple;
48
59
  }
49
60
 
50
- setMetavariable(metavariable) {
51
- this.metavariable = metavariable;
61
+ compareStatement(statement, context) {
62
+ statement = stripBracketsFromStatement(statement, context); ///
63
+
64
+ const replacementStatementEqualToStatement = this.replacementStatement.isEqualTo(statement),
65
+ comparesToStatement = replacementStatementEqualToStatement; ///
66
+
67
+ return comparesToStatement;
52
68
  }
53
69
 
54
- setSubstitution(substitution) {
55
- this.substitution = substitution;
70
+ compareParameter(parameter) {
71
+ const targetStatementComparesToParameter = this.targetStatement.compareParameter(parameter),
72
+ comparesToParameter = targetStatementComparesToParameter; ///
73
+
74
+ return comparesToParameter;
56
75
  }
57
76
 
58
- isMetavariableEqualToMetavariable(metavariable) { return this.metavariable.isEqualTo(metavariable); }
77
+ compareSubstitution(substitution) {
78
+ let comparesToSubstitution = false;
59
79
 
60
- isSubstitutionEqualToSubstitution(substitution) {
61
- let substitutionEqualToSubstitution;
80
+ if (false) {
81
+ ///
82
+ } else if ((this.substitution === null) && (substitution === null)){
83
+ comparesToSubstitution = true;
84
+ } else if ((this.substitution !== null) && (substitution !== null)){
85
+ const substitutionEqualToSubstituion = this.substitution.isEqualTo(substitution);
62
86
 
63
- if (this.substitution === null) {
64
- substitutionEqualToSubstitution = (substitution === null);
65
- } else {
66
- if (substitution === null) {
67
- substitutionEqualToSubstitution = false;
68
- } else {
69
- substitutionEqualToSubstitution = this.substitution.isEqualTo(substitution);
87
+ if (substitutionEqualToSubstituion) {
88
+ comparesToSubstitution = true;
70
89
  }
71
90
  }
72
91
 
73
- return substitutionEqualToSubstitution;
92
+ return comparesToSubstitution;
74
93
  }
75
94
 
76
- isStatementEqualToStatement(statement, context) {
77
- statement = stripBracketsFromStatement(statement, context); ///
95
+ validate(context) {
96
+ let validates = false;
97
+
98
+ const statementSubstitutionString = this.getString(); ///
99
+
100
+ context.trace(`Validating the '${statementSubstitutionString}' statement substitution...`);
101
+
102
+ const targetStatementValidates = this.validateTargetStatement(context);
78
103
 
79
- const statementEqualToStatement = this.statement.isEqualTo(statement);
104
+ if (targetStatementValidates) {
105
+ const replacementStatementValidates = this.validateReplacementStatement(context);
80
106
 
81
- return statementEqualToStatement;
107
+ if (replacementStatementValidates) {
108
+ validates = true;
109
+ }
110
+ }
111
+
112
+ if (validates) {
113
+ const substititoin = this; ///
114
+
115
+ context.addSubstitution(substititoin);
116
+
117
+ context.debug(`...validated the '${statementSubstitutionString}' statement substitution.`);
118
+ }
119
+
120
+ return validates;
82
121
  }
83
122
 
84
- isSimple() {
85
- const simple = (this.substitution === null);
123
+ validateTargetStatement(context) {
124
+ let targetStatementValidates = false;
86
125
 
87
- return simple;
126
+ const targetStatementString = this.targetStatement.getString(),
127
+ statementSubstitutionString = this.getString(); ///
128
+
129
+ context.trace(`Validating the '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement...`);
130
+
131
+ const targetStatementSingular = this.targetStatement.isSingular();
132
+
133
+ if (targetStatementSingular) {
134
+ const stated = true,
135
+ assignments = null;
136
+
137
+ targetStatementValidates = this.targetStatement.validate(assignments, stated, context);
138
+ } else {
139
+ context.debug(`The '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement is not singular.`);
140
+ }
141
+
142
+ if (targetStatementValidates) {
143
+ context.debug(`...validated the '${statementSubstitutionString}' statement subtitution's '${targetStatementString}' target statement...`);
144
+ }
145
+
146
+ return targetStatementValidates;
147
+ }
148
+
149
+ validateReplacementStatement(context) {
150
+ let replacementStatementValidates;
151
+
152
+ const replacementStatementString = this.replacementStatement.getString(),
153
+ statementSubstitutionString = this.getString(); ///
154
+
155
+ context.trace(`Validating the '${statementSubstitutionString}' statement subtitution's '${replacementStatementString}' replacement statement...`);
156
+
157
+ const stated = true,
158
+ assignments = null;
159
+
160
+ replacementStatementValidates = this.replacementStatement.validate(assignments, stated, context);
161
+
162
+ if (replacementStatementValidates) {
163
+ context.debug(`...validated the '${statementSubstitutionString}' statement subtitution's '${replacementStatementString}' replacement statement...`);
164
+ }
165
+
166
+ return replacementStatementValidates;
88
167
  }
89
168
 
90
169
  unifyStatement(statement, context) {
91
- let substitution = null;
170
+ let statementUnifies = false;
92
171
 
93
- const { Substitutions } = elements,
94
- substitutions = Substitutions.fromNothing(),
95
- specificContext = context; ///
172
+ const statementString = statement.getString(),
173
+ statementSubstitutionString = this.getString();
174
+
175
+ context.trace(`Unifying the '${statementString}' statement with the '${statementSubstitutionString}' statement substiution's statement...`);
176
+
177
+ const specificContext = context; ///
96
178
 
97
179
  context = this.getContext();
98
180
 
99
- const generalContext = context, ///
100
- statementUnifies = this.statement.unifyStatement(statement, substitutions, generalContext, specificContext);
181
+ const generalContext = context; ///
182
+
183
+ context = specificContext; ///
184
+
185
+ const { Substitutions } = elements,
186
+ substitutions = Substitutions.fromNothing(context);
187
+
188
+ statementUnifies = this.replacementStatement.unifyStatement(statement, substitutions, generalContext, specificContext);
189
+
190
+ let substitution = null;
101
191
 
102
192
  if (statementUnifies) {
103
193
  const substitutionsNonTrivialLength = substitutions.getNonTrivialLength();
@@ -106,9 +196,15 @@ export default define(class StatementSubstitution extends Substitution {
106
196
  const firstSubstitution = substitutions.getFirstSubstitution();
107
197
 
108
198
  substitution = firstSubstitution; ///
199
+ } else {
200
+ statementUnifies = false;
109
201
  }
110
202
  }
111
203
 
204
+ if (statementUnifies) {
205
+ context.trace(`...unified the '${statementString}' statement with the '${statementSubstitutionString}' statement substiution's statement.`);
206
+ }
207
+
112
208
  return substitution;
113
209
  }
114
210
 
@@ -139,41 +235,28 @@ export default define(class StatementSubstitution extends Substitution {
139
235
  }
140
236
 
141
237
  resolve(substitutions, context) {
142
- const substitutionString = this.string; ///
238
+ context = this.getContext();
239
+
240
+ const substitutionString = this.getString(); ///
143
241
 
144
242
  context.trace(`Resolving the ${substitutionString} substitution...`);
145
243
 
146
- substitutions.snapshot();
244
+ substitutions.snapshot(context);
147
245
 
148
246
  const metavariable = this.getMetavariable(),
149
- simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable);
247
+ simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable),
248
+ substitution = simpleSubstitution.unifyStatement(this.replacementStatement, context);
150
249
 
151
- if (simpleSubstitution !== null) {
152
- let context;
250
+ if (substitution !== null) {
251
+ const substitutionUnifies = this.unifySubstitution(substitution, substitutions, context);
153
252
 
154
- context = this.getContext();
155
-
156
- const substitution = simpleSubstitution.unifyStatement(this.statement, context);
157
-
158
- if (substitution !== null) {
159
- context = simpleSubstitution.getContext();
160
-
161
- const simpleContext = context; ///
162
-
163
- context = substitution.getContext();
164
-
165
- context.merge(simpleContext);
166
-
167
- const substitutionUnifies = this.unifySubstitution(substitution, substitutions, context);
168
-
169
- if (substitutionUnifies) {
170
- this.resolved = true;
171
- }
253
+ if (substitutionUnifies) {
254
+ this.resolved = true;
172
255
  }
173
256
  }
174
257
 
175
258
  this.resolved ?
176
- substitutions.continue() :
259
+ substitutions.continue(context) :
177
260
  substitutions.rollback(context);
178
261
 
179
262
  if (this.resolved) {
@@ -182,11 +265,11 @@ export default define(class StatementSubstitution extends Substitution {
182
265
  }
183
266
 
184
267
  toJSON() {
185
- const metavariableJSON = metavariableToMetavariableJSON(this.metavariable),
186
- statementJSON = statementToStatementJSON(this.statement),
268
+ const metavariableJSON = metavariableToMetavariableJSON(this.targetStatement),
269
+ statementJSON = statementToStatementJSON(this.replacementStatement),
187
270
  metavariable = metavariableJSON, ///
188
271
  statement = statementJSON, ///
189
- string = this.string, ///
272
+ string = this.getString(), ///
190
273
  json = {
191
274
  string,
192
275
  statement,
@@ -199,80 +282,36 @@ export default define(class StatementSubstitution extends Substitution {
199
282
  static name = "StatementSubstitution";
200
283
 
201
284
  static fromJSON(json, context) {
202
- const { string } = json,
203
- statementSubstitutionNode = instantiateStatementSubstitution(string, context),
204
- node = statementSubstitutionNode,
205
- resolved = true,
206
- statement = statementFromJSON(json, context),
207
- metavariable = metavariableFromJSON(json, context),
208
- substitution = null, ///
209
- statementSubstitution = new StatementSubstitution(context, string, node, resolved, statement, metavariable, substitution);
210
-
211
- return statementSubstitution;
285
+ ///
212
286
  }
213
287
 
214
288
  static fromStatementAndMetavariable(statement, metavariable, context) {
215
289
  statement = stripBracketsFromStatement(statement, context); ///
216
290
 
217
- const string = stringFromStatementAndMetavariable(statement, metavariable),
218
- statementSubstitutionNode = instantiateStatementSubstitution(string, context);
219
-
220
- context = {
221
- nodeAsString: () => string
222
- };
223
-
224
- const statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, context);
291
+ return literally((context) => {
292
+ const statementSubstitutionString = statementSubstitutionStringFromStatementAndMetavariable(statement, metavariable, context),
293
+ string = statementSubstitutionString, ///
294
+ statementSubstitutionNode = instantiateStatementSubstitution(string, context),
295
+ statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, context);
225
296
 
226
- statementSubstitution.setStatement(statement);
297
+ statementSubstitution.validate(context);
227
298
 
228
- statementSubstitution.setMetavariable(metavariable);
229
-
230
- return statementSubstitution;
299
+ return statementSubstitution;
300
+ }, context);
231
301
  }
232
302
 
233
303
  static fromStatementMetavariableAndSubstitution(statement, metavariable, substitution, context) {
234
304
  statement = stripBracketsFromStatement(statement, context); ///
235
305
 
236
- const string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, context),
237
- statementSubstitutionNode = instantiateStatementSubstitution(string, context);
238
-
239
- context = {
240
- nodeAsString: () => string
241
- };
306
+ return literally((context) => {
307
+ const statementSubstitutionString = statementSubstitutionStringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution),
308
+ string = statementSubstitutionString, ///
309
+ statementSubstitutionNode = instantiateStatementSubstitution(string, context),
310
+ statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, substitution, context);
242
311
 
243
- const statementSubstitution = statementSubstitutionFromStatementSubstitutionNode(statementSubstitutionNode, context);
312
+ statementSubstitution.validate(context);
244
313
 
245
- statementSubstitution.setStatement(statement);
246
-
247
- statementSubstitution.setMetavariable(metavariable);
248
-
249
- statementSubstitution.setSubstitution(substitution);
250
-
251
- return statementSubstitution;
314
+ return statementSubstitution;
315
+ }, context);
252
316
  }
253
317
  });
254
-
255
- function stringFromStatementAndMetavariable(statement, metavariable) {
256
- const statementString = statement.getString(),
257
- metavariableString = metavariable.getString(),
258
- string = `[${statementString} for ${metavariableString}]`;
259
-
260
- return string;
261
- }
262
-
263
- function stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution) {
264
- let string;
265
-
266
- const statementString = statement.getString(),
267
- metavariableString = metavariable.getString();
268
-
269
- if (substitution === null) {
270
- string = `[${statementString} for ${metavariableString}]`;
271
- } else {
272
- const substitutionString = substitution.getString();
273
-
274
- string = `[${statementString} for ${metavariableString}${substitutionString}]`;
275
- }
276
-
277
- return string;
278
- }
@@ -3,97 +3,139 @@
3
3
  import Substitution from "../substitution";
4
4
 
5
5
  import { define } from "../../elements";
6
+ import { literally } from "../../utilities/context";
6
7
  import { stripBracketsFromTerm } from "../../utilities/brackets";
7
8
  import { instantiateTermSubstitution } from "../../process/instantiate";
9
+ import { termSubstitutionStringFromTermAndVariable } from "../../utilities/string";
8
10
  import { termSubstitutionFromStatementNode, termSubstitutionFromTermSubstitutionNode } from "../../utilities/element";
9
11
 
10
12
  export default define(class TermSubstitution extends Substitution {
11
- constructor(context, string, node, term, variable) {
13
+ constructor(context, string, node, targetTerm, replacementTerm) {
12
14
  super(context, string, node);
13
15
 
14
- this.term = term;
15
- this.variable = variable;
16
+ this.targetTerm = targetTerm;
17
+ this.replacementTerm = replacementTerm;
16
18
  }
17
19
 
18
- getTerm() {
19
- return this.term;
20
+ getTargetTerm() {
21
+ return this.targetTerm;
20
22
  }
21
23
 
22
- getVariable() {
23
- return this.variable;
24
+ getReplacementTerm() {
25
+ return this.replacementTerm;
26
+ }
27
+
28
+ getTargetNode() {
29
+ const targetTermNode = this.targetTerm.getNode(),
30
+ tergetNode = targetTermNode; ///
31
+
32
+ return tergetNode;
24
33
  }
25
34
 
26
35
  getReplacementNode() {
27
- const termNode = this.term.getNode(),
28
- replacementNode = termNode; ///
36
+ const replacementTermNode = this.replacementTerm.getNode(),
37
+ replacementNode = replacementTermNode; ///
29
38
 
30
39
  return replacementNode;
31
40
  }
32
41
 
33
- isTermEqualToTerm(term, context) {
42
+ isTrivial() {
43
+ const targetTermEqualToReplacementTerm = this.targetTerm.isEqualTo(this.replacementTerm),
44
+ trivial = targetTermEqualToReplacementTerm; ///
45
+
46
+ return trivial;
47
+ }
48
+
49
+ compareTerm(term, context) {
34
50
  term = stripBracketsFromTerm(term, context); ///
35
51
 
36
- const termEqualToTerm = this.term.isEqualTo(term);
52
+ const termEqualToReplacementTerm = this.replacementTerm.isEqualTo(term),
53
+ comparedToTerm = termEqualToReplacementTerm; ///
37
54
 
38
- return termEqualToTerm;
55
+ return comparedToTerm;
39
56
  }
40
57
 
41
- isTrivial() {
42
- let trivial = false;
58
+ compareParameter(parameter) {
59
+ const targetTermComparesToParameter = this.targetTerm.compareParameter(parameter),
60
+ comparesToParameter = targetTermComparesToParameter; ///
61
+
62
+ return comparesToParameter;
63
+ }
64
+
65
+ validate(context) {
66
+ let validates = false;
67
+
68
+ const termSubstitutionString = this.getString(); ///
69
+
70
+ context.trace(`Validating the '${termSubstitutionString}' term substitution...`);
71
+
72
+ const targetTermValidates = this.validateTargetTerm(context);
43
73
 
44
- const termComparesToVaraible = this.term.compareVariable(this.variable);
74
+ if (targetTermValidates) {
75
+ const replacementTermValidates = this.validateReplacementTerm(context);
45
76
 
46
- if (termComparesToVaraible) {
47
- trivial = true;
77
+ if (replacementTermValidates) {
78
+ validates = true;
79
+ }
48
80
  }
49
81
 
50
- return trivial;
51
- }
82
+ if (validates) {
83
+ const substititoin = this; ///
84
+
85
+ context.addSubstitution(substititoin);
52
86
 
53
- verify(context) {
54
- let verifies = false;
87
+ context.debug(`...validated the '${termSubstitutionString}' term substitution.`);
88
+ }
55
89
 
56
- const termSubstitutionString = this.string; ///
90
+ return validates;
91
+ }
57
92
 
58
- context.trace(`Verifiying the '${termSubstitutionString}' term substitution...`);
93
+ validateTargetTerm(context) {
94
+ let targetTermValidates = false;
59
95
 
60
- const termSingular = this.term.isSingular();
96
+ const targetTermString = this.targetTerm.getString(),
97
+ termSubstitutionString = this.getString(); ///
61
98
 
62
- if (termSingular) {
63
- if (this.variable !== null) {
64
- const variableIdentifier = this.variable.getIdentifier(),
65
- variablePresent = context.isVariablePresentByVariableIdentifier(variableIdentifier);
99
+ context.trace(`Validating the '${termSubstitutionString}' term subtitution's '${targetTermString}' target term...`);
66
100
 
67
- if (variablePresent) {
68
- const termNode = this.term.getNode(),
69
- variableIdentifier = termNode.getVariableIdentifier(),
70
- termVariableIdentifier = variableIdentifier, ///
71
- termVariablePresent = context.isVariablePresentByVariableIdentifier(termVariableIdentifier);
101
+ const targetTermSingular = this.targetTerm.isSingular();
72
102
 
73
- if (termVariablePresent) {
74
- verifies = true;
75
- } else {
76
- context.debug(`The '${termSubstitutionString}' term substitution's general term's variable is not present.`);
77
- }
78
- } else {
79
- context.debug(`The '${termSubstitutionString}' term substitution's specific term's variable is not present.`);
80
- }
81
- } else {
82
- context.debug(`The '${termSubstitutionString}' term substitution's general term is not singular.`);
83
- }
103
+ if (targetTermSingular) {
104
+ targetTermValidates = this.targetTerm.validate(context, () => {
105
+ const verifiesAhead = true;
106
+
107
+ return verifiesAhead;
108
+ });
84
109
  } else {
85
- context.debug(`The '${termSubstitutionString}' term substitution's specific term is not singular.`);
110
+ context.debug(`The '${termSubstitutionString}' term subtitution's '${targetTermString}' target term is not singular.`);
86
111
  }
87
112
 
88
- if (verifies) {
89
- const substititoin = this; ///
113
+ if (targetTermValidates) {
114
+ context.debug(`...validated the '${termSubstitutionString}' term subtitution's '${targetTermString}' target term...`);
115
+ }
90
116
 
91
- context.addSubstitution(substititoin);
117
+ return targetTermValidates;
118
+ }
119
+
120
+ validateReplacementTerm(context) {
121
+ let replacementTermValidates;
92
122
 
93
- context.debug(`...verified the '${termSubstitutionString}' term substitution.`);
123
+ const replacementTermString = this.replacementTerm.getString(),
124
+ termSubstitutionString = this.getString(); ///
125
+
126
+ context.trace(`Validating the '${termSubstitutionString}' term subtitution's '${replacementTermString}' replacement term...`);
127
+
128
+ replacementTermValidates = this.replacementTerm.validate(context, () => {
129
+ const validatesAhead = true;
130
+
131
+ return validatesAhead;
132
+ });
133
+
134
+ if (replacementTermValidates) {
135
+ context.debug(`...validated the '${termSubstitutionString}' term subtitution's '${replacementTermString}' replacement term...`);
94
136
  }
95
137
 
96
- return verifies;
138
+ return replacementTermValidates;
97
139
  }
98
140
 
99
141
  static name = "TermSubstitution";
@@ -105,19 +147,18 @@ export default define(class TermSubstitution extends Substitution {
105
147
  return termSubstitution;
106
148
  }
107
149
 
108
- static fromTermAndMetavariable(term, metavariable, context) {
109
- const string = stringFromTermAndVariable(term, metavariable),
110
- termSubstitutionNode = instantiateTermSubstitution(string, context),
111
- termSubstitution = termSubstitutionFromTermSubstitutionNode(termSubstitutionNode, context);
150
+ static fromTermAndVariable(term, variable, context) {
151
+ term = stripBracketsFromTerm(term, context); ///
152
+
153
+ return literally((context) => {
154
+ const termSubstitutionString = termSubstitutionStringFromTermAndVariable(term, variable),
155
+ string = termSubstitutionString, ///
156
+ termSubstitutionNode = instantiateTermSubstitution(string, context),
157
+ termSubstitution = termSubstitutionFromTermSubstitutionNode(termSubstitutionNode, context);
112
158
 
113
- return termSubstitution;
159
+ termSubstitution.validate(context);
160
+
161
+ return termSubstitution;
162
+ }, context);
114
163
  }
115
164
  });
116
-
117
- function stringFromTermAndVariable(term, variable) {
118
- const termString = term.getString(),
119
- variableString = variable.getString(),
120
- string = `[${termString} for ${variableString}]`;
121
-
122
- return string;
123
- }