occam-verify-cli 0.0.1061 → 0.0.1065

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 (78) hide show
  1. package/bin/action/verify.js +2 -0
  2. package/lib/assertion/contained.js +184 -0
  3. package/lib/assertion/defined.js +171 -0
  4. package/lib/assertion/subproof.js +5 -5
  5. package/lib/assertion/type.js +13 -6
  6. package/lib/conclusion.js +5 -8
  7. package/lib/consequent.js +5 -8
  8. package/lib/context/release.js +3 -2
  9. package/lib/declaration.js +6 -50
  10. package/lib/equality.js +6 -7
  11. package/lib/equivalence.js +3 -2
  12. package/lib/frame.js +160 -64
  13. package/lib/metavariable.js +49 -39
  14. package/lib/mixins/statement/verify.js +24 -32
  15. package/lib/premise.js +5 -8
  16. package/lib/proofStep.js +2 -2
  17. package/lib/statement/unqualified.js +14 -1
  18. package/lib/statement.js +77 -23
  19. package/lib/substitution/statement.js +17 -2
  20. package/lib/substitution/statementForMetavariable.js +22 -27
  21. package/lib/substitution/termForVariable.js +9 -9
  22. package/lib/supposition.js +5 -8
  23. package/lib/term.js +46 -3
  24. package/lib/unifier/intrinsicLevel.js +4 -4
  25. package/lib/unifier/metaLevel.js +9 -13
  26. package/lib/unifier/metavariable.js +4 -4
  27. package/lib/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +3 -3
  28. package/lib/unify/statementWithSttaemetnGivenEquivalences.js +5 -5
  29. package/lib/utilities/unify.js +4 -21
  30. package/lib/variable.js +19 -3
  31. package/lib/verifier/intrinsicLevel.js +4 -4
  32. package/lib/verifier/metaLevel.js +4 -4
  33. package/lib/verifier/substitution.js +161 -0
  34. package/lib/verifier/topLevel.js +4 -4
  35. package/package.json +1 -1
  36. package/src/assertion/contained.js +170 -0
  37. package/src/assertion/defined.js +161 -0
  38. package/src/assertion/subproof.js +5 -4
  39. package/src/assertion/type.js +18 -7
  40. package/src/conclusion.js +5 -18
  41. package/src/consequent.js +5 -18
  42. package/src/context/release.js +3 -1
  43. package/src/declaration.js +49 -49
  44. package/src/equality.js +7 -8
  45. package/src/equivalence.js +3 -1
  46. package/src/frame.js +204 -59
  47. package/src/metavariable.js +82 -45
  48. package/src/mixins/statement/verify.js +30 -42
  49. package/src/premise.js +5 -18
  50. package/src/proofStep.js +1 -1
  51. package/src/statement/unqualified.js +17 -0
  52. package/src/statement.js +116 -32
  53. package/src/substitution/statement.js +22 -2
  54. package/src/substitution/statementForMetavariable.js +27 -34
  55. package/src/substitution/termForVariable.js +15 -12
  56. package/src/supposition.js +5 -18
  57. package/src/term.js +61 -3
  58. package/src/unifier/intrinsicLevel.js +3 -3
  59. package/src/unifier/metaLevel.js +16 -21
  60. package/src/unifier/metavariable.js +3 -3
  61. package/src/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +2 -2
  62. package/src/unify/statementWithSttaemetnGivenEquivalences.js +4 -4
  63. package/src/utilities/unify.js +0 -14
  64. package/src/variable.js +27 -3
  65. package/src/verifier/intrinsicLevel.js +3 -3
  66. package/src/verifier/metaLevel.js +3 -3
  67. package/src/verifier/substitution.js +75 -0
  68. package/src/verifier/topLevel.js +3 -3
  69. package/lib/unify/frameWithMetaType.js +0 -24
  70. package/lib/verify/assertion/contained.js +0 -107
  71. package/lib/verify/assertion/defined.js +0 -98
  72. package/lib/verify/assertion/subproof.js +0 -16
  73. package/lib/verify/frameGivenMetaType.js +0 -37
  74. package/src/unify/frameWithMetaType.js +0 -14
  75. package/src/verify/assertion/contained.js +0 -134
  76. package/src/verify/assertion/defined.js +0 -120
  77. package/src/verify/assertion/subproof.js +0 -9
  78. package/src/verify/frameGivenMetaType.js +0 -31
