occam-verify-cli 0.0.1067 → 0.0.1069

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 (137) hide show
  1. package/bin/action/verify.js +3 -2
  2. package/lib/assertion/contained.js +2 -2
  3. package/lib/assertion/defined.js +2 -2
  4. package/lib/assertion/subproof.js +3 -3
  5. package/lib/assignment/judgement.js +3 -3
  6. package/lib/axiom.js +11 -6
  7. package/lib/combinator.js +9 -9
  8. package/lib/conclusion.js +13 -10
  9. package/lib/conjecture.js +11 -6
  10. package/lib/consequent.js +13 -10
  11. package/lib/constructor.js +9 -9
  12. package/lib/context/file.js +34 -126
  13. package/lib/context/local.js +16 -5
  14. package/lib/context/release.js +2 -3
  15. package/lib/declaration.js +96 -2
  16. package/lib/equivalence.js +2 -2
  17. package/lib/frame.js +179 -98
  18. package/lib/index.js +22 -6
  19. package/lib/judgement.js +84 -5
  20. package/lib/label.js +12 -8
  21. package/lib/lemma.js +12 -12
  22. package/lib/metaLemma.js +120 -8
  23. package/lib/metaType.js +24 -3
  24. package/lib/metatheorem.js +145 -9
  25. package/lib/metavariable.js +128 -43
  26. package/lib/mixins/statement/qualified/unify.js +6 -10
  27. package/lib/mixins/statement/unify.js +4 -19
  28. package/lib/mixins/statement/verify.js +13 -13
  29. package/lib/mixins/term/unify.js +2 -2
  30. package/lib/premise.js +21 -13
  31. package/lib/reference.js +17 -17
  32. package/lib/rule.js +28 -40
  33. package/lib/statement/unqualified.js +34 -9
  34. package/lib/statement.js +7 -5
  35. package/lib/substitution/frameForMetavariable.js +75 -70
  36. package/lib/substitution/statementForMetavariable.js +83 -42
  37. package/lib/substitution/termForVariable.js +65 -68
  38. package/lib/substitution.js +46 -43
  39. package/lib/substitutions.js +52 -40
  40. package/lib/supposition.js +15 -11
  41. package/lib/term.js +6 -11
  42. package/lib/theorem.js +11 -6
  43. package/lib/topLevelAssertion.js +24 -42
  44. package/lib/type.js +5 -12
  45. package/lib/unifier/intrinsicLevel.js +4 -4
  46. package/lib/unifier/metaLevel.js +11 -7
  47. package/lib/unifier/metavariable.js +6 -6
  48. package/lib/unifier/statementWithCombinator.js +16 -16
  49. package/lib/unifier/termWithConstructor.js +7 -7
  50. package/lib/utilities/brackets.js +10 -10
  51. package/lib/utilities/json.js +493 -0
  52. package/lib/utilities/node.js +26 -19
  53. package/lib/utilities/release.js +53 -0
  54. package/lib/utilities/releaseContext.js +4 -15
  55. package/lib/utilities/tokens.js +8 -1
  56. package/lib/variable.js +14 -15
  57. package/lib/verifier/topLevel.js +5 -5
  58. package/package.json +1 -1
  59. package/src/assertion/contained.js +1 -1
  60. package/src/assertion/defined.js +1 -1
  61. package/src/assertion/subproof.js +2 -3
  62. package/src/assignment/judgement.js +3 -4
  63. package/src/axiom.js +14 -6
  64. package/src/combinator.js +12 -13
  65. package/src/conclusion.js +16 -13
  66. package/src/conjecture.js +14 -6
  67. package/src/consequent.js +16 -13
  68. package/src/constructor.js +11 -13
  69. package/src/context/file.js +94 -202
  70. package/src/context/local.js +8 -6
  71. package/src/context/release.js +2 -3
  72. package/src/declaration.js +126 -45
  73. package/src/equivalence.js +2 -2
  74. package/src/frame.js +225 -141
  75. package/src/index.js +17 -1
  76. package/src/judgement.js +109 -3
  77. package/src/label.js +15 -10
  78. package/src/lemma.js +17 -10
  79. package/src/metaLemma.js +102 -1
  80. package/src/metaType.js +29 -3
  81. package/src/metatheorem.js +143 -2
  82. package/src/metavariable.js +189 -66
  83. package/src/mixins/statement/qualified/unify.js +7 -19
  84. package/src/mixins/statement/unify.js +3 -25
  85. package/src/mixins/statement/verify.js +15 -13
  86. package/src/mixins/term/unify.js +1 -1
  87. package/src/premise.js +31 -16
  88. package/src/reference.js +18 -18
  89. package/src/rule.js +40 -58
  90. package/src/statement/unqualified.js +41 -11
  91. package/src/statement.js +6 -3
  92. package/src/substitution/frameForMetavariable.js +85 -98
  93. package/src/substitution/statementForMetavariable.js +109 -45
  94. package/src/substitution/termForVariable.js +83 -94
  95. package/src/substitution.js +36 -34
  96. package/src/substitutions.js +53 -46
  97. package/src/supposition.js +22 -14
  98. package/src/term.js +5 -15
  99. package/src/theorem.js +14 -6
  100. package/src/topLevelAssertion.js +38 -64
  101. package/src/type.js +5 -20
  102. package/src/unifier/intrinsicLevel.js +4 -3
  103. package/src/unifier/metaLevel.js +19 -7
  104. package/src/unifier/metavariable.js +5 -5
  105. package/src/unifier/statementWithCombinator.js +19 -19
  106. package/src/unifier/termWithConstructor.js +7 -7
  107. package/src/utilities/brackets.js +5 -5
  108. package/src/utilities/json.js +551 -0
  109. package/src/utilities/node.js +28 -23
  110. package/src/{verify → utilities}/release.js +5 -1
  111. package/src/utilities/releaseContext.js +2 -2
  112. package/src/utilities/tokens.js +10 -0
  113. package/src/variable.js +18 -19
  114. package/src/verifier/topLevel.js +6 -4
  115. package/lib/argument.js +0 -106
  116. package/lib/metaTypes.js +0 -19
  117. package/lib/unify/metavariableWithFrame.js +0 -40
  118. package/lib/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +0 -31
  119. package/lib/unify/statementWithSttaemetnGivenEquivalences.js +0 -45
  120. package/lib/verify/declaration.js +0 -83
  121. package/lib/verify/frame.js +0 -120
  122. package/lib/verify/judgement.js +0 -88
  123. package/lib/verify/metaLemma.js +0 -49
  124. package/lib/verify/metatheorem.js +0 -48
  125. package/lib/verify/metavariableGivenMetaType.js +0 -44
  126. package/lib/verify/release.js +0 -50
  127. package/src/argument.js +0 -79
  128. package/src/metaTypes.js +0 -11
  129. package/src/unify/metavariableWithFrame.js +0 -40
  130. package/src/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +0 -27
  131. package/src/unify/statementWithSttaemetnGivenEquivalences.js +0 -51
  132. package/src/verify/declaration.js +0 -113
  133. package/src/verify/frame.js +0 -157
  134. package/src/verify/judgement.js +0 -127
  135. package/src/verify/metaLemma.js +0 -72
  136. package/src/verify/metatheorem.js +0 -67
  137. package/src/verify/metavariableGivenMetaType.js +0 -45
