occam-verify-cli 0.0.1066 → 0.0.1068
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 +3 -2
- package/lib/assertion/defined.js +3 -2
- package/lib/assignment/judgement.js +3 -3
- package/lib/conclusion.js +8 -4
- package/lib/consequent.js +8 -4
- package/lib/context/file.js +7 -7
- package/lib/context/local.js +12 -25
- package/lib/declaration.js +90 -3
- package/lib/frame.js +109 -48
- package/lib/judgement.js +84 -5
- package/lib/metaType.js +24 -3
- package/lib/metavariable.js +94 -65
- package/lib/mixins/statement/unify.js +1 -1
- package/lib/mixins/statement/verify.js +14 -23
- package/lib/premise.js +14 -6
- package/lib/proofStep.js +22 -13
- package/lib/reference.js +11 -9
- package/lib/rule.js +9 -2
- package/lib/ruleNames.js +5 -1
- package/lib/statement/qualified.js +30 -17
- package/lib/statement/unqualified.js +30 -6
- package/lib/statement.js +20 -9
- package/lib/subproof.js +1 -1
- package/lib/substitution/frameForMetavariable.js +80 -71
- package/lib/substitution/statementForMetavariable.js +118 -56
- package/lib/substitution/termForVariable.js +75 -75
- package/lib/substitution.js +68 -33
- package/lib/substitutions.js +58 -49
- package/lib/supposition.js +8 -4
- package/lib/unifier/intrinsicLevel.js +4 -4
- package/lib/unifier/metaLevel.js +23 -16
- package/lib/unifier/statementWithCombinator.js +2 -2
- package/lib/utilities/node.js +24 -10
- package/lib/utilities/tokens.js +8 -1
- package/lib/variable.js +17 -13
- package/package.json +2 -2
- package/src/assertion/contained.js +3 -1
- package/src/assertion/defined.js +3 -1
- package/src/assignment/judgement.js +3 -4
- package/src/conclusion.js +10 -3
- package/src/consequent.js +10 -3
- package/src/context/file.js +6 -8
- package/src/context/local.js +12 -33
- package/src/declaration.js +57 -4
- package/src/frame.js +149 -90
- package/src/judgement.js +109 -3
- package/src/metaType.js +29 -3
- package/src/metavariable.js +140 -87
- package/src/mixins/statement/unify.js +1 -0
- package/src/mixins/statement/verify.js +16 -28
- package/src/premise.js +19 -5
- package/src/proofStep.js +28 -12
- package/src/reference.js +11 -7
- package/src/rule.js +13 -1
- package/src/ruleNames.js +1 -0
- package/src/statement/qualified.js +38 -21
- package/src/statement/unqualified.js +35 -5
- package/src/statement.js +20 -12
- package/src/subproof.js +0 -1
- package/src/substitution/frameForMetavariable.js +90 -104
- package/src/substitution/statementForMetavariable.js +133 -61
- package/src/substitution/termForVariable.js +83 -113
- package/src/substitution.js +55 -26
- package/src/substitutions.js +59 -47
- package/src/supposition.js +10 -3
- package/src/unifier/intrinsicLevel.js +4 -3
- package/src/unifier/metaLevel.js +42 -24
- package/src/unifier/statementWithCombinator.js +1 -1
- package/src/utilities/node.js +26 -10
- package/src/utilities/tokens.js +7 -0
- package/src/variable.js +20 -11
- package/lib/resolve/complexSubstitutionAgainstSimpleSubstitution.js +0 -62
- package/lib/resolve/substitution.js +0 -27
- package/lib/resolve/substitutions.js +0 -37
- package/lib/unify/metavariableWithFrame.js +0 -40
- package/lib/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +0 -31
- package/lib/verify/declaration.js +0 -83
- package/lib/verify/frame.js +0 -120
- package/lib/verify/judgement.js +0 -88
- package/lib/verify/metavariableGivenMetaType.js +0 -44
- package/src/resolve/complexSubstitutionAgainstSimpleSubstitution.js +0 -79
- package/src/resolve/substitution.js +0 -19
- package/src/resolve/substitutions.js +0 -31
- package/src/unify/metavariableWithFrame.js +0 -40
- package/src/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +0 -27
- package/src/verify/declaration.js +0 -113
- package/src/verify/frame.js +0 -157
- package/src/verify/judgement.js +0 -127
- package/src/verify/metavariableGivenMetaType.js +0 -45
|
@@ -2,36 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
import shim from "../shim";
|
|
4
4
|
import Substitution from "../substitution";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import LocalContext from "../context/local";
|
|
6
|
+
import Substitutions from "../substitutions";
|
|
7
|
+
import metaLevelUnifier from "../unifier/metaLevel";
|
|
7
8
|
|
|
8
9
|
import { stripBracketsFromStatement } from "../utilities/brackets";
|
|
9
10
|
|
|
10
11
|
export default class StatementForMetavariableSubstitution extends Substitution {
|
|
11
|
-
constructor(string,
|
|
12
|
+
constructor(string, statement, metavariable, substitution) {
|
|
12
13
|
super(string);
|
|
13
14
|
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
15
|
+
this.statement = statement;
|
|
16
|
+
this.metavariable = metavariable;
|
|
16
17
|
this.substitution = substitution;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
return this.
|
|
20
|
+
getStatement() {
|
|
21
|
+
return this.statement;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
return this.
|
|
24
|
+
getMetavariable() {
|
|
25
|
+
return this.metavariable;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
getSubstitution() {
|
|
28
29
|
return this.substitution;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
const
|
|
32
|
+
getStatementNode() {
|
|
33
|
+
const statementNode = this.statement.getNode();
|
|
33
34
|
|
|
34
|
-
return
|
|
35
|
+
return statementNode;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getMetavariableNode() {
|
|
39
|
+
const metavariableNode = this.metavariable.getNode();
|
|
40
|
+
|
|
41
|
+
return metavariableNode;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getMetavariableName() {
|
|
45
|
+
const metavariableName = this.metavariable.getName();
|
|
46
|
+
|
|
47
|
+
return metavariableName;
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
isSimple() {
|
|
@@ -40,89 +53,148 @@ export default class StatementForMetavariableSubstitution extends Substitution {
|
|
|
40
53
|
return simple;
|
|
41
54
|
}
|
|
42
55
|
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
resolve(substitutions, localContextA, localContextB) {
|
|
57
|
+
let resolved = false;
|
|
45
58
|
|
|
46
|
-
const
|
|
59
|
+
const substitutionString = this.string;
|
|
47
60
|
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
localContextB.trace(`Resolving the ${substitutionString} substitution...`);
|
|
62
|
+
|
|
63
|
+
const metavariableName = this.getMetavariableName(),
|
|
64
|
+
simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariableName(metavariableName);
|
|
50
65
|
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
if (simpleSubstitution !== null) {
|
|
67
|
+
const substitution = simpleSubstitution, ///
|
|
68
|
+
substitutionResolved = substitution.resolveSubstitution(this.substitution, this.statement, substitutions, localContextA, localContextB);
|
|
69
|
+
|
|
70
|
+
resolved = substitutionResolved; ///
|
|
71
|
+
}
|
|
53
72
|
|
|
54
|
-
|
|
73
|
+
if (resolved) {
|
|
74
|
+
localContextB.debug(`...resolved the ${substitutionString} substitution.`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return resolved;
|
|
55
78
|
}
|
|
56
79
|
|
|
57
|
-
|
|
58
|
-
let
|
|
80
|
+
resolveSubstitution(substitution, statement, substitutions, localContextA, localContextB) {
|
|
81
|
+
let substitutionResolved = false;
|
|
59
82
|
|
|
60
|
-
|
|
83
|
+
const substitutionString = substitution.getString();
|
|
61
84
|
|
|
62
|
-
|
|
85
|
+
localContextB.trace(`Resolving the ${substitutionString} substitution...`);
|
|
63
86
|
|
|
64
|
-
|
|
87
|
+
const substitutionA = substitution; ///
|
|
65
88
|
|
|
66
|
-
|
|
67
|
-
substitution = null,
|
|
68
|
-
metavariableNode = metavariable.getNode(),
|
|
69
|
-
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, statementNode, metavariableNode, substitution);
|
|
89
|
+
substitution = this.unifyStatement(statement, localContextA, localContextB);
|
|
70
90
|
|
|
71
|
-
|
|
91
|
+
if (substitution !== null) {
|
|
92
|
+
substitutions.snapshot();
|
|
93
|
+
|
|
94
|
+
const substitutionTokens = substitution.getSubstitutionTokens(),
|
|
95
|
+
tokens = substitutionTokens; ///
|
|
96
|
+
|
|
97
|
+
localContextB = LocalContext.fromLocalContextAndTokens(localContextB, tokens); ///
|
|
98
|
+
|
|
99
|
+
const substitutionB = substitution, ///
|
|
100
|
+
nodeA = substitutionA.getSubstitutionNode(), ///
|
|
101
|
+
nodeB = substitutionB.getSubstitutionNode(), ///
|
|
102
|
+
unifiedAtMetaLevel = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
|
|
103
|
+
|
|
104
|
+
unifiedAtMetaLevel ?
|
|
105
|
+
substitutions.continue() :
|
|
106
|
+
substitutions.rollback(localContextB);
|
|
107
|
+
|
|
108
|
+
substitutionResolved = unifiedAtMetaLevel; ///
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (substitutionResolved) {
|
|
112
|
+
localContextB.debug(`...resolved the ${substitutionString} substitution.`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return substitutionResolved;
|
|
72
116
|
}
|
|
73
117
|
|
|
74
|
-
|
|
75
|
-
let
|
|
118
|
+
unifyStatement(statement, localContextA, localContextB) {
|
|
119
|
+
let substitution = null;
|
|
76
120
|
|
|
77
|
-
|
|
121
|
+
localContextA = localContextB; ///
|
|
78
122
|
|
|
79
|
-
const
|
|
123
|
+
const substitutions = Substitutions.fromNothing(),
|
|
124
|
+
statementUnified = this.statement.unifyStatement(statement, substitutions, localContextA, localContextB);
|
|
80
125
|
|
|
81
|
-
|
|
126
|
+
if (statementUnified) {
|
|
127
|
+
const substitutionsLength = substitutions.getLength();
|
|
82
128
|
|
|
83
|
-
|
|
84
|
-
|
|
129
|
+
if (substitutionsLength === 1) {
|
|
130
|
+
const firstSubstitution = substitutions.getFirstSubstitution();
|
|
85
131
|
|
|
86
|
-
|
|
132
|
+
substitution = firstSubstitution; ///
|
|
87
133
|
|
|
88
|
-
|
|
134
|
+
substitution.setSubstitutionTokens();
|
|
89
135
|
|
|
90
|
-
|
|
136
|
+
substitution.setSubstitutionNode();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return substitution;
|
|
91
141
|
}
|
|
92
|
-
}
|
|
93
142
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitution(substitution, localContext);
|
|
143
|
+
matchStatementNode(statementNode) {
|
|
144
|
+
statementNode = stripBracketsFromStatement(statementNode); ///
|
|
97
145
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
146
|
+
const statementNodeMatches = this.statement.matchStatementNode(statementNode);
|
|
147
|
+
|
|
148
|
+
return statementNodeMatches;
|
|
101
149
|
}
|
|
102
150
|
|
|
103
|
-
|
|
104
|
-
|
|
151
|
+
matchMetavariableName(metavariableName) { return this.metavariable.matchMetavariableName(metavariableName); }
|
|
152
|
+
|
|
153
|
+
matchSubstitutionNode(substitutionNode) {
|
|
154
|
+
let substitutionNodeMatches;
|
|
105
155
|
|
|
106
|
-
if (
|
|
107
|
-
|
|
156
|
+
if ((substitutionNode === null) && (this.substitution === null)) {
|
|
157
|
+
substitutionNodeMatches = true;
|
|
158
|
+
} else if ((substitutionNode === null) && (this.substitution !== null)) {
|
|
159
|
+
substitutionNodeMatches = false;
|
|
160
|
+
} else if ((substitutionNode !== null) && (this.substitution === null)) {
|
|
161
|
+
substitutionNodeMatches = false;
|
|
162
|
+
} else {
|
|
163
|
+
substitutionNodeMatches = this.substitution.matchSubstitutionNode(substitutionNode);
|
|
108
164
|
}
|
|
165
|
+
|
|
166
|
+
return substitutionNodeMatches;
|
|
109
167
|
}
|
|
110
168
|
|
|
111
|
-
|
|
112
|
-
|
|
169
|
+
matchMetavariableNameAndSubstitutionNode(metavariableName, substitutionNode) {
|
|
170
|
+
const metavariableNameMatches = this.matchMetavariableName(metavariableName),
|
|
171
|
+
substitutionNodeMatches = this.matchSubstitutionNode(substitutionNode),
|
|
172
|
+
metavariableNameAndSubstitutionNodeMatches = (metavariableNameMatches && substitutionNodeMatches);
|
|
113
173
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
metavariableString = metavariable.getString(),
|
|
117
|
-
string = `[${statementString} for ${metavariableString}]`;
|
|
174
|
+
return metavariableNameAndSubstitutionNodeMatches;
|
|
175
|
+
}
|
|
118
176
|
|
|
119
|
-
|
|
177
|
+
static fromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext) {
|
|
178
|
+
let statementNode = statement.getNode();
|
|
179
|
+
|
|
180
|
+
statementNode = stripBracketsFromStatement(statementNode); ///
|
|
181
|
+
|
|
182
|
+
const { Statement } = shim;
|
|
183
|
+
|
|
184
|
+
statement = Statement.fromStatementNode(statementNode, localContext);
|
|
185
|
+
|
|
186
|
+
const string = stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext),
|
|
187
|
+
statementForMetavariableSubstitution = new StatementForMetavariableSubstitution(string, statement, metavariable, substitution);
|
|
188
|
+
|
|
189
|
+
return statementForMetavariableSubstitution;
|
|
190
|
+
}
|
|
120
191
|
}
|
|
121
192
|
|
|
122
|
-
function stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution) {
|
|
193
|
+
function stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext) {
|
|
123
194
|
let string;
|
|
124
195
|
|
|
125
|
-
const
|
|
196
|
+
const statementNode = statement.getNode(),
|
|
197
|
+
statementString = localContext.nodeAsString(statementNode),
|
|
126
198
|
metavariableString = metavariable.getString();
|
|
127
199
|
|
|
128
200
|
if (substitution === null) {
|
|
@@ -134,4 +206,4 @@ function stringFromStatementMetavariableAndSubstitution(statement, metavariable,
|
|
|
134
206
|
}
|
|
135
207
|
|
|
136
208
|
return string;
|
|
137
|
-
}
|
|
209
|
+
}
|
|
@@ -5,18 +5,23 @@ import Substitution from "../substitution";
|
|
|
5
5
|
|
|
6
6
|
import { nodeQuery } from "../utilities/query";
|
|
7
7
|
import { stripBracketsFromTerm } from "../utilities/brackets";
|
|
8
|
+
import { variableNameFromVariableNode } from "../utilities/name";
|
|
9
|
+
import { substitutionNodeFromSubstitutionTokens } from "../utilities/node";
|
|
10
|
+
import { substitutionTokensFromSubstitutionString } from "../utilities/tokens";
|
|
8
11
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
const termNodeQuery = nodeQuery("/substitution/term[0]"),
|
|
13
|
+
variableNodeQuery = nodeQuery("/substitution/term[1]/variable!"),
|
|
14
|
+
termVariableNodeQuery = nodeQuery("/term/variable"),
|
|
15
|
+
substitutionNodeQuery = nodeQuery("/statement/substitution");
|
|
13
16
|
|
|
14
17
|
export default class TermForVariableSubstitution extends Substitution {
|
|
15
|
-
constructor(string, termNode, variableNode) {
|
|
18
|
+
constructor(string, termNode, variableNode, substitutionNode, substitutionTokens) {
|
|
16
19
|
super(string);
|
|
17
20
|
|
|
18
21
|
this.termNode = termNode;
|
|
19
22
|
this.variableNode = variableNode;
|
|
23
|
+
this.substitutionNode = substitutionNode;
|
|
24
|
+
this.substitutionTokens = substitutionTokens;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
getTermNode() {
|
|
@@ -27,29 +32,45 @@ export default class TermForVariableSubstitution extends Substitution {
|
|
|
27
32
|
return this.variableNode;
|
|
28
33
|
}
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
getSubstitutionNode() {
|
|
36
|
+
return this.substitutionNode;
|
|
37
|
+
}
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
getSubstitutionTokens() {
|
|
40
|
+
return this.substitutionTokens;
|
|
41
|
+
}
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
variableNode = transformedVariableNode, ///
|
|
39
|
-
termForVariableSubstitution = new TermForVariableSubstitution(termNode, variableNode);
|
|
43
|
+
getVariableName() {
|
|
44
|
+
const variableName = variableNameFromVariableNode(this.variableNode);
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
return variableName;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setSubstitutionNode() {
|
|
50
|
+
this.substitutionNode = substitutionNodeFromSubstitutionTokens(this.substitutionTokens);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setSubstitutionTokens() {
|
|
54
|
+
const termVariableNode = termVariableNodeQuery(this.termNode),
|
|
55
|
+
termVariableName = variableNameFromVariableNode(termVariableNode),
|
|
56
|
+
variableName = variableNameFromVariableNode(this.variableNode),
|
|
57
|
+
substitutionString = `[${termVariableName} for ${variableName}]`;
|
|
43
58
|
|
|
44
|
-
|
|
59
|
+
this.substitutionTokens = substitutionTokensFromSubstitutionString(substitutionString);
|
|
45
60
|
}
|
|
46
61
|
|
|
47
62
|
isEqualTo(substitution) {
|
|
63
|
+
let equalTo = false;
|
|
64
|
+
|
|
48
65
|
const termNode = substitution.getTermNode(),
|
|
49
|
-
variableNode = substitution.getVariableNode()
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
variableNode = substitution.getVariableNode();
|
|
67
|
+
|
|
68
|
+
if ((termNode !== null) && (variableNode !== null)) {
|
|
69
|
+
const termNodeMatches = this.matchTermNode(termNode),
|
|
70
|
+
variableNodeMatches = this.matchVariableNode(variableNode);
|
|
71
|
+
|
|
72
|
+
equalTo = (termNodeMatches && variableNodeMatches);
|
|
73
|
+
}
|
|
53
74
|
|
|
54
75
|
return equalTo;
|
|
55
76
|
}
|
|
@@ -62,10 +83,34 @@ export default class TermForVariableSubstitution extends Substitution {
|
|
|
62
83
|
return termNodeMatches;
|
|
63
84
|
}
|
|
64
85
|
|
|
65
|
-
|
|
66
|
-
|
|
86
|
+
matchVariableName(variableName) {
|
|
87
|
+
let variableNameMatches;
|
|
88
|
+
|
|
89
|
+
const variableNameA = variableName; ///
|
|
90
|
+
|
|
91
|
+
variableName = variableNameFromVariableNode(this.variableNode);
|
|
92
|
+
|
|
93
|
+
const variableNameB = variableName; ///
|
|
94
|
+
|
|
95
|
+
variableNameMatches = (variableNameA === variableNameB);
|
|
96
|
+
|
|
97
|
+
return variableNameMatches;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
matchSubstitutionNode(substitutionNode) {
|
|
101
|
+
let substitutionNodeMatches;
|
|
102
|
+
|
|
103
|
+
if ((substitutionNode === null) && (this.substitutionNode === null)) {
|
|
104
|
+
substitutionNodeMatches = true;
|
|
105
|
+
} else if ((substitutionNode === null) && (this.substitutionNode !== null)) {
|
|
106
|
+
substitutionNodeMatches = false;
|
|
107
|
+
} else if ((substitutionNode !== null) && (this.substitutionNode === null)) {
|
|
108
|
+
substitutionNodeMatches = false;
|
|
109
|
+
} else {
|
|
110
|
+
substitutionNodeMatches = this.substitutionNode.match(substitutionNode);
|
|
111
|
+
}
|
|
67
112
|
|
|
68
|
-
return
|
|
113
|
+
return substitutionNodeMatches;
|
|
69
114
|
}
|
|
70
115
|
|
|
71
116
|
unifyWithEquivalence(equivalence, substitutions, localContextA, localContextB) {
|
|
@@ -84,122 +129,47 @@ export default class TermForVariableSubstitution extends Substitution {
|
|
|
84
129
|
return unifiedWithEquivalence;
|
|
85
130
|
}
|
|
86
131
|
|
|
87
|
-
static fromSubstitution(substitution, localContext) {
|
|
88
|
-
let termForVariableSubstitution = null;
|
|
89
|
-
|
|
90
|
-
const substitutionNode = substitution.getNode();
|
|
91
|
-
|
|
92
|
-
let substitutionTermNode = substitutionTermNodeQuery(substitutionNode);
|
|
93
|
-
|
|
94
|
-
if (substitutionTermNode !== null) {
|
|
95
|
-
let termNode;
|
|
96
|
-
|
|
97
|
-
const substitutionVariableNode = substitutionsVariableNodeQuery(substitutionNode),
|
|
98
|
-
variableNode = substitutionVariableNode; ///
|
|
99
|
-
|
|
100
|
-
termNode = substitutionTermNode; ///
|
|
101
|
-
|
|
102
|
-
termNode = stripBracketsFromTerm(termNode); ///
|
|
103
|
-
|
|
104
|
-
const { Term, Variable } = shim,
|
|
105
|
-
term = Term.fromTermNode(termNode, localContext),
|
|
106
|
-
variable = Variable.fromVariableNode(variableNode, localContext),
|
|
107
|
-
string = stringFromTermAndVariable(term, variable);
|
|
108
|
-
|
|
109
|
-
termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return termForVariableSubstitution;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
132
|
static fromStatementNode(statementNode, localContext) {
|
|
116
133
|
let termForVariableSubstitution = null;
|
|
117
134
|
|
|
118
135
|
const substitutionNode = substitutionNodeQuery(statementNode);
|
|
119
136
|
|
|
120
137
|
if (substitutionNode !== null) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (substitutionTermNode !== null) {
|
|
124
|
-
let termNode;
|
|
125
|
-
|
|
126
|
-
const substitutionVariableNode = substitutionsVariableNodeQuery(substitutionNode),
|
|
127
|
-
variableNode = substitutionVariableNode; ///
|
|
128
|
-
|
|
129
|
-
termNode = substitutionTermNode; ///
|
|
138
|
+
const termNode = termNodeQuery(substitutionNode),
|
|
139
|
+
variableNode = variableNodeQuery(substitutionNode);
|
|
130
140
|
|
|
141
|
+
if ((termNode !== null) && (variableNode !== null)) {
|
|
131
142
|
const { Term, Variable } = shim,
|
|
132
143
|
term = Term.fromTermNode(termNode, localContext),
|
|
133
144
|
variable = Variable.fromVariableNode(variableNode, localContext),
|
|
134
|
-
string = stringFromTermAndVariable(term, variable)
|
|
145
|
+
string = stringFromTermAndVariable(term, variable, localContext),
|
|
146
|
+
substitutionTokens = localContext.nodeAsTokens(substitutionNode);
|
|
135
147
|
|
|
136
|
-
termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode);
|
|
148
|
+
termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode, substitutionNode, substitutionTokens);
|
|
137
149
|
}
|
|
138
150
|
}
|
|
139
151
|
|
|
140
152
|
return termForVariableSubstitution;
|
|
141
153
|
}
|
|
142
154
|
|
|
143
|
-
static fromTernAndVariable(term, variable) {
|
|
155
|
+
static fromTernAndVariable(term, variable, localContext) {
|
|
144
156
|
let termNode = term.getNode();
|
|
145
157
|
|
|
146
158
|
termNode = stripBracketsFromTerm(termNode); ///
|
|
147
159
|
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
160
|
+
const string = stringFromTermAndVariable(term, variable, localContext),
|
|
161
|
+
variableNode = variable.getNode(),
|
|
162
|
+
substitutionNode = null,
|
|
163
|
+
substitutionTokens = null,
|
|
164
|
+
termForVariableSubstitution = new TermForVariableSubstitution(string, termNode, variableNode, substitutionNode, substitutionTokens);
|
|
151
165
|
|
|
152
166
|
return termForVariableSubstitution;
|
|
153
167
|
}
|
|
154
168
|
}
|
|
155
169
|
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const termVariableNode = termVariableNodeQuery(termNode);
|
|
160
|
-
|
|
161
|
-
if (termVariableNode !== null) {
|
|
162
|
-
const variableNode = termVariableNode; ///
|
|
163
|
-
|
|
164
|
-
substitutions.someSubstitution((substitution) => {
|
|
165
|
-
const substitutionMatchesVariableNode = substitution.matchVariableNode(variableNode);
|
|
166
|
-
|
|
167
|
-
if (substitutionMatchesVariableNode) {
|
|
168
|
-
const termNode = substitution.getTermNode();
|
|
169
|
-
|
|
170
|
-
transformedTermNode = termNode; ////
|
|
171
|
-
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return transformedTermNode;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function transformVariableNode(variableNode, substitutions) {
|
|
181
|
-
let transformedVariableNode = null;
|
|
182
|
-
|
|
183
|
-
substitutions.someSubstitution((substitution) => {
|
|
184
|
-
const variableNodeMatches = substitution.matchVariableNode(variableNode);
|
|
185
|
-
|
|
186
|
-
if (variableNodeMatches) {
|
|
187
|
-
const termNode = substitution.getTermNode(),
|
|
188
|
-
termVariableNode = termVariableNodeQuery(termNode);
|
|
189
|
-
|
|
190
|
-
if (termVariableNode !== null) {
|
|
191
|
-
transformedVariableNode = termVariableNode; ///
|
|
192
|
-
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
return transformedVariableNode;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function stringFromTermAndVariable(term, variable) {
|
|
202
|
-
const termString = term.getString(),
|
|
170
|
+
function stringFromTermAndVariable(term, variable, localContext) {
|
|
171
|
+
const termNode = term.getNode(),
|
|
172
|
+
termString = localContext.nodeAsString(termNode),
|
|
203
173
|
variableString = variable.getString(),
|
|
204
174
|
string = `[${termString} for ${variableString}]`;
|
|
205
175
|
|
package/src/substitution.js
CHANGED
|
@@ -9,36 +9,53 @@ export default class Substitution {
|
|
|
9
9
|
return this.string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
const
|
|
12
|
+
getTermNode() {
|
|
13
|
+
const termNode = null;
|
|
14
14
|
|
|
15
|
-
return
|
|
15
|
+
return termNode;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
complex = !simple;
|
|
18
|
+
getFrameNode() {
|
|
19
|
+
const frameNode = null;
|
|
21
20
|
|
|
22
|
-
return
|
|
21
|
+
return frameNode;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
resolved = simple; ///
|
|
24
|
+
getStatementNode() {
|
|
25
|
+
const statementNode = null;
|
|
28
26
|
|
|
29
|
-
return
|
|
27
|
+
return statementNode;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getSubstitutionNode() {
|
|
31
|
+
const substitutionNode = null;
|
|
32
|
+
|
|
33
|
+
return substitutionNode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getVariableName() {
|
|
37
|
+
const variableName = null;
|
|
38
|
+
|
|
39
|
+
return variableName;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getMetavariableName() {
|
|
43
|
+
const metavariableName = null;
|
|
44
|
+
|
|
45
|
+
return metavariableName;
|
|
30
46
|
}
|
|
31
47
|
|
|
32
|
-
|
|
33
|
-
const
|
|
48
|
+
isSimple() {
|
|
49
|
+
const simple = true;
|
|
34
50
|
|
|
35
|
-
return
|
|
51
|
+
return simple;
|
|
36
52
|
}
|
|
37
53
|
|
|
38
|
-
|
|
39
|
-
const
|
|
54
|
+
isComplex() {
|
|
55
|
+
const simple = this.isSimple(),
|
|
56
|
+
complex = !simple;
|
|
40
57
|
|
|
41
|
-
return
|
|
58
|
+
return complex;
|
|
42
59
|
}
|
|
43
60
|
|
|
44
61
|
isEqualTo(substitution) {
|
|
@@ -47,16 +64,22 @@ export default class Substitution {
|
|
|
47
64
|
return equalTo;
|
|
48
65
|
}
|
|
49
66
|
|
|
67
|
+
resolve(substitutions, localContext) {
|
|
68
|
+
const resolved = true;
|
|
69
|
+
|
|
70
|
+
return resolved;
|
|
71
|
+
}
|
|
72
|
+
|
|
50
73
|
matchTermNode(termNode) {
|
|
51
74
|
const termNodeMatches = false;
|
|
52
75
|
|
|
53
76
|
return termNodeMatches;
|
|
54
77
|
}
|
|
55
78
|
|
|
56
|
-
|
|
57
|
-
const
|
|
79
|
+
matchFrameNode(frameNode) {
|
|
80
|
+
const frameNodeMatches = false;
|
|
58
81
|
|
|
59
|
-
return
|
|
82
|
+
return frameNodeMatches;
|
|
60
83
|
}
|
|
61
84
|
|
|
62
85
|
matchStatementNode(statementNode) {
|
|
@@ -65,16 +88,22 @@ export default class Substitution {
|
|
|
65
88
|
return statementNodeMatches;
|
|
66
89
|
}
|
|
67
90
|
|
|
68
|
-
|
|
69
|
-
const
|
|
91
|
+
matchVariableName(variableName) {
|
|
92
|
+
const variableNameMatches = false;
|
|
93
|
+
|
|
94
|
+
return variableNameMatches;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
matchMetavariableName(metavariableName) {
|
|
98
|
+
const metavariableNameMatches = false;
|
|
70
99
|
|
|
71
|
-
return
|
|
100
|
+
return metavariableNameMatches;
|
|
72
101
|
}
|
|
73
102
|
|
|
74
|
-
|
|
75
|
-
const
|
|
103
|
+
matchMetavariableNameAndSubstitutionNode(metavariableName, substitutionNode) {
|
|
104
|
+
const metavariableNameAndSubstitutionNodeMatches = false;
|
|
76
105
|
|
|
77
|
-
return
|
|
106
|
+
return metavariableNameAndSubstitutionNodeMatches;
|
|
78
107
|
}
|
|
79
108
|
|
|
80
109
|
unifyWithEquivalence(equivalence, substitutions, localContextA, localContextB) {
|