package/src/proofStep.js CHANGED
@@ -71,7 +71,7 @@ class ProofStep {
71
71
 
72
72
  verified = qualifiedStatementVerified; ///
73
73
  } else if (this.unqualifiedStatement !== null) {
74
- const stated = true,
74
+ const stated = false,
75
75
  assignments = [],
76
76
  unqualifiedStatementVerified = this.unqualifiedStatement.verify(assignments, stated, localContext);
77
77
 
@@ -45,6 +45,23 @@ export default class UnqualifiedStatement {
45
45
  return verified;
46
46
  }
47
47
 
48
+ unifyStatement(statement, substitutions, fileContext, localContext) {
49
+ let statementUnified;
50
+
51
+ const statementString = statement.getString(),
52
+ unqualifiedStatementString = this.getString(); ///
53
+
54
+ localContext.trace(`Unifying the '${statementString}' statement with the '${unqualifiedStatementString}' unqualified statement...`);
55
+
56
+ statementUnified = this.statement.unifyStatement(statement, substitutions, fileContext, localContext);
57
+
58
+ if (statementUnified) {
59
+ localContext.debug(`...unified the '${statementString}' statement with the '${unqualifiedStatementString}' unqualified statement.`);
60
+ }
61
+
62
+ return statementUnified;
63
+ }
64
+
48
65
  toJSON() {
49
66
  const statementJSON = this.statement.toJSON(),
50
67
  statement = statementJSON, ///
package/src/statement.js CHANGED
@@ -3,17 +3,23 @@
3
3
  import shim from "./shim";
4
4
  import unifyMixins from "./mixins/statement/unify";
5
5
  import verifyMixins from "./mixins/statement/verify";
6
- import StatementSubstitution from "./substitution/statement";
6
+ import LocalContext from "./context/local";
7
+ import metaLevelUnifier from "./unifier/metaLevel";
7
8
  import statementAsCombinatorVerifier from "./verifier/statementAsCombinator";
8
9
 
10
+ import { nodeQuery, nodesQuery } from "./utilities/query";
9
11
  import { STATEMENT_META_TYPE_NAME } from "./metaTypeNames";
10
12
  import { statementNodeFromStatementString } from "./utilities/node";
11
13
 
14
+ const statementNodeQuery = nodeQuery("/*//statement"),
15
+ substitutionNodeQuery = nodeQuery("/statement/substitution"),
16
+ statementVariableNodesQuery = nodesQuery("/statement//variable"),
17
+ statementMetavariableNodesQuery = nodesQuery("/statement//metavariable");
18
+
12
19
  class Statement {
13
- constructor(string, node, substitution) {
20
+ constructor(string, node) {
14
21
  this.string = string;
15
22
  this.node = node;
16
- this.substitution = substitution;
17
23
  }
18
24
 
19
25
  getString() {
@@ -24,10 +30,6 @@ class Statement {
24
30
  return this.node;
25
31
  }
26
32
 
27
- getSubstitution() {
28
- return this.substitution;
29
- }
30
-
31
33
  isEqualTo(statement) {
32
34
  const node = statement.getNode(),
33
35
  matches = this.node.match(node),
@@ -36,6 +38,60 @@ class Statement {
36
38
  return equalTo;
37
39
  }
38
40
 
41
+ isVariableContained(variable, localContext) {
42
+ let variableContained;
43
+
44
+ const variableString = variable.getString(),
45
+ statementString = this.string; ///
46
+
47
+ localContext.trace(`The '${variableString}' variable is contained in hte '${statementString}' statement...`);
48
+
49
+ const variableNode = variable.getNode(),
50
+ statementNode = this.node,
51
+ statementVariableNodes = statementVariableNodesQuery(statementNode);
52
+
53
+ variableContained = statementVariableNodes.some((statementVariableNode) => { ///
54
+ const variableNodeMatchesStatementVariableNode = variableNode.match(statementVariableNode);
55
+
56
+ if (variableNodeMatchesStatementVariableNode) {
57
+ return true;
58
+ }
59
+ });
60
+
61
+ if (variableContained) {
62
+ localContext.debug(`...the '${variableString}' variable is contained in hte '${statementString}' statement.`);
63
+ }
64
+
65
+ return variableContained;
66
+ }
67
+
68
+ isMetavariableContained(metavariable, localContext) {
69
+ let metavariableContained;
70
+
71
+ const metavariableString = metavariable.getString(),
72
+ statementString = this.string; ///
73
+
74
+ localContext.trace(`The '${metavariableString}' metavariable is contained in hte '${statementString}' statement...`);
75
+
76
+ const metavariableNode = metavariable.getNode(),
77
+ statementNode = this.node,
78
+ statementMetavariableNodes = statementMetavariableNodesQuery(statementNode);
79
+
80
+ metavariableContained = statementMetavariableNodes.some((statementMetavariableNode) => { ///
81
+ const metavariableNodeMatchesStatementMetavariableNode = metavariableNode.match(statementMetavariableNode);
82
+
83
+ if (metavariableNodeMatchesStatementMetavariableNode) {
84
+ return true;
85
+ }
86
+ });
87
+
88
+ if (metavariableContained) {
89
+ localContext.debug(`...the '${metavariableString}' metavariable is contained in hte '${statementString}' statement.`);
90
+ }
91
+
92
+ return metavariableContained;
93
+ }
94
+
39
95
  verify(assignments, stated, localContext) {
40
96
  let verified = false;
41
97
 
@@ -96,7 +152,7 @@ class Statement {
96
152
  const metaTypeString = metaType.getString(),
97
153
  statementString = this.string; ///
98
154
 
99
- localContext.trace(`Verifying the '${statementString}' given the '${metaTypeString}' meta-type...`);
155
+ localContext.trace(`Verifying the '${statementString}' statement given the '${metaTypeString}' meta-type...`);
100
156
 
101
157
  const metaTypeName = metaType.getName();
102
158
 
@@ -107,20 +163,41 @@ class Statement {
107
163
  }
108
164
 
109
165
  if (verifiedGivenMetaType) {
110
- localContext.debug(`...verified the '${statementString}' given the '${metaTypeString}' meta-type.`);
166
+ localContext.debug(`...verified the '${statementString}' statement given the '${metaTypeString}' meta-type.`);
111
167
  }
112
168
 
113
169
  return verifiedGivenMetaType;
114
170
  }
115
171
 
172
+ unifyStatement(statement, substitutions, fileContext, localContext) {
173
+ let statementUnified;
174
+
175
+ const statementA = this, ///
176
+ statementB = statement, ///
177
+ statementAString = statementA.getString(),
178
+ statementBString = statementB.getString();
179
+
180
+ localContext.trace(`Unifying the '${statementBString}' statement with the '${statementAString}' statement...`);
181
+
182
+ const statementANode = statementA.getNode(),
183
+ statementBNode = statementB.getNode(),
184
+ nodeA = statementANode, ///
185
+ nodeB = statementBNode, ///
186
+ fileContextA = fileContext, ///
187
+ localContextA = LocalContext.fromFileContext(fileContextA),
188
+ localContextB = localContext, ///
189
+ unifiedAtMetaLevel = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
190
+
191
+ statementUnified = unifiedAtMetaLevel; ///
192
+
193
+ localContext.debug(`...unified the '${statementBString}' statement with the '${statementAString}' statement.`);
194
+
195
+ return statementUnified;
196
+ }
197
+
116
198
  toJSON() {
117
- const substitutionJSON = (this.substitution !== null) ?
118
- this.substitution.toJSON() :
119
- null,
120
- substitution = substitutionJSON, ///
121
- string = this.string, ///
199
+ const string = this.string, ///
122
200
  json = {
123
- substitution,
124
201
  string
125
202
  };
126
203
 
@@ -133,17 +210,8 @@ class Statement {
133
210
  lexer = fileContext.getLexer(),
134
211
  parser = fileContext.getParser(),
135
212
  statementNode = statementNodeFromStatementString(statementString, lexer, parser),
136
- node = statementNode; ///
137
-
138
- let { substitution } = json;
139
-
140
- json = substitution; ///
141
-
142
- const statementSubstitution = StatementSubstitution.fromJSON(json, fileContext);
143
-
144
- substitution = statementSubstitution; ///
145
-
146
- const statement = new Statement(string, node, substitution);
213
+ node = statementNode, ///
214
+ statement = new Statement(string, node);
147
215
 
148
216
  return statement;
149
217
  }
@@ -153,22 +221,38 @@ class Statement {
153
221
 
154
222
  if (statementNode !== null) {
155
223
  const node = statementNode, ///
156
- string = localContext.nodeAsString(node),
157
- statementSubstitution = StatementSubstitution.fromStatementNode(statementNode, localContext),
158
- substitution = statementSubstitution; ///
224
+ string = localContext.nodeAsString(node);
159
225
 
160
- statement = new Statement(string, node, substitution);
226
+ statement = new Statement(string, node);
161
227
  }
162
228
 
163
229
  return statement;
164
230
  }
231
+
232
+ static fromDefinedAssertionNode(definedAssertionNode, localContext) {
233
+ const statementNode = statementNodeQuery(definedAssertionNode),
234
+ node = statementNode, ///
235
+ string = localContext.nodeAsString(node),
236
+ statement = new Statement(string, node);
237
+
238
+ return statement;
239
+ }
240
+
241
+ static fromContainedAssertionNode(containedAssertionNode, localContext) {
242
+ const statementNode = statementNodeQuery(containedAssertionNode),
243
+ node = statementNode, ///
244
+ string = localContext.nodeAsString(node),
245
+ statement = new Statement(string, node);
246
+
247
+ return statement;
248
+ }
165
249
  }
166
250
 
251
+ Object.assign(Statement.prototype, unifyMixins);
252
+
167
253
  Object.assign(shim, {
168
254
  Statement
169
255
  });
170
256
 
171
- Object.assign(Statement.prototype, unifyMixins);
172
-
173
257
  export default Statement;
174
258
 
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  import Substitution from "../substitution";
4
+ import substitutionVerifier from "../verifier/substitution";
4
5
 
5
6
  import { nodeQuery } from "../utilities/query";
6
7
  import { substitutionNodeFromSubstitutionString } from "../utilities/node";
@@ -18,6 +19,25 @@ export default class StatementSubstitution extends Substitution {
18
19
  return this.node;
19
20
  }
20
21
 
22
+ verify(assignments, stated, localContext) {
23
+ let verified;
24
+
25
+ const statementSubstitutionString = this.string; ///
26
+
27
+ localContext.trace(`Verifying the '${statementSubstitutionString}' statement substitution...`);
28
+
29
+ const substitutionNode = this.node, ///
30
+ substitutionVerified = substitutionVerifier.verify(substitutionNode, assignments, stated, localContext);
31
+
32
+ verified = substitutionVerified; ///
33
+
34
+ if (verified) {
35
+ localContext.debug(`...verified the '${statementSubstitutionString}' statement substitution.`);
36
+ }
37
+
38
+ return verified;
39
+ }
40
+
21
41
  toJSON() {
22
42
  const string = this.getString(),
23
43
  json = {
@@ -50,10 +70,10 @@ export default class StatementSubstitution extends Substitution {
50
70
  const substitutionNode = substitutionNodeQuery(statementNode);
51
71
 
52
72
  if (substitutionNode) {
53
- const node = substitutionNode,
73
+ const node = substitutionNode, ///
54
74
  string = fileContext.nodeAsString(substitutionNode);
55
75
 
56
- statementSubstitution = new Substitution(string, node);
76
+ statementSubstitution = new StatementSubstitution(string, node);
57
77
  }
58
78
 
59
79
  return statementSubstitution;
@@ -81,7 +81,7 @@ export default class StatementForMetavariableSubstitution extends Substitution {
81
81
  statement = Statement.fromStatementNode(statementNode, localContext); ///
82
82
 
83
83
  const metavariableNode = metavariable.getNode(),
84
- string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext);
84
+ string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution);
85
85
 
86
86
  substitution = substitutionFromSubstitution(substitution, localContext);
87
87
 
@@ -91,53 +91,46 @@ export default class StatementForMetavariableSubstitution extends Substitution {
91
91
  }
92
92
  }
93
93
 
94
- function stringFromStatementAndMetavariable(statement, metavariable) {
95
- const statementString = statement.getString(),
96
- metavariableString = metavariable.getString(),
97
- string = `[${statementString} for ${metavariableString}]`;
94
+ function substitutionFromSubstitution(substitution, localContext) {
95
+ if (substitution === null) {
96
+ const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitution(substitution, localContext);
98
97
 
99
- return string;
100
- }
98
+ if (termForVariableSubstitution !== null) {
99
+ substitution = termForVariableSubstitution; ///
100
+ }
101
+ }
101
102
 
103
+ if (substitution === null) {
104
+ const frameForMetavariableSubstitution = FrameForMetavariableSubstitution.fromSubstitution(substitution, localContext);
102
105
 
103
- function substitutionFromSubstitution(substitution, localContextA, localContextB) {
104
- // let substitution = null;
106
+ if (frameForMetavariableSubstitution !== null) {
107
+ substitution = frameForMetavariableSubstitution; ///
108
+ }
109
+ }
105
110
 
106
- debugger
111
+ return substitution;
112
+ }
107
113
 
108
- // if (substitution === null) {
109
- // const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitution(substitutionNode, localContextA, localContextB);
110
- //
111
- // if (termForVariableSubstitution !== null) {
112
- // substitution = termForVariableSubstitution; ///
113
- // }
114
- // }
115
- //
116
- // if (substitution === null) {
117
- // const frameForMetavariableSubstitution = FrameForMetavariableSubstitution.fromSubstitution(substitutionNode, localContextA, localContextB);
118
- //
119
- // if (frameForMetavariableSubstitution !== null) {
120
- // substitution = frameForMetavariableSubstitution; ///
121
- // }
122
- // }
114
+ function stringFromStatementAndMetavariable(statement, metavariable) {
115
+ const statementString = statement.getString(),
116
+ metavariableString = metavariable.getString(),
117
+ string = `[${statementString} for ${metavariableString}]`;
123
118
 
124
- return substitution;
119
+ return string;
125
120
  }
126
121
 
127
- function stringFromStatementMetavariableAndSubstitution(statementNode, metavariableNode, substitution, localContextA, localContextB) {
122
+ function stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution) {
128
123
  let string;
129
124
 
130
- const statementNodeB = statementNode, ///
131
- statementStringB = localContextB.nodeAsString(statementNodeB),
132
- metavariableNodeA = metavariableNode, ///
133
- metavariableStringA = localContextA.nodeAsString(metavariableNodeA);
125
+ const statementString = statement.getString(),
126
+ metavariableString = metavariable.getString();
134
127
 
135
128
  if (substitution === null) {
136
- string = `[${statementStringB} for ${metavariableStringA}]`;
129
+ string = `[${statementString} for ${metavariableString}]`;
137
130
  } else {
138
- const substitutionString = substitution.asString(localContextA, localContextA);
131
+ const substitutionString = substitution.getString();
139
132
 
140
- string = `[${statementStringB} for ${metavariableStringA}${substitutionString}]`;
133
+ string = `[${statementString} for ${metavariableString}${substitutionString}]`;
141
134
  }
142
135
 
143
136
  return string;
@@ -83,7 +83,7 @@ export default class TermForVariableSubstitution extends Substitution {
83
83
  return unifiedWithEquivalence;
84
84
  }
85
85
 
86
- static fromSubstitution(substitution) {
86
+ static fromSubstitution(substitution, localContext) {
87
87
  let termForVariableSubstitution = null;
88
88
 
89
89
  const substitutionNode = substitution.getNode();
@@ -91,30 +91,33 @@ export default class TermForVariableSubstitution extends Substitution {
91
91
  let substitutionTermNode = substitutionTermNodeQuery(substitutionNode);
92
92
 
93
93
  if (substitutionTermNode !== null) {
94
- let termNode = substitutionTermNode; ///
95
-
96
- termNode = stripBracketsFromTerm(termNode); ///
94
+ let termNode;
97
95
 
98
96
  const substitutionVariableNode = substitutionsVariableNodeQuery(substitutionNode),
99
97
  variableNode = substitutionVariableNode; ///
100
98
 
101
- termForVariableSubstitution = new TermForVariableSubstitution(termNode, variableNode);
99
+ termNode = substitutionTermNode; ///
100
+
101
+ termNode = stripBracketsFromTerm(termNode); ///
102
+
103
+ const { Term, Variable } = shim,
104
+ term = Term.fromTermNode(termNode, localContext),
105
+ variable = Variable.fromVariableNode(variableNode, localContext),
106
+ string = stringFromTermAndVariable(term, variable);
107
+
108
+ termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode);
102
109
  }
103
110
 
104
111
  return termForVariableSubstitution;
105
112
  }
106
113
 
107
- static fromTernAndVariable(term, variable, localContext) {
114
+ static fromTernAndVariable(term, variable) {
108
115
  let termNode = term.getNode();
109
116
 
110
117
  termNode = stripBracketsFromTerm(termNode); ///
111
118
 
112
- const { Term } = shim;
113
-
114
- term = Term.fromTermNode(termNode, localContext); ///
115
-
116
- const string = stringFromTermAndVariable(term, variable),
117
- variableNode = variable.getNode(),
119
+ const variableNode = variable.getNode(),
120
+ string = stringFromTermAndVariable(term, variable),
118
121
  termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode);
119
122
 
120
123
  return termForVariableSubstitution;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  import shim from "./shim";
4
- import LocalContext from "./context/local";
5
- import metaLevelUnifier from "./unifier/metaLevel";
6
4
  import SubproofAssertion from "./assertion/subproof";
7
5
  import UnqualifiedStatement from "./statement/unqualified";
8
6
 
@@ -111,26 +109,15 @@ export default class Supposition {
111
109
  unifyStatement(statement, substitutions, localContext) {
112
110
  let statementUnified;
113
111
 
114
- const supposition = this, ///
115
- statementString = statement.getString(),
116
- suppositionStatement = supposition.getStatement(),
117
- suppositionStatementString = suppositionStatement.getString();
118
-
119
- localContext.trace(`Unifying the '${statementString}' statement with the supposition's '${suppositionStatementString}' statement...`);
112
+ const statementString = statement.getString(),
113
+ suppositionString = this.getString();
120
114
 
121
- const statementNode = statement.getNode(),
122
- suppositionStatementNode = suppositionStatement.getNode(),
123
- nodeA = suppositionStatementNode, ///
124
- nodeB = statementNode, ///
125
- fileContextA = this.fileContext, ///
126
- localContextA = LocalContext.fromFileContext(fileContextA),
127
- localContextB = localContext, ///
128
- unified = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
115
+ localContext.trace(`Unifying the '${statementString}' statement with the '${suppositionString}' supposition...`);
129
116
 
130
- statementUnified = unified; ///
117
+ statementUnified = this.unqualifiedStatement.unifyStatement(statement, substitutions, this.fileContext, localContext);
131
118
 
132
119
  if (statementUnified) {
133
- localContext.debug(`...unified the '${statementString}' statement with the supposition's '${suppositionStatementString}' statement.`);
120
+ localContext.debug(`...unified the '${statementString}' statement with the '${suppositionString}' supposition.`);
134
121
  }
135
122
 
136
123
  return statementUnified;
package/src/term.js CHANGED
@@ -8,12 +8,15 @@ import verifyMixins from "./mixins/term/verify";
8
8
  import termAsConstructorVerifier from "./verifier/termAsConstructor";
9
9
 
10
10
  import { objectType } from "./type";
11
- import { nodesQuery } from "./utilities/query"
11
+ import { nodeQuery, nodesQuery } from "./utilities/query"
12
12
  import { termNodeFromTermString } from "./utilities/node";
13
+ import { variableNameFromVariableNode } from "./utilities/name";
13
14
 
14
15
  const { filter } = arrayUtilities;
15
16
 
16
- const variableNodesQuery = nodesQuery("//variable");
17
+ const termNodeQuery = nodeQuery("/*/term[0]"),
18
+ variableNodeQuery = nodeQuery("/term/variable!"),
19
+ variableNodesQuery = nodesQuery("//variable");
17
20
 
18
21
  class Term {
19
22
  constructor(string, node, type) {
@@ -45,12 +48,27 @@ class Term {
45
48
  return matches;
46
49
  }
47
50
 
51
+ getVariable(localContext) {
52
+ let variable = null;
53
+
54
+ const variableNode = variableNodeQuery(this.node);
55
+
56
+ if (variableNode !== null) {
57
+ const variableName = variableNameFromVariableNode(variableNode);
58
+
59
+ variable = localContext.findVariableByVariableName(variableName);
60
+ }
61
+
62
+ return variable;
63
+ }
64
+
48
65
  getVariables(localContext) {
49
66
  const variables = [],
50
67
  variableNodes = variableNodesQuery(this.node);
51
68
 
52
69
  variableNodes.forEach((variableNode) => {
53
- const variable = localContext.findVariableByVariableNode(variableNode),
70
+ const variableName = variableNameFromVariableNode(variableNode),
71
+ variable = localContext.findVariableByVariableName(variableName),
54
72
  variablesIncludesVariable = variables.includes(variable);
55
73
 
56
74
  if (!variablesIncludesVariable) {
@@ -263,6 +281,46 @@ class Term {
263
281
 
264
282
  return term;
265
283
  }
284
+
285
+ static fromDefinedAssertionNode(definedAssertionNode, localContext) {
286
+ let term = null;
287
+
288
+ const termNode = termNodeQuery(definedAssertionNode);
289
+
290
+ if (termNode !== null) {
291
+ const variableNode = variableNodeQuery(termNode);
292
+
293
+ if (variableNode !== null) {
294
+ const node = termNode, ///
295
+ string = localContext.nodeAsString(node),
296
+ type = null;
297
+
298
+ term = new Term(string, node, type);
299
+ }
300
+ }
301
+
302
+ return term;
303
+ }
304
+
305
+ static fromContainedAssertionNode(containedAssertionNode, localContext) {
306
+ let term = null;
307
+
308
+ const termNode = termNodeQuery(containedAssertionNode);
309
+
310
+ if (termNode !== null) {
311
+ const variableNode = variableNodeQuery(termNode);
312
+
313
+ if (variableNode !== null) {
314
+ const node = termNode, ///
315
+ string = localContext.nodeAsString(node),
316
+ type = null;
317
+
318
+ term = new Term(string, node, type);
319
+ }
320
+ }
321
+
322
+ return term;
323
+ }
266
324
  }
267
325
 
268
326
  Object.assign(shim, {
@@ -11,15 +11,15 @@ const termNodeQuery = nodeQuery("/term!"),
11
11
 
12
12
  class IntrinsicLevelUnifier extends Unifier {
13
13
  unify(nodeA, nodeB, substitutions, localContextA, localContextB) {
14
- let unified;
14
+ let unifiedAtIntrinsicLevel;
15
15
 
16
16
  const nonTerminalNodeA = nodeA, ///
17
17
  nonTerminalNodeB = nodeB, ///
18
18
  nonTerminalNodeUnified = this.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions, localContextA, localContextB);
19
19
 
20
- unified = nonTerminalNodeUnified; ///
20
+ unifiedAtIntrinsicLevel = nonTerminalNodeUnified; ///
21
21
 
22
- return unified;
22
+ return unifiedAtIntrinsicLevel;
23
23
  }
24
24
 
25
25
  static maps = [
@@ -16,15 +16,15 @@ const termNodeQuery = nodeQuery("/term!"),
16
16
 
17
17
  class MetaLevelUnifier extends Unifier {
18
18
  unify(nodeA, nodeB, substitutions, localContextA, localContextB) {
19
- let unified;
19
+ let unifiedAtMetaLevel;
20
20
 
21
21
  const nonTerminalNodeA = nodeA, ///
22
22
  nonTerminalNodeB = nodeB, ///
23
23
  nonTerminalNodeUnified = this.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions, localContextA, localContextB);
24
24
 
25
- unified = nonTerminalNodeUnified; ///
25
+ unifiedAtMetaLevel = nonTerminalNodeUnified; ///
26
26
 
27
- return unified;
27
+ return unifiedAtMetaLevel;
28
28
  }
29
29
 
30
30
  static maps = [
@@ -39,30 +39,23 @@ class MetaLevelUnifier extends Unifier {
39
39
  if (matches) {
40
40
  statementUnified = true;
41
41
  } else {
42
- const { Statement } = shim,
43
- statementB = Statement.fromStatementNode(statementNodeB, localContextB),
44
- statementMetavariableNodeA = statementMetavariableNodeQuery(statementNodeA);
42
+ const statementNode = statementNodeA, ///
43
+ statementMetavariableNode = statementMetavariableNodeQuery(statementNode);
45
44
 
46
- if (statementMetavariableNodeA !== null) {
47
- let statement;
48
-
49
- const statementA = Statement.fromStatementNode(statementNodeA, localContextA);
50
-
51
- statement = statementA; ///
52
-
53
- const substitution = statement.getSubstitution();
54
-
55
- statement = statementB; ///
56
-
57
- const localContext = localContextB, ///
58
- metavariableNode = statementMetavariableNodeA, ///
45
+ if (statementMetavariableNode !== null) {
46
+ const { Statement } = shim,
47
+ metavariableNode = statementMetavariableNode, ///
59
48
  metavariableName = metavariableNameFromMetavariableNode(metavariableNode),
60
- metavariable = localContextA.findMetavariableByMetavariableName(metavariableName);
49
+ metavariable = localContextA.findMetavariableByMetavariableName(metavariableName),
50
+ substitution = substitutionA, ///
51
+ localContext = localContextB, ///
52
+ statementNode = statementNodeB, ///
53
+ statement = Statement.fromStatementNode(statementNode, localContext);
61
54
 
62
55
  if (substitution === null) {
63
56
  statementUnified = metavariable.unifyStatement(statement, substitutions, localContext);
64
57
  } else {
65
- const statementUnifiedGivenSubstitution = metavariableNode.unifyStatementGivenSubstitution(statement, substitution, substitutions, localContext);
58
+ const statementUnifiedGivenSubstitution = metavariable.unifyStatementGivenSubstitution(statement, substitution, substitutions, localContext);
66
59
 
67
60
  statementUnified = statementUnifiedGivenSubstitution; ///
68
61
  }
@@ -116,6 +109,8 @@ const metaLevelUnifier = new MetaLevelUnifier();
116
109
  export default metaLevelUnifier;
117
110
 
118
111
  function unifyStatementWithStatement(statementNodeA, statementNodeB, substitutions, localContextA, localContextB) {
112
+ substitutionA = null;
113
+
119
114
  const nonTerminalNodeA = statementNodeA, ///
120
115
  nonTerminalNodeB = statementNodeB, ///
121
116
  nonTerminalNodeAChildNodes = nonTerminalNodeA.getChildNodes(),