occam-verify-cli 0.0.1065 → 0.0.1067
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/assertion/contained.js +2 -1
- package/lib/assertion/defined.js +2 -1
- package/lib/combinator/bracketed.js +135 -0
- package/lib/conclusion.js +6 -2
- package/lib/consequent.js +6 -2
- package/lib/constants.js +3 -3
- package/lib/constructor/bracketed.js +30 -11
- package/lib/context/file.js +45 -9
- package/lib/context/local.js +67 -28
- package/lib/metavariable.js +15 -54
- package/lib/mixins/statement/unify.js +18 -3
- package/lib/mixins/statement/verify.js +2 -11
- package/lib/premise.js +6 -2
- package/lib/proofStep.js +22 -13
- package/lib/rule.js +6 -2
- package/lib/ruleNames.js +1 -5
- package/lib/statement/qualified.js +30 -17
- package/lib/statement/unqualified.js +5 -5
- package/lib/statement.js +41 -24
- package/lib/subproof.js +1 -1
- package/lib/substitution/frameForMetavariable.js +44 -21
- package/lib/substitution/statementForMetavariable.js +93 -54
- package/lib/substitution/termForVariable.js +38 -21
- package/lib/substitution.js +48 -13
- package/lib/substitutions.js +22 -19
- package/lib/supposition.js +6 -2
- package/lib/unifier/metaLevel.js +14 -12
- package/lib/unify/metavariableWithFrame.js +2 -2
- package/lib/utilities/brackets.js +5 -10
- package/lib/utilities/node.js +29 -15
- package/lib/utilities/string.js +34 -16
- package/lib/utilities/tokens.js +16 -8
- package/lib/variable.js +10 -10
- package/package.json +2 -2
- package/src/assertion/contained.js +2 -0
- package/src/assertion/defined.js +2 -0
- package/src/combinator/bracketed.js +49 -0
- package/src/conclusion.js +8 -1
- package/src/consequent.js +8 -1
- package/src/constants.js +2 -2
- package/src/constructor/bracketed.js +32 -9
- package/src/context/file.js +41 -13
- package/src/context/local.js +71 -35
- package/src/metavariable.js +24 -74
- package/src/mixins/statement/unify.js +25 -2
- package/src/mixins/statement/verify.js +1 -14
- package/src/premise.js +8 -1
- package/src/proofStep.js +28 -12
- package/src/rule.js +7 -1
- package/src/ruleNames.js +0 -1
- package/src/statement/qualified.js +38 -21
- package/src/statement/unqualified.js +4 -4
- package/src/statement.js +62 -41
- package/src/subproof.js +0 -1
- package/src/substitution/frameForMetavariable.js +62 -32
- package/src/substitution/statementForMetavariable.js +102 -61
- package/src/substitution/termForVariable.js +52 -32
- package/src/substitution.js +40 -11
- package/src/substitutions.js +32 -25
- package/src/supposition.js +8 -1
- package/src/unifier/metaLevel.js +23 -18
- package/src/unify/metavariableWithFrame.js +2 -2
- package/src/utilities/brackets.js +2 -3
- package/src/utilities/node.js +30 -22
- package/src/utilities/string.js +39 -23
- package/src/utilities/tokens.js +17 -8
- package/src/variable.js +7 -7
- package/lib/node/statement/bracketed.js +0 -16
- package/lib/node/statement/combinator/bracketed.js +0 -25
- package/lib/node/term/bracketed.js +0 -16
- package/lib/node/term/constructor/bracketed.js +0 -25
- package/lib/ocmbinator/bracketed.js +0 -157
- package/lib/resolve/complexSubstitutionAgainstSimpleSubstitution.js +0 -62
- package/lib/resolve/substitution.js +0 -27
- package/lib/resolve/substitutions.js +0 -37
- package/lib/substitution/statement.js +0 -163
- package/lib/verifier/substitution.js +0 -161
- package/src/node/statement/bracketed.js +0 -9
- package/src/node/statement/combinator/bracketed.js +0 -10
- package/src/node/term/bracketed.js +0 -9
- package/src/node/term/constructor/bracketed.js +0 -10
- package/src/ocmbinator/bracketed.js +0 -26
- package/src/resolve/complexSubstitutionAgainstSimpleSubstitution.js +0 -79
- package/src/resolve/substitution.js +0 -19
- package/src/resolve/substitutions.js +0 -31
- package/src/substitution/statement.js +0 -81
- package/src/verifier/substitution.js +0 -75
package/src/statement.js
CHANGED
|
@@ -9,17 +9,20 @@ import statementAsCombinatorVerifier from "./verifier/statementAsCombinator";
|
|
|
9
9
|
|
|
10
10
|
import { nodeQuery, nodesQuery } from "./utilities/query";
|
|
11
11
|
import { STATEMENT_META_TYPE_NAME } from "./metaTypeNames";
|
|
12
|
-
import {
|
|
12
|
+
import { statementTokensFromUnqualifiedStatementTokens, unqualifiedStatementTokensFromUnqualifiedStatementString } from "./utilities/tokens";
|
|
13
|
+
import { statementNodeFromUnqualifiedStatementNode,
|
|
14
|
+
unqualifiedStatementStringFromStatementString,
|
|
15
|
+
unqualifiedStatementNodeFromUnqualifiedStatementTokens } from "./utilities/node";
|
|
13
16
|
|
|
14
17
|
const statementNodeQuery = nodeQuery("/*//statement"),
|
|
15
|
-
substitutionNodeQuery = nodeQuery("/statement/substitution"),
|
|
16
18
|
statementVariableNodesQuery = nodesQuery("/statement//variable"),
|
|
17
19
|
statementMetavariableNodesQuery = nodesQuery("/statement//metavariable");
|
|
18
20
|
|
|
19
21
|
class Statement {
|
|
20
|
-
constructor(string, node) {
|
|
22
|
+
constructor(string, node, tokens) {
|
|
21
23
|
this.string = string;
|
|
22
24
|
this.node = node;
|
|
25
|
+
this.tokens = tokens;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
getString() {
|
|
@@ -30,6 +33,10 @@ class Statement {
|
|
|
30
33
|
return this.node;
|
|
31
34
|
}
|
|
32
35
|
|
|
36
|
+
getTokens() {
|
|
37
|
+
return this.tokens;
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
isEqualTo(statement) {
|
|
34
41
|
const node = statement.getNode(),
|
|
35
42
|
matches = this.node.match(node),
|
|
@@ -44,7 +51,7 @@ class Statement {
|
|
|
44
51
|
const variableString = variable.getString(),
|
|
45
52
|
statementString = this.string; ///
|
|
46
53
|
|
|
47
|
-
localContext.trace(`
|
|
54
|
+
localContext.trace(`Is the '${variableString}' variable contained in the '${statementString}' statement...`);
|
|
48
55
|
|
|
49
56
|
const variableNode = variable.getNode(),
|
|
50
57
|
statementNode = this.node,
|
|
@@ -59,7 +66,7 @@ class Statement {
|
|
|
59
66
|
});
|
|
60
67
|
|
|
61
68
|
if (variableContained) {
|
|
62
|
-
localContext.debug(`...the '${variableString}' variable is contained in
|
|
69
|
+
localContext.debug(`...the '${variableString}' variable is contained in the '${statementString}' statement.`);
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
return variableContained;
|
|
@@ -71,7 +78,7 @@ class Statement {
|
|
|
71
78
|
const metavariableString = metavariable.getString(),
|
|
72
79
|
statementString = this.string; ///
|
|
73
80
|
|
|
74
|
-
localContext.trace(`
|
|
81
|
+
localContext.trace(`Is the '${metavariableString}' metavariable contained in the '${statementString}' statement...`);
|
|
75
82
|
|
|
76
83
|
const metavariableNode = metavariable.getNode(),
|
|
77
84
|
statementNode = this.node,
|
|
@@ -86,12 +93,44 @@ class Statement {
|
|
|
86
93
|
});
|
|
87
94
|
|
|
88
95
|
if (metavariableContained) {
|
|
89
|
-
localContext.debug(`...the '${metavariableString}' metavariable is contained in
|
|
96
|
+
localContext.debug(`...the '${metavariableString}' metavariable is contained in the '${statementString}' statement.`);
|
|
90
97
|
}
|
|
91
98
|
|
|
92
99
|
return metavariableContained;
|
|
93
100
|
}
|
|
94
101
|
|
|
102
|
+
matchStatementNode(statementNode) {
|
|
103
|
+
const statementNodeMatches = this.node.match(statementNode);
|
|
104
|
+
|
|
105
|
+
return statementNodeMatches;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
unifyStatement(statement, substitutions, localContextA, localContextB) {
|
|
109
|
+
let statementUnified;
|
|
110
|
+
|
|
111
|
+
const statementA = this, ///
|
|
112
|
+
statementB = statement, ///
|
|
113
|
+
statementAString = statementA.getString(),
|
|
114
|
+
statementBString = statementB.getString();
|
|
115
|
+
|
|
116
|
+
localContextB.trace(`Unifying the '${statementBString}' statement with the '${statementAString}' statement...`);
|
|
117
|
+
|
|
118
|
+
const statementANode = statementA.getNode(),
|
|
119
|
+
statementBNode = statementB.getNode(),
|
|
120
|
+
nodeA = statementANode, ///
|
|
121
|
+
nodeB = statementBNode; ///
|
|
122
|
+
|
|
123
|
+
localContextA = LocalContext.fromLocalContextAndTokens(localContextA, this.tokens);
|
|
124
|
+
|
|
125
|
+
const unifiedAtMetaLevel = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
|
|
126
|
+
|
|
127
|
+
statementUnified = unifiedAtMetaLevel; ///
|
|
128
|
+
|
|
129
|
+
localContextB.debug(`...unified the '${statementBString}' statement with the '${statementAString}' statement.`);
|
|
130
|
+
|
|
131
|
+
return statementUnified;
|
|
132
|
+
}
|
|
133
|
+
|
|
95
134
|
verify(assignments, stated, localContext) {
|
|
96
135
|
let verified = false;
|
|
97
136
|
|
|
@@ -169,32 +208,6 @@ class Statement {
|
|
|
169
208
|
return verifiedGivenMetaType;
|
|
170
209
|
}
|
|
171
210
|
|
|
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
|
-
|
|
198
211
|
toJSON() {
|
|
199
212
|
const string = this.string, ///
|
|
200
213
|
json = {
|
|
@@ -209,9 +222,14 @@ class Statement {
|
|
|
209
222
|
statementString = string, ///
|
|
210
223
|
lexer = fileContext.getLexer(),
|
|
211
224
|
parser = fileContext.getParser(),
|
|
212
|
-
|
|
225
|
+
unqualifiedStatementString = unqualifiedStatementStringFromStatementString(statementString),
|
|
226
|
+
unqualifiedStatementTokens = unqualifiedStatementTokensFromUnqualifiedStatementString(unqualifiedStatementString, lexer),
|
|
227
|
+
unqualifiedStatementNode = unqualifiedStatementNodeFromUnqualifiedStatementTokens(unqualifiedStatementTokens, parser),
|
|
228
|
+
statementTokens = statementTokensFromUnqualifiedStatementTokens(unqualifiedStatementTokens),
|
|
229
|
+
statementNode = statementNodeFromUnqualifiedStatementNode(unqualifiedStatementNode),
|
|
213
230
|
node = statementNode, ///
|
|
214
|
-
|
|
231
|
+
tokens = statementTokens, ///
|
|
232
|
+
statement = new Statement(string, node, tokens);
|
|
215
233
|
|
|
216
234
|
return statement;
|
|
217
235
|
}
|
|
@@ -221,9 +239,10 @@ class Statement {
|
|
|
221
239
|
|
|
222
240
|
if (statementNode !== null) {
|
|
223
241
|
const node = statementNode, ///
|
|
224
|
-
|
|
242
|
+
tokens = localContext.nodeAsTokens(node),
|
|
243
|
+
string = localContext.tokensAsString(tokens);
|
|
225
244
|
|
|
226
|
-
statement = new Statement(string, node);
|
|
245
|
+
statement = new Statement(string, node, tokens);
|
|
227
246
|
}
|
|
228
247
|
|
|
229
248
|
return statement;
|
|
@@ -232,8 +251,9 @@ class Statement {
|
|
|
232
251
|
static fromDefinedAssertionNode(definedAssertionNode, localContext) {
|
|
233
252
|
const statementNode = statementNodeQuery(definedAssertionNode),
|
|
234
253
|
node = statementNode, ///
|
|
235
|
-
|
|
236
|
-
|
|
254
|
+
tokens = localContext.nodeAsTokens(node),
|
|
255
|
+
string = localContext.tokensAsString(tokens),
|
|
256
|
+
statement = new Statement(string, node, tokens);
|
|
237
257
|
|
|
238
258
|
return statement;
|
|
239
259
|
}
|
|
@@ -241,8 +261,9 @@ class Statement {
|
|
|
241
261
|
static fromContainedAssertionNode(containedAssertionNode, localContext) {
|
|
242
262
|
const statementNode = statementNodeQuery(containedAssertionNode),
|
|
243
263
|
node = statementNode, ///
|
|
244
|
-
|
|
245
|
-
|
|
264
|
+
tokens = localContext.nodeAsTokens(node),
|
|
265
|
+
string = localContext.tokensAsString(tokens),
|
|
266
|
+
statement = new Statement(string, node, tokens);
|
|
246
267
|
|
|
247
268
|
return statement;
|
|
248
269
|
}
|
package/src/subproof.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import shim from "../shim";
|
|
3
4
|
import Substitution from "../substitution";
|
|
4
5
|
|
|
5
6
|
import { nodeQuery } from "../utilities/query";
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const substitutionNodeQuery = nodeQuery("/statement/substitution"),
|
|
9
|
+
substitutionFrameNodeQuery = nodeQuery("/substitution/frame!"),
|
|
8
10
|
frameMetavariableNodeQuery = nodeQuery("/frame/metavariable!"),
|
|
9
11
|
substitutionMetavariableNodeQuery = nodeQuery("/substitution/metavariable!");
|
|
10
12
|
|
|
11
13
|
export default class FrameForMetavariableSubstitution extends Substitution {
|
|
12
|
-
constructor(string, frameNode, metavariableNode) {
|
|
14
|
+
constructor(string, frameNode, metavariableNode, substitutionNode) {
|
|
13
15
|
super(string);
|
|
14
16
|
|
|
15
17
|
this.frameNode = frameNode;
|
|
16
18
|
this.metavariableNode = metavariableNode;
|
|
19
|
+
this.substitutionNode = substitutionNode;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
getFrameNode() {
|
|
@@ -24,10 +27,8 @@ export default class FrameForMetavariableSubstitution extends Substitution {
|
|
|
24
27
|
return this.metavariableNode;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return node;
|
|
30
|
+
getSubstitutionNode() {
|
|
31
|
+
return this.substitutionNode;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
transformed(substitutions) {
|
|
@@ -37,9 +38,11 @@ export default class FrameForMetavariableSubstitution extends Substitution {
|
|
|
37
38
|
transformedMetavariableNode = transformMetavariableNode(this.metavariableNode, substitutions);
|
|
38
39
|
|
|
39
40
|
if ((transformedFrameNode !== null) && (transformedMetavariableNode !== null)) {
|
|
40
|
-
const
|
|
41
|
+
const string = null, ///
|
|
42
|
+
frameNode = transformedFrameNode, ///
|
|
41
43
|
metavariableNode = transformedMetavariableNode, ///
|
|
42
|
-
|
|
44
|
+
substitutionNode = null,
|
|
45
|
+
frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode, substitutionNode);
|
|
43
46
|
|
|
44
47
|
transformedSubstitution = frameForMetavariableSubstitution; ///
|
|
45
48
|
}
|
|
@@ -48,11 +51,17 @@ export default class FrameForMetavariableSubstitution extends Substitution {
|
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
isEqualTo(substitution) {
|
|
54
|
+
let equalTo = false;
|
|
55
|
+
|
|
51
56
|
const frameNode = substitution.getFrameNode(),
|
|
52
|
-
metavariableNode = substitution.getMetavariableNode()
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
metavariableNode = substitution.getMetavariableNode();
|
|
58
|
+
|
|
59
|
+
if ((frameNode !== null) && (metavariableNode !== null)) {
|
|
60
|
+
const frameNodeMatches = this.matchFrameNode(frameNode),
|
|
61
|
+
metavariableNodeMatches = this.matchMetavariableNode(metavariableNode);
|
|
62
|
+
|
|
63
|
+
equalTo = (frameNodeMatches && metavariableNodeMatches);
|
|
64
|
+
}
|
|
56
65
|
|
|
57
66
|
return equalTo;
|
|
58
67
|
}
|
|
@@ -69,29 +78,52 @@ export default class FrameForMetavariableSubstitution extends Substitution {
|
|
|
69
78
|
return metavariableNodeMatches;
|
|
70
79
|
}
|
|
71
80
|
|
|
72
|
-
|
|
81
|
+
matchSubstitutionNode(substitutionNode) {
|
|
82
|
+
const substitutionNodeMatches = this.substitutionNode.match(substitutionNode);
|
|
83
|
+
|
|
84
|
+
return substitutionNodeMatches;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
matchMetavariableNodeAndSubstitutionNode(metavariableNode, substitutionNode) {
|
|
88
|
+
const metavariableNodeMatches = this.matchMetavariableNode(metavariableNode),
|
|
89
|
+
substitutionNodeMatches = this.matchSubstitutionNode(substitutionNode),
|
|
90
|
+
metavariableNodeAndSubstitutionNodeMatches = (metavariableNodeMatches && substitutionNodeMatches);
|
|
91
|
+
|
|
92
|
+
return metavariableNodeAndSubstitutionNodeMatches;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static fromStatementNode(statementNode, localContext) {
|
|
73
96
|
let frameForMetavariableSubstitution = null;
|
|
74
97
|
|
|
75
|
-
const substitutionNode =
|
|
76
|
-
|
|
98
|
+
const substitutionNode = substitutionNodeQuery(statementNode);
|
|
99
|
+
|
|
100
|
+
if (substitutionNode !== null) {
|
|
101
|
+
let substitutionFrameNode = substitutionFrameNodeQuery(substitutionNode);
|
|
77
102
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
103
|
+
if (substitutionFrameNode !== null) {
|
|
104
|
+
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);
|
|
83
111
|
|
|
84
|
-
frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode);
|
|
112
|
+
frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode, substitutionNode);
|
|
113
|
+
}
|
|
85
114
|
}
|
|
86
115
|
|
|
87
116
|
return frameForMetavariableSubstitution;
|
|
88
117
|
}
|
|
89
118
|
|
|
90
|
-
static
|
|
91
|
-
const string =
|
|
92
|
-
|
|
119
|
+
static fromFrameAndMetavariable(frame, metavariable, localContext) {
|
|
120
|
+
const string = stringFromFrameAndMetavariable(frame, metavariable, localContext),
|
|
121
|
+
frameNode = frame.getNode(),
|
|
122
|
+
metavariableNode = metavariable.getNode(),
|
|
123
|
+
substitutionNode = null,
|
|
124
|
+
statementForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode, substitutionNode);
|
|
93
125
|
|
|
94
|
-
return
|
|
126
|
+
return statementForMetavariableSubstitution;
|
|
95
127
|
}
|
|
96
128
|
}
|
|
97
129
|
|
|
@@ -140,13 +172,11 @@ function transformMetavariableNode(metavariableNode, substitutions) {
|
|
|
140
172
|
return transformedMetavariableNode;
|
|
141
173
|
}
|
|
142
174
|
|
|
143
|
-
function
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
string = `[${frameStringB} for ${metavariableStringA}]`;
|
|
175
|
+
function stringFromFrameAndMetavariable(frame, metavariable, localContext) {
|
|
176
|
+
const frameNode = frame.getNode(),
|
|
177
|
+
frameString = localContext.nodeAsString(frameNode),
|
|
178
|
+
metavariableString = metavariable.getString(),
|
|
179
|
+
string = `[[${frameString}] for [${metavariableString}]]`;
|
|
149
180
|
|
|
150
181
|
return string;
|
|
151
182
|
}
|
|
152
|
-
|
|
@@ -2,36 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
import shim from "../shim";
|
|
4
4
|
import Substitution from "../substitution";
|
|
5
|
-
import
|
|
6
|
-
import FrameForMetavariableSubstitution from "../substitution/frameForMetavariable";
|
|
5
|
+
import Substitutions from "../substitutions";
|
|
7
6
|
|
|
8
7
|
import { stripBracketsFromStatement } from "../utilities/brackets";
|
|
9
8
|
|
|
10
9
|
export default class StatementForMetavariableSubstitution extends Substitution {
|
|
11
|
-
constructor(string,
|
|
10
|
+
constructor(string, statement, metavariable, substitution) {
|
|
12
11
|
super(string);
|
|
13
12
|
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
13
|
+
this.statement = statement;
|
|
14
|
+
this.metavariable = metavariable;
|
|
16
15
|
this.substitution = substitution;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
return this.
|
|
18
|
+
getStatement() {
|
|
19
|
+
return this.statement;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
return this.
|
|
22
|
+
getMetavariable() {
|
|
23
|
+
return this.metavariable;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
getSubstitution() {
|
|
28
27
|
return this.substitution;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
const
|
|
30
|
+
getStatementNode() {
|
|
31
|
+
const statementNode = this.statement.getNode();
|
|
32
|
+
|
|
33
|
+
return statementNode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getMetavariableNode() {
|
|
37
|
+
const metavariableNode = this.metavariable.getNode();
|
|
33
38
|
|
|
34
|
-
return
|
|
39
|
+
return metavariableNode;
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
isSimple() {
|
|
@@ -40,89 +45,125 @@ export default class StatementForMetavariableSubstitution extends Substitution {
|
|
|
40
45
|
return simple;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
resolve(substitutions, localContext) {
|
|
49
|
+
let resolved = false;
|
|
45
50
|
|
|
46
|
-
const
|
|
51
|
+
const substitutionString = this.string;
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
localContext.trace(`Resolving the ${substitutionString} substitution...`);
|
|
54
|
+
|
|
55
|
+
const metavariableNode = this.getMetavariableNode(),
|
|
56
|
+
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariableNode(metavariableNode);
|
|
57
|
+
|
|
58
|
+
if (simpleSubstitution !== null) {
|
|
59
|
+
const substitution = simpleSubstitution, ///
|
|
60
|
+
substitutionResolved = substitution.resolveSubstitution(this.substitution, this.statement, substitutions, localContext);
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
resolved = substitutionResolved; ///
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (resolved) {
|
|
66
|
+
localContext.debug(`...resolved the ${substitutionString} substitution.`);
|
|
67
|
+
}
|
|
53
68
|
|
|
54
|
-
return
|
|
69
|
+
return resolved;
|
|
55
70
|
}
|
|
56
71
|
|
|
57
|
-
|
|
58
|
-
let
|
|
72
|
+
resolveSubstitution(substitution, statement, substitutions, localContext) {
|
|
73
|
+
let substitutionResolved = false;
|
|
59
74
|
|
|
60
|
-
|
|
75
|
+
const substitutionString = substitution.getString();
|
|
61
76
|
|
|
62
|
-
|
|
77
|
+
localContext.trace(`Resolving the ${substitutionString} substitution...`);
|
|
63
78
|
|
|
64
|
-
|
|
79
|
+
const transformedSubstitution = substitution.transformed(substitutions, localContext);
|
|
65
80
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
metavariableNode = metavariable.getNode(),
|
|
69
|
-
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, statementNode, metavariableNode, substitution);
|
|
81
|
+
if (transformedSubstitution !== null) {
|
|
82
|
+
const transformedSubstitutionString = transformedSubstitution.getString();
|
|
70
83
|
|
|
71
|
-
|
|
72
|
-
}
|
|
84
|
+
localContext.trace(`Transformed the substitution to ${transformedSubstitutionString}...`);
|
|
73
85
|
|
|
74
|
-
|
|
75
|
-
let statementNode = statement.getNode();
|
|
86
|
+
substitutions = Substitutions.fromNothing(); ///
|
|
76
87
|
|
|
77
|
-
|
|
88
|
+
const localContextA = localContext, ///
|
|
89
|
+
localContextB = localContext, ///
|
|
90
|
+
statementUnified = this.statement.unifyStatement(statement, substitutions, localContextA, localContextB);
|
|
78
91
|
|
|
79
|
-
|
|
92
|
+
if (statementUnified) {
|
|
93
|
+
const substitutionsLength = substitutions.getLength();
|
|
80
94
|
|
|
81
|
-
|
|
95
|
+
if (substitutionsLength === 1) {
|
|
96
|
+
const firstSubstitution = substitutions.getFirstSubstitution(),
|
|
97
|
+
substitution = firstSubstitution, ///
|
|
98
|
+
substitutionEqualToTransformedSubstitution = substitution.isEqualTo(transformedSubstitution);
|
|
82
99
|
|
|
83
|
-
|
|
84
|
-
|
|
100
|
+
substitutionResolved = substitutionEqualToTransformedSubstitution; ///
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
85
104
|
|
|
86
|
-
|
|
105
|
+
if (substitutionResolved) {
|
|
106
|
+
localContext.debug(`...resolved the ${substitutionString} substitution.`);
|
|
107
|
+
}
|
|
87
108
|
|
|
88
|
-
|
|
109
|
+
return substitutionResolved;
|
|
110
|
+
}
|
|
89
111
|
|
|
90
|
-
|
|
112
|
+
matchStatementNode(statementNode) {
|
|
113
|
+
statementNode = stripBracketsFromStatement(statementNode); ///
|
|
114
|
+
|
|
115
|
+
const statementNodeMatches = this.statement.matchStatementNode(statementNode);
|
|
116
|
+
|
|
117
|
+
return statementNodeMatches;
|
|
91
118
|
}
|
|
92
|
-
}
|
|
93
119
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
120
|
+
matchMetavariableNode(metavariableNode) { return this.metavariable.matchMetavariableNode(metavariableNode); }
|
|
121
|
+
|
|
122
|
+
matchSubstitutionNode(substitutionNode) {
|
|
123
|
+
let substitutionNodeMatches;
|
|
97
124
|
|
|
98
|
-
if (
|
|
99
|
-
|
|
125
|
+
if ((substitutionNode === null) && (this.substitution === null)) {
|
|
126
|
+
substitutionNodeMatches = true;
|
|
127
|
+
} else if ((substitutionNode === null) && (this.substitution !== null)) {
|
|
128
|
+
substitutionNodeMatches = false;
|
|
129
|
+
} else if ((substitutionNode !== null) && (this.substitution === null)) {
|
|
130
|
+
substitutionNodeMatches = false;
|
|
131
|
+
} else {
|
|
132
|
+
substitutionNodeMatches = this.substitution.matchSubstitutionNode(substitutionNode);
|
|
100
133
|
}
|
|
134
|
+
|
|
135
|
+
return substitutionNodeMatches;
|
|
101
136
|
}
|
|
102
137
|
|
|
103
|
-
|
|
104
|
-
const
|
|
138
|
+
matchMetavariableNodeAndSubstitutionNode(metavariableNode, substitutionNode) {
|
|
139
|
+
const metavariableNodeMatches = this.matchMetavariableNode(metavariableNode),
|
|
140
|
+
substitutionNodeMatches = this.matchSubstitutionNode(substitutionNode),
|
|
141
|
+
metavariableNodeAndSubstitutionNodeMatches = (metavariableNodeMatches && substitutionNodeMatches);
|
|
105
142
|
|
|
106
|
-
|
|
107
|
-
substitution = frameForMetavariableSubstitution; ///
|
|
108
|
-
}
|
|
143
|
+
return metavariableNodeAndSubstitutionNodeMatches;
|
|
109
144
|
}
|
|
110
145
|
|
|
111
|
-
|
|
112
|
-
|
|
146
|
+
static fromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext) {
|
|
147
|
+
let statementNode = statement.getNode();
|
|
113
148
|
|
|
114
|
-
|
|
115
|
-
const statementString = statement.getString(),
|
|
116
|
-
metavariableString = metavariable.getString(),
|
|
117
|
-
string = `[${statementString} for ${metavariableString}]`;
|
|
149
|
+
statementNode = stripBracketsFromStatement(statementNode); ///
|
|
118
150
|
|
|
119
|
-
|
|
151
|
+
const { Statement } = shim;
|
|
152
|
+
|
|
153
|
+
statement = Statement.fromStatementNode(statementNode, localContext);
|
|
154
|
+
|
|
155
|
+
const string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext),
|
|
156
|
+
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, statement, metavariable, substitution);
|
|
157
|
+
|
|
158
|
+
return statementForMetavariableSubstitution;
|
|
159
|
+
}
|
|
120
160
|
}
|
|
121
161
|
|
|
122
|
-
function stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution) {
|
|
162
|
+
function stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext) {
|
|
123
163
|
let string;
|
|
124
164
|
|
|
125
|
-
const
|
|
165
|
+
const statementNode = statement.getNode(),
|
|
166
|
+
statementString = localContext.nodeAsString(statementNode),
|
|
126
167
|
metavariableString = metavariable.getString();
|
|
127
168
|
|
|
128
169
|
if (substitution === null) {
|