package/src/reference.js CHANGED
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  import Metavariable from "./metavariable";
4
+ import LocalContext from "./context/local";
4
5
 
5
6
  import { nodeQuery } from "./utilities/query";
7
+ import { referenceMetaType } from "./metaType";
8
+ import { metavariableFromJSON, metavariableToMetavariableJSON } from "./utilities/json";
6
9
 
7
10
  const metavariableNodeQuery = nodeQuery("//reference/metavariable");
8
11
 
@@ -25,24 +28,27 @@ export default class Reference {
25
28
  return metavariableNode;
26
29
  }
27
30
 
28
- verifyAtTopLevel(fileContext) {
29
- let verifiedAtTopLevel;
31
+ verify(localContext) {
32
+ let verified;
30
33
 
31
34
  const referenceString = this.getString(); ///
32
35
 
33
- fileContext.trace(`Verifying the '${referenceString}' reference at top level...`);
36
+ localContext.trace(`Verifying the '${referenceString}' reference...`);
34
37
 
35
- verifiedAtTopLevel = true;
38
+ const metaType = referenceMetaType, ///
39
+ metavariableVerifiedGivenMetaType = this.metavariable.verifyGivenMetaType(metaType, localContext);
36
40
 
37
- if (verifiedAtTopLevel) {
38
- fileContext.debug(`...verified the '${referenceString}' reference at top level.`);
41
+ verified = metavariableVerifiedGivenMetaType; ///
42
+
43
+ if (verified) {
44
+ localContext.debug(`...verified the '${referenceString}' reference.`);
39
45
  }
40
46
 
41
- return verifiedAtTopLevel;
47
+ return verified;
42
48
  }
43
49
 
44
50
  toJSON() {
45
- const metavariableJSON = this.metavariable.toJSON(),
51
+ const metavariableJSON = metavariableToMetavariableJSON(this.metavariable),
46
52
  metavariable = metavariableJSON, ///
47
53
  string = this.string,
48
54
  json = {
@@ -54,22 +60,16 @@ export default class Reference {
54
60
  }
55
61
 
56
62
  static fromJSON(json, fileContext) {
57
- const { string } = json;
58
-
59
- let { metavariable } = json;
60
-
61
- json = metavariable; ///
62
-
63
- metavariable = Metavariable.fromJSON(json, fileContext);
64
-
65
- const reference = new Reference(string, metavariable);
63
+ const metavariable = metavariableFromJSON(json, fileContext),
64
+ reference = new Reference(string, metavariable);
66
65
 
67
66
  return reference;
68
67
  }
69
68
 
70
69
  static fromReferenceNode(referenceNode, fileContext) {
71
70
  const metavariableNode = metavariableNodeQuery(referenceNode),
72
- metavariable = Metavariable.fromMetavariableNode(metavariableNode, fileContext),
71
+ localContext = LocalContext.fromFileContext(fileContext),
72
+ metavariable = Metavariable.fromMetavariableNode(metavariableNode, localContext),
73
73
  reference = new Reference(metavariable);
74
74
 
75
75
  return reference;
package/src/rule.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { arrayUtilities } from "necessary";
4
4
 
5
+ import shim from "./shim";
5
6
  import Label from "./label";
6
7
  import Proof from "./proof";
7
8
  import Premise from "./premise";
@@ -9,7 +10,14 @@ import Conclusion from "./conclusion";
9
10
  import LocalContext from "./context/local";
10
11
  import Substitutions from "./substitutions";
11
12
 
13
+ import { stringFromLabels } from "./topLevelAssertion";
12
14
  import { nodeQuery, nodesQuery } from "./utilities/query";
15
+ import { labelsFromJSON,
16
+ premisesFromJSON,
17
+ conclusionFromJSON,
18
+ labelsToLabelsJSON,
19
+ premisesToPremisesJSON,
20
+ conclusionToConclusionJSON } from "./utilities/json";
13
21
 
14
22
  const { reverse, correlate } = arrayUtilities;
15
23
 
@@ -18,9 +26,10 @@ const proofNodeQuery = nodeQuery("/rule/proof"),
18
26
  premiseNodesQuery = nodesQuery("/rule/premise"),
19
27
  conclusionNodeQuery = nodeQuery("/rule/conclusion");
20
28
 
21
- export default class Rule {
22
- constructor(fileContext, labels, premises, conclusion, proof) {
29
+ class Rule {
30
+ constructor(fileContext, string, labels, premises, conclusion, proof) {
23
31
  this.fileContext = fileContext;
32
+ this.string = string;
24
33
  this.labels = labels;
25
34
  this.premises = premises;
26
35
  this.conclusion = conclusion;
@@ -31,6 +40,10 @@ export default class Rule {
31
40
  return this.fileContext;
32
41
  }
33
42
 
43
+ getString() {
44
+ return this.string;
45
+ }
46
+
34
47
  getLabels() {
35
48
  return this.labels;
36
49
  }
@@ -70,7 +83,13 @@ export default class Rule {
70
83
  const statementUnifiedWithConclusion = this.conclusion.unifyStatement(statement, substitutions, localContext); ///
71
84
 
72
85
  if (statementUnifiedWithConclusion) {
73
- const substitutionsResolved = substitutions.resolve(localContext);
86
+ const localContextB = localContext; ///
87
+
88
+ localContext = LocalContext.fromFileContext(this.fileContext);
89
+
90
+ const localContextA = localContext; ///
91
+
92
+ const substitutionsResolved = substitutions.resolve(localContextA, localContextB);
74
93
 
75
94
  statementUnified = substitutionsResolved; ///
76
95
  }
@@ -102,9 +121,9 @@ export default class Rule {
102
121
  verify() {
103
122
  let verified = false;
104
123
 
105
- const labelsString = labelsStringFromLabels(this.labels);
124
+ const ruleString = this.string; ///
106
125
 
107
- this.fileContext.trace(`Verifying the '${labelsString}' rule...`);
126
+ this.fileContext.trace(`Verifying the '${ruleString}' rule...`);
108
127
 
109
128
  const labelsVerifiedAtTopLevel = this.labels.every((label) => {
110
129
  const labelVVerifiedAtTopLevel = label.verifyAtTopLevel(this.fileContext);
@@ -148,24 +167,16 @@ export default class Rule {
148
167
  }
149
168
 
150
169
  if (verified) {
151
- this.fileContext.debug(`...verified the '${labelsString}' rule.`);
170
+ this.fileContext.debug(`...verified the '${ruleString}' rule.`);
152
171
  }
153
172
 
154
173
  return verified;
155
174
  }
156
175
 
157
176
  toJSON() {
158
- const labelsJSON = this.labels.map((label) => {
159
- const labelJSON = label.toJSON();
160
-
161
- return labelJSON;
162
- }),
163
- premisesJSON = this.premises.map((premise) => {
164
- const premiseJSON = premise.toJSON();
165
-
166
- return premiseJSON;
167
- }),
168
- conclusionJSON = this.conclusion.toJSON(),
177
+ const labelsJSON = labelsToLabelsJSON(this.labels),
178
+ premisesJSON = premisesToPremisesJSON(this.premises),
179
+ conclusionJSON = conclusionToConclusionJSON(this.conclusion),
169
180
  labels = labelsJSON, ///
170
181
  premises = premisesJSON, ///
171
182
  conclusion = conclusionJSON, ///
@@ -181,39 +192,13 @@ export default class Rule {
181
192
  static fromJSON(json, fileContext) {
182
193
  let rule;
183
194
 
184
- let { labels } = json;
185
-
186
- const labelsJSON = labels; ///
187
-
188
- labels = labelsJSON.map((labelJSON) => {
189
- const json = labelJSON, ///
190
- label = Label.fromJSON(json, fileContext);
191
-
192
- return label;
193
- });
194
-
195
- let { premises } = json;
196
-
197
- const premisesJSON = premises; ///
198
-
199
- premises = premisesJSON.map((premiseJSON) => {
200
- const json = premiseJSON, ///
201
- premise = Premise.fromJSON(json, fileContext);
202
-
203
- return premise;
204
- });
195
+ const proof = null,
196
+ labels = labelsFromJSON(json, fileContext),
197
+ premises = premisesFromJSON(json, fileContext),
198
+ conclusion = conclusionFromJSON(json, fileContext),
199
+ string = stringFromLabels(labels);
205
200
 
206
- let { conclusion } = json;
207
-
208
- const conclusionJSON = conclusion; ///
209
-
210
- json = conclusionJSON; ///
211
-
212
- conclusion = Conclusion.fromJSON(json, fileContext);
213
-
214
- const proof = null;
215
-
216
- rule = new Rule(fileContext, labels, premises, conclusion, proof);
201
+ rule = new Rule(fileContext, string, labels, premises, conclusion, proof);
217
202
 
218
203
  return rule;
219
204
  }
@@ -234,19 +219,16 @@ export default class Rule {
234
219
  return premise;
235
220
  }),
236
221
  conclusion = Conclusion.fromConclusionNode(conclusionNode, fileContext),
222
+ string = stringFromLabels(labels),
237
223
  proof = Proof.fromProofNode(proofNode, fileContext),
238
- rule = new Rule(fileContext, labels, premises, conclusion, proof);
224
+ rule = new Rule(fileContext, string, labels, premises, conclusion, proof);
239
225
 
240
226
  return rule;
241
227
  }
242
228
  }
243
229
 
244
- function labelsStringFromLabels(labels) {
245
- const labelsString = labels.map((label) => {
246
- const labelString = label.getString();
247
-
248
- return labelString;
249
- });
230
+ Object.assign(shim, {
231
+ Rule
232
+ });
250
233
 
251
- return labelsString;
252
- }
234
+ export default Rule;
@@ -1,14 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ import { arrayUtilities } from "necessary";
4
+
3
5
  import shim from "../shim";
4
6
  import LocalContext from "../context/local";
5
7
 
6
8
  import { trim } from "../utilities/string";
7
9
  import { nodeQuery } from "../utilities/query";
10
+ import { statementFromJSON, statementToStatementJSON } from "../utilities/json";
11
+
12
+ const { reverse } = arrayUtilities;
8
13
 
9
14
  const statementNodeQuery = nodeQuery("/unqualifiedStatement/statement");
10
15
 
11
- export default class UnqualifiedStatement {
16
+ class UnqualifiedStatement {
12
17
  constructor(string, statement) {
13
18
  this.string = string;
14
19
  this.statement = statement;
@@ -32,7 +37,15 @@ export default class UnqualifiedStatement {
32
37
 
33
38
  const statementVerified = this.statement.verify(assignments, stated, localContext);
34
39
 
35
- verified = statementVerified; ///
40
+ if (statementVerified) {
41
+ verified = true;
42
+ } else {
43
+ const statementUnifiedWithProofSteps = this.unifyStatementWithProofSteps(this.statement, assignments, stated, localContext);
44
+
45
+ if (statementUnifiedWithProofSteps) {
46
+ verified = true;
47
+ }
48
+ }
36
49
 
37
50
  if (verified) {
38
51
  localContext.debug(`...verified the '${unqualifiedStatementString}' unqualified statement.`);
@@ -62,8 +75,26 @@ export default class UnqualifiedStatement {
62
75
  return statementUnified;
63
76
  }
64
77
 
78
+ unifyStatementWithProofSteps(statement, assignments, stated, localContext) {
79
+ let statementUnifiedWithProofSteps;
80
+
81
+ let proofSteps = localContext.getProofSteps();
82
+
83
+ proofSteps = reverse(proofSteps); ///
84
+
85
+ statementUnifiedWithProofSteps = proofSteps.some((proofStep) => {
86
+ const statementUnified = proofStep.unifyStatement(statement, localContext);
87
+
88
+ if (statementUnified) {
89
+ return true;
90
+ }
91
+ });
92
+
93
+ return statementUnifiedWithProofSteps;
94
+ }
95
+
65
96
  toJSON() {
66
- const statementJSON = this.statement.toJSON(),
97
+ const statementJSON = statementToStatementJSON(this.statement),
67
98
  statement = statementJSON, ///
68
99
  string = this.string, ///
69
100
  json = {
@@ -75,15 +106,8 @@ export default class UnqualifiedStatement {
75
106
  }
76
107
 
77
108
  static fromJSON(json, fileContext) {
78
- const { Statement } = shim;
79
-
80
- let { statement } = json;
81
-
82
- json = statement; ///
83
-
84
- statement = Statement.fromJSON(json, fileContext);
85
-
86
109
  const { string } = json,
110
+ statement = statementFromJSON(json, fileContext),
87
111
  unqualifiedStatement = new UnqualifiedStatement(string, statement);
88
112
 
89
113
  return unqualifiedStatement;
@@ -111,3 +135,9 @@ export default class UnqualifiedStatement {
111
135
  return unqualifiedStatement;
112
136
  }
113
137
  }
138
+
139
+ Object.assign(shim, {
140
+ UnqualifiedStatement
141
+ });
142
+
143
+ export default UnqualifiedStatement;
package/src/statement.js CHANGED
@@ -117,16 +117,19 @@ class Statement {
117
117
 
118
118
  const statementANode = statementA.getNode(),
119
119
  statementBNode = statementB.getNode(),
120
+ context = localContextA, ///
120
121
  nodeA = statementANode, ///
121
122
  nodeB = statementBNode; ///
122
123
 
123
- localContextA = LocalContext.fromLocalContextAndTokens(localContextA, this.tokens);
124
+ localContextA = LocalContext.fromContextAndTokens(context, this.tokens);
124
125
 
125
126
  const unifiedAtMetaLevel = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
126
127
 
127
128
  statementUnified = unifiedAtMetaLevel; ///
128
129
 
129
- localContextB.debug(`...unified the '${statementBString}' statement with the '${statementAString}' statement.`);
130
+ if (statementUnified) {
131
+ localContextB.debug(`...unified the '${statementBString}' statement with the '${statementAString}' statement.`);
132
+ }
130
133
 
131
134
  return statementUnified;
132
135
  }
@@ -219,9 +222,9 @@ class Statement {
219
222
 
220
223
  static fromJSON(json, fileContext) {
221
224
  const { string } = json,
222
- statementString = string, ///
223
225
  lexer = fileContext.getLexer(),
224
226
  parser = fileContext.getParser(),
227
+ statementString = string, ///
225
228
  unqualifiedStatementString = unqualifiedStatementStringFromStatementString(statementString),
226
229
  unqualifiedStatementTokens = unqualifiedStatementTokensFromUnqualifiedStatementString(unqualifiedStatementString, lexer),
227
230
  unqualifiedStatementNode = unqualifiedStatementNodeFromUnqualifiedStatementTokens(unqualifiedStatementTokens, parser),
@@ -4,92 +4,126 @@ import shim from "../shim";
4
4
  import Substitution from "../substitution";
5
5
 
6
6
  import { nodeQuery } from "../utilities/query";
7
+ import { substitutionNodeFromUnqualifiedStatementNode,
8
+ unqualifiedStatementStringFromSubstitutionString,
9
+ unqualifiedStatementNodeFromUnqualifiedStatementTokens } from "../utilities/node";
10
+ import { unqualifiedStatementTokensFromUnqualifiedStatementString,
11
+ substitutionTokensFromUnqualifiedStatementTokensAndSubstitutionNode } from "../utilities/tokens";
7
12
 
8
- const substitutionNodeQuery = nodeQuery("/statement/substitution"),
9
- substitutionFrameNodeQuery = nodeQuery("/substitution/frame!"),
10
- frameMetavariableNodeQuery = nodeQuery("/frame/metavariable!"),
11
- substitutionMetavariableNodeQuery = nodeQuery("/substitution/metavariable!");
13
+ const frameNodeQuery = nodeQuery("/substitution/frame[0]"),
14
+ metavariableNodeQuery = nodeQuery("/substitution/frame[1]/metavariable!"),
15
+ substitutionNodeQuery = nodeQuery("/statement/substitution");
12
16
 
13
17
  export default class FrameForMetavariableSubstitution extends Substitution {
14
- constructor(string, frameNode, metavariableNode, substitutionNode) {
18
+ constructor(string, frame, metavariable, substitutionNode, substitutionTokens) {
15
19
  super(string);
16
20
 
17
- this.frameNode = frameNode;
18
- this.metavariableNode = metavariableNode;
21
+ this.frame = frame;
22
+ this.metavariable = metavariable;
19
23
  this.substitutionNode = substitutionNode;
24
+ this.substitutionTokens = substitutionTokens;
20
25
  }
21
26
 
22
- getFrameNode() {
23
- return this.frameNode;
27
+ getFrame() {
28
+ return this.frame;
24
29
  }
25
30
 
26
- getMetavariableNode() {
27
- return this.metavariableNode;
31
+ getMetavariable() {
32
+ return this.metavariable;
28
33
  }
29
34
 
30
35
  getSubstitutionNode() {
31
36
  return this.substitutionNode;
32
37
  }
33
38
 
34
- transformed(substitutions) {
35
- let transformedSubstitution = null;
39
+ getSubstitutionTokens() {
40
+ return this.substitutionTokens;
41
+ }
36
42
 
37
- const transformedFrameNode = transformFrameNode(this.frameNode, substitutions),
38
- transformedMetavariableNode = transformMetavariableNode(this.metavariableNode, substitutions);
43
+ getMetavariableName() {
44
+ const metavariableName = this.metavariable.getName();
39
45
 
40
- if ((transformedFrameNode !== null) && (transformedMetavariableNode !== null)) {
41
- const string = null, ///
42
- frameNode = transformedFrameNode, ///
43
- metavariableNode = transformedMetavariableNode, ///
44
- substitutionNode = null,
45
- frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode, substitutionNode);
46
+ return metavariableName;
47
+ }
46
48
 
47
- transformedSubstitution = frameForMetavariableSubstitution; ///
48
- }
49
+ getSubstitutionString() {
50
+ const frameString = this.frame.getString(),
51
+ metavariableString = this.metavariable.getString(),
52
+ substitutionString = `[[${frameString}] for [${metavariableString}]]`;
53
+
54
+ return substitutionString;
55
+ }
56
+
57
+ setSubstitutionNodeAndTokens(localContext) {
58
+ const lexer = localContext.getLexer(),
59
+ parser = localContext.getParser(),
60
+ substitutionString = this.getSubstitutionString(),
61
+ unqualifiedStatementString = unqualifiedStatementStringFromSubstitutionString(substitutionString),
62
+ unqualifiedStatementTokens = unqualifiedStatementTokensFromUnqualifiedStatementString(unqualifiedStatementString, lexer),
63
+ unqualifiedStatementNode = unqualifiedStatementNodeFromUnqualifiedStatementTokens(unqualifiedStatementTokens, parser);
64
+
65
+ this.substitutionNode = substitutionNodeFromUnqualifiedStatementNode(unqualifiedStatementNode);
66
+
67
+ this.substitutionTokens = substitutionTokensFromUnqualifiedStatementTokensAndSubstitutionNode(unqualifiedStatementTokens, this.substitutionNode);
68
+ }
49
69
 
50
- return transformedSubstitution;
70
+ setSubstitutionTokens(localContext) {
51
71
  }
52
72
 
53
73
  isEqualTo(substitution) {
54
74
  let equalTo = false;
55
75
 
56
76
  const frameNode = substitution.getFrameNode(),
57
- metavariableNode = substitution.getMetavariableNode();
77
+ metavariableName = substitution.getMetavariableName();
58
78
 
59
- if ((frameNode !== null) && (metavariableNode !== null)) {
79
+ if ((frameNode !== null) && (metavariableName !== null)) {
60
80
  const frameNodeMatches = this.matchFrameNode(frameNode),
61
- metavariableNodeMatches = this.matchMetavariableNode(metavariableNode);
81
+ metavariableNameMatches = this.matchMetavariableName(metavariableName);
62
82
 
63
- equalTo = (frameNodeMatches && metavariableNodeMatches);
83
+ equalTo = (frameNodeMatches && metavariableNameMatches);
64
84
  }
65
85
 
66
86
  return equalTo;
67
87
  }
68
88
 
69
- matchFrameNode(frameNode) {
70
- const frameNodeMatches = this.frameNode.match(frameNode);
89
+ matchFrameNode(frameNode) { return this.frame.matchFrameNode(frameNode); }
71
90
 
72
- return frameNodeMatches;
73
- }
91
+ matchMetavariableName(metavariableName) {
92
+ let metavariableNameMatches;
93
+
94
+ const metavariableNameA = metavariableName; ///
95
+
96
+ metavariableName = this.metavariable.getName();
74
97
 
75
- matchMetavariableNode(metavariableNode) {
76
- const metavariableNodeMatches = this.metavariableNode.match(metavariableNode);
98
+ const metavariableNameB = metavariableName; ///
77
99
 
78
- return metavariableNodeMatches;
100
+ metavariableNameMatches = (metavariableNameA === metavariableNameB);
101
+
102
+ return metavariableNameMatches;
79
103
  }
80
104
 
81
105
  matchSubstitutionNode(substitutionNode) {
82
- const substitutionNodeMatches = this.substitutionNode.match(substitutionNode);
106
+ let substitutionNodeMatches;
107
+
108
+ if ((substitutionNode === null) && (this.substitutionNode === null)) {
109
+ substitutionNodeMatches = true;
110
+ } else if ((substitutionNode === null) && (this.substitutionNode !== null)) {
111
+ substitutionNodeMatches = false;
112
+ } else if ((substitutionNode !== null) && (this.substitutionNode === null)) {
113
+ substitutionNodeMatches = false;
114
+ } else {
115
+ substitutionNodeMatches = this.substitutionNode.match(substitutionNode);
116
+ }
83
117
 
84
118
  return substitutionNodeMatches;
85
119
  }
86
120
 
87
- matchMetavariableNodeAndSubstitutionNode(metavariableNode, substitutionNode) {
88
- const metavariableNodeMatches = this.matchMetavariableNode(metavariableNode),
121
+ matchMetavariableNameAndSubstitutionNode(metavariableName, substitutionNode) {
122
+ const metavariableNameMatches = this.matchMetavariableName(metavariableName),
89
123
  substitutionNodeMatches = this.matchSubstitutionNode(substitutionNode),
90
- metavariableNodeAndSubstitutionNodeMatches = (metavariableNodeMatches && substitutionNodeMatches);
124
+ metavariableNameAndSubstitutionNodeMatches = (metavariableNameMatches && substitutionNodeMatches);
91
125
 
92
- return metavariableNodeAndSubstitutionNodeMatches;
126
+ return metavariableNameAndSubstitutionNodeMatches;
93
127
  }
94
128
 
95
129
  static fromStatementNode(statementNode, localContext) {
@@ -98,18 +132,17 @@ export default class FrameForMetavariableSubstitution extends Substitution {
98
132
  const substitutionNode = substitutionNodeQuery(statementNode);
99
133
 
100
134
  if (substitutionNode !== null) {
101
- let substitutionFrameNode = substitutionFrameNodeQuery(substitutionNode);
135
+ const frameNode = frameNodeQuery(substitutionNode),
136
+ metavariableNode = metavariableNodeQuery(substitutionNode);
102
137
 
103
- if (substitutionFrameNode !== null) {
138
+ if ((frameNode !== null) && (metavariableNode !== null)) {
104
139
  const { Frame, Metavariable } = shim,
105
- substitutionMetavariableNode = substitutionMetavariableNodeQuery(substitutionNode),
106
- metavariableNode = substitutionMetavariableNode, ///
107
- frameNode = substitutionFrameNode, ///
108
- frame = Frame.fromTermNode(frameNode, localContext),
109
- variable = Metavariable.fromMetavariableNode(metavariableNode, localContext),
110
- string = stringFromFrameAndMetavariable(frame, variable, localContext);
111
-
112
- frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode, substitutionNode);
140
+ frame = Frame.fromFrameNode(frameNode, localContext),
141
+ metavariable = Metavariable.fromMetavariableNode(metavariableNode, localContext),
142
+ string = stringFromFrameAndMetavariable(frame, metavariable, localContext),
143
+ substitutionTokens = localContext.nodeAsTokens(substitutionNode);
144
+
145
+ frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frame, metavariable, substitutionNode, substitutionTokens);
113
146
  }
114
147
  }
115
148
 
@@ -118,60 +151,14 @@ export default class FrameForMetavariableSubstitution extends Substitution {
118
151
 
119
152
  static fromFrameAndMetavariable(frame, metavariable, localContext) {
120
153
  const string = stringFromFrameAndMetavariable(frame, metavariable, localContext),
121
- frameNode = frame.getNode(),
122
- metavariableNode = metavariable.getNode(),
123
154
  substitutionNode = null,
124
- statementForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode, substitutionNode);
155
+ substitutionTokens = null,
156
+ statementForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frame, metavariable, substitutionNode, substitutionTokens);
125
157
 
126
158
  return statementForMetavariableSubstitution;
127
159
  }
128
160
  }
129
161
 
130
- function transformFrameNode(frameNode, substitutions) {
131
- let transformedFrameNode = null;
132
-
133
- const frameMetavariableNode = frameMetavariableNodeQuery(frameNode);
134
-
135
- if (frameMetavariableNode !== null) {
136
- const metavariableNode = frameMetavariableNode; ///
137
-
138
- substitutions.someSubstitution((substitution) => {
139
- const metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
140
-
141
- if (metavariableNodeMatches) {
142
- const frameNode = substitution.getFrameNode();
143
-
144
- transformedFrameNode = frameNode; ////
145
-
146
- return true;
147
- }
148
- });
149
- }
150
-
151
- return transformedFrameNode;
152
- }
153
-
154
- function transformMetavariableNode(metavariableNode, substitutions) {
155
- let transformedMetavariableNode = null;
156
-
157
- substitutions.someSubstitution((substitution) => {
158
- const metavariableNodeMatches = substitution.matchMetavariableNode(metavariableNode);
159
-
160
- if (metavariableNodeMatches) {
161
- const frameNode = substitution.getFrameNode(),
162
- frameMetavariableNode = frameMetavariableNodeQuery(frameNode);
163
-
164
- if (frameMetavariableNode !== null) {
165
- transformedMetavariableNode = frameMetavariableNode; ///
166
-
167
- return true;
168
- }
169
- }
170
- });
171
-
172
- return transformedMetavariableNode;
173
- }
174
-
175
162
  function stringFromFrameAndMetavariable(frame, metavariable, localContext) {
176
163
  const frameNode = frame.getNode(),
177
164
  frameString = localContext.nodeAsString(frameNode),