occam-verify-cli 0.0.1120 → 0.0.1121
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/dom/metavariable.js +118 -41
- package/lib/dom/reference.js +8 -1
- package/lib/dom/statement.js +6 -1
- package/lib/dom/term.js +4 -3
- package/lib/mixins/proofStep/unify.js +15 -1
- package/lib/nodeAndTokens/substitution/reference.js +158 -0
- package/lib/substitution/reference.js +164 -0
- package/lib/substitution/statement.js +5 -5
- package/lib/substitution/term.js +2 -3
- package/lib/substitution.js +15 -1
- package/lib/unifier/intrinsicLevel.js +145 -0
- package/lib/unifier/metaLevel.js +17 -2
- package/lib/unifier/metavariable.js +2 -2
- package/lib/utilities/brackets.js +31 -1
- package/lib/utilities/unification.js +13 -1
- package/lib/utilities/verification.js +25 -24
- package/package.json +2 -2
- package/src/dom/metavariable.js +167 -42
- package/src/dom/reference.js +10 -0
- package/src/dom/statement.js +8 -0
- package/src/dom/term.js +3 -3
- package/src/mixins/proofStep/unify.js +22 -1
- package/src/nodeAndTokens/substitution/reference.js +18 -0
- package/src/substitution/reference.js +74 -0
- package/src/substitution/statement.js +1 -1
- package/src/substitution/term.js +1 -1
- package/src/substitution.js +12 -0
- package/src/unifier/intrinsicLevel.js +55 -0
- package/src/unifier/metaLevel.js +27 -0
- package/src/unifier/metavariable.js +1 -1
- package/src/utilities/brackets.js +42 -0
- package/src/utilities/unification.js +18 -0
- package/src/utilities/verification.js +33 -27
package/src/dom/metavariable.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import dom from "../dom";
|
|
4
4
|
import LocalContext from "../context/local";
|
|
5
5
|
import FrameSubstitution from "../substitution/frame";
|
|
6
|
+
import ReferenceSubstitution from "../substitution/reference";
|
|
6
7
|
import StatementSubstitution from "../substitution/statement";
|
|
7
8
|
import MetavariableNodeAndTokens from "../nodeAndTokens/metavariable";
|
|
8
9
|
|
|
@@ -10,10 +11,11 @@ import { nodeQuery } from "../utilities/query";
|
|
|
10
11
|
import { objectType } from "../dom/type";
|
|
11
12
|
import { domAssigned } from "../dom";
|
|
12
13
|
import { EMPTY_STRING } from "../constants";
|
|
13
|
-
import { unifyMetavariable } from "../utilities/unification";
|
|
14
14
|
import { typeFromJSON, typeToTypeJSON } from "../utilities/json";
|
|
15
15
|
import { metavariableNameFromMetavariableNode } from "../utilities/name";
|
|
16
16
|
import { metaTypeFromJSON, metaTypeToMetaTypeJSON } from "../utilities/json";
|
|
17
|
+
import { unifyMetavariable, unifyMetavariableIntrinsically } from "../utilities/unification";
|
|
18
|
+
import { metavariableFromFrame, metavariableFromReference, metavariableFromStatement } from "../utilities/verification";
|
|
17
19
|
|
|
18
20
|
const termNodeQuery = nodeQuery("/metavariable/argument/term"),
|
|
19
21
|
metavariableNodeQuery = nodeQuery("/metavariableDeclaration/metavariable"),
|
|
@@ -77,38 +79,28 @@ export default domAssigned(class Metavariable {
|
|
|
77
79
|
return equalTo;
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
let
|
|
82
|
-
|
|
83
|
-
const generalContextFilePath = generalContext.getFilePath(),
|
|
84
|
-
specificContextFilePath = specificContext.getFilePath();
|
|
85
|
-
|
|
86
|
-
if (generalContextFilePath === specificContextFilePath) {
|
|
87
|
-
const frameString = frame.getString();
|
|
82
|
+
unifySubstitution(substitution, context) {
|
|
83
|
+
let substitutionUnified = false;
|
|
88
84
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
}
|
|
85
|
+
const metavariableString = this.string, ///
|
|
86
|
+
substitutionString = substitution.getString();
|
|
93
87
|
|
|
94
|
-
|
|
95
|
-
}
|
|
88
|
+
context.trace(`Unifying the '${substitutionString}' substitution with the '${metavariableString}' metavariable...`);
|
|
96
89
|
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
const metavariable = this, ///
|
|
91
|
+
judgement = context.findJudgementByMetavariable(metavariable);
|
|
99
92
|
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
if (judgement !== null) {
|
|
94
|
+
const declaration = judgement.getDeclaration();
|
|
102
95
|
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
substitutionUnified = declaration.unifySubstitution(substitution, context);
|
|
97
|
+
}
|
|
105
98
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
99
|
+
if (substitutionUnified) {
|
|
100
|
+
context.debug(`...unified the '${substitutionString}' substitution with the '${metavariableString}' metavariable.`);
|
|
109
101
|
}
|
|
110
102
|
|
|
111
|
-
return
|
|
103
|
+
return substitutionUnified;
|
|
112
104
|
}
|
|
113
105
|
|
|
114
106
|
unifyFrame(frame, substitutions, generalContext, specificContext) {
|
|
@@ -119,9 +111,9 @@ export default domAssigned(class Metavariable {
|
|
|
119
111
|
|
|
120
112
|
specificContext.trace(`Unifying the '${frameString}' frame with the '${metavariableString}' metavariable...`);
|
|
121
113
|
|
|
122
|
-
const
|
|
114
|
+
const frameMetavariableUnified = this.unifyFrameMetavariable(frame, substitutions, generalContext, specificContext);
|
|
123
115
|
|
|
124
|
-
if (
|
|
116
|
+
if (frameMetavariableUnified) {
|
|
125
117
|
frameUnified = true;
|
|
126
118
|
} else {
|
|
127
119
|
const metavariable = this, ///
|
|
@@ -154,6 +146,49 @@ export default domAssigned(class Metavariable {
|
|
|
154
146
|
return frameUnified;
|
|
155
147
|
}
|
|
156
148
|
|
|
149
|
+
unifyReference(reference, substitutions, generalContext, specificContext) {
|
|
150
|
+
let referenceUnified = false;
|
|
151
|
+
|
|
152
|
+
const referenceString = reference.getString(),
|
|
153
|
+
metavariableString = this.string; ///
|
|
154
|
+
|
|
155
|
+
specificContext.trace(`Unifying the '${referenceString}' reference with the '${metavariableString}' metavariable...`);
|
|
156
|
+
|
|
157
|
+
const referenceMetavariableUnified = this.unifyReferenceMetavariable(reference, substitutions, generalContext, specificContext);
|
|
158
|
+
|
|
159
|
+
if (referenceMetavariableUnified) {
|
|
160
|
+
referenceUnified = true;
|
|
161
|
+
} else {
|
|
162
|
+
const metavariable = this, ///
|
|
163
|
+
simpleSubstitutionPresent = substitutions.isSimpleSubstitutionPresentByMetavariable(metavariable);
|
|
164
|
+
|
|
165
|
+
if (simpleSubstitutionPresent) {
|
|
166
|
+
const simpleSubstitution = substitutions.findSimpleSubstitutionByMetavariable(metavariable),
|
|
167
|
+
substitution = simpleSubstitution, ///
|
|
168
|
+
substitutionReferenceEqualToReference = substitution.isReferenceEqualTo(reference);
|
|
169
|
+
|
|
170
|
+
if (substitutionReferenceEqualToReference) {
|
|
171
|
+
referenceUnified = true;
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
const context = specificContext, ///
|
|
175
|
+
metavariable = this, ///
|
|
176
|
+
referenceSubstitution = ReferenceSubstitution.fromFrameAndMetavariable(reference, metavariable, context),
|
|
177
|
+
substitution = referenceSubstitution; ///
|
|
178
|
+
|
|
179
|
+
substitutions.addSubstitution(substitution, context);
|
|
180
|
+
|
|
181
|
+
referenceUnified = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (referenceUnified) {
|
|
186
|
+
specificContext.debug(`...unified the '${referenceString}' reference with the '${metavariableString}' metavariable.`);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return referenceUnified;
|
|
190
|
+
}
|
|
191
|
+
|
|
157
192
|
unifyStatement(statement, substitution, substitutions, generalContext, specificContext) {
|
|
158
193
|
let statementUnified = false;
|
|
159
194
|
|
|
@@ -165,9 +200,9 @@ export default domAssigned(class Metavariable {
|
|
|
165
200
|
|
|
166
201
|
specificContext.trace(`Unifying the '${statementString}' statement with the '${metavariableString}${substitutionString}' metavariable...`);
|
|
167
202
|
|
|
168
|
-
const
|
|
203
|
+
const statementMetavariableUnified = this.unifyStatementMetavariable(statement, substitutions, generalContext, specificContext);
|
|
169
204
|
|
|
170
|
-
if (
|
|
205
|
+
if (statementMetavariableUnified) {
|
|
171
206
|
statementUnified = true;
|
|
172
207
|
} else {
|
|
173
208
|
const context = specificContext, ///
|
|
@@ -220,28 +255,118 @@ export default domAssigned(class Metavariable {
|
|
|
220
255
|
return metavariableUnified;
|
|
221
256
|
}
|
|
222
257
|
|
|
223
|
-
|
|
224
|
-
let
|
|
258
|
+
unifyFrameMetavariable(frame, substitutions, generalContext, specificContext) {
|
|
259
|
+
let frameMetavariableUnified = false;
|
|
225
260
|
|
|
226
|
-
const
|
|
227
|
-
|
|
261
|
+
const generalContextFilePath = generalContext.getFilePath(),
|
|
262
|
+
specificContextFilePath = specificContext.getFilePath();
|
|
228
263
|
|
|
229
|
-
|
|
264
|
+
if (generalContextFilePath === specificContextFilePath) {
|
|
265
|
+
const frameString = frame.getString();
|
|
230
266
|
|
|
231
|
-
|
|
232
|
-
|
|
267
|
+
if (frameString === this.string) {
|
|
268
|
+
frameMetavariableUnified = true;
|
|
269
|
+
} else {
|
|
270
|
+
const context = specificContext, ///
|
|
271
|
+
metavariable = metavariableFromFrame(frame, context);
|
|
233
272
|
|
|
234
|
-
|
|
235
|
-
|
|
273
|
+
if (metavariable !== null) {
|
|
274
|
+
const frameMetavariable = metavariable, ///
|
|
275
|
+
metavariableString = this.string, ///
|
|
276
|
+
frameMetavariableString = frameMetavariable.getString();
|
|
236
277
|
|
|
237
|
-
|
|
278
|
+
specificContext.trace(`Unifying the frame's ${frameMetavariableString}' metavariable with the '${metavariableString}' metavariable...`);
|
|
279
|
+
|
|
280
|
+
const specificMetavariable = frameMetavariable, ///
|
|
281
|
+
generalMetavariable = this, ///
|
|
282
|
+
metavariableUnifiedIntrinsically = unifyMetavariableIntrinsically(generalMetavariable, specificMetavariable, substitutions, generalContext, specificContext);
|
|
283
|
+
|
|
284
|
+
frameMetavariableUnified = metavariableUnifiedIntrinsically; ///
|
|
285
|
+
|
|
286
|
+
if (frameMetavariableUnified) {
|
|
287
|
+
specificContext.debug(`...unified the frame's '${frameMetavariableString}' metavariable with the '${metavariableString}' metavariable.`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
238
291
|
}
|
|
239
292
|
|
|
240
|
-
|
|
241
|
-
|
|
293
|
+
return frameMetavariableUnified;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
unifyReferenceMetavariable(reference, substitutions, generalContext, specificContext) {
|
|
297
|
+
let referenceMetavariableUnified = false;
|
|
298
|
+
|
|
299
|
+
const generalContextFilePath = generalContext.getFilePath(),
|
|
300
|
+
specificContextFilePath = specificContext.getFilePath();
|
|
301
|
+
|
|
302
|
+
if (generalContextFilePath === specificContextFilePath) {
|
|
303
|
+
const referenceString = reference.getString();
|
|
304
|
+
|
|
305
|
+
if (referenceString === this.string) {
|
|
306
|
+
referenceMetavariableUnified = true;
|
|
307
|
+
} else {
|
|
308
|
+
const context = specificContext, ///
|
|
309
|
+
metavariable = metavariableFromReference(reference, context);
|
|
310
|
+
|
|
311
|
+
if (metavariable !== null) {
|
|
312
|
+
const referenceMetavariable = metavariable, ///
|
|
313
|
+
metavariableString = this.string, ///
|
|
314
|
+
referenceMetavariableString = referenceMetavariable.getString();
|
|
315
|
+
|
|
316
|
+
specificContext.trace(`Unifying the reference's ${referenceMetavariableString}' metavariable with the '${metavariableString}' metavariable...`);
|
|
317
|
+
|
|
318
|
+
const specificMetavariable = referenceMetavariable, ///
|
|
319
|
+
generalMetavariable = this, ///
|
|
320
|
+
metavariableUnifiedIntrinsically = unifyMetavariableIntrinsically(generalMetavariable, specificMetavariable, substitutions, generalContext, specificContext);
|
|
321
|
+
|
|
322
|
+
referenceMetavariableUnified = metavariableUnifiedIntrinsically; ///
|
|
323
|
+
|
|
324
|
+
if (referenceMetavariableUnified) {
|
|
325
|
+
specificContext.debug(`...unified the reference's '${referenceMetavariableString}' metavariable with the '${metavariableString}' metavariable.`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
242
329
|
}
|
|
243
330
|
|
|
244
|
-
return
|
|
331
|
+
return referenceMetavariableUnified;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
unifyStatementMetavariable(statement, substitutions, generalContext, specificContext) {
|
|
335
|
+
let statementMetavariableUnified = false;
|
|
336
|
+
|
|
337
|
+
const generalContextFilePath = generalContext.getFilePath(),
|
|
338
|
+
specificContextFilePath = specificContext.getFilePath();
|
|
339
|
+
|
|
340
|
+
if (generalContextFilePath === specificContextFilePath) {
|
|
341
|
+
const statementString = statement.getString();
|
|
342
|
+
|
|
343
|
+
if (statementString === this.string) {
|
|
344
|
+
statementMetavariableUnified = true;
|
|
345
|
+
} else {
|
|
346
|
+
const context = specificContext, ///
|
|
347
|
+
metavariable = metavariableFromStatement(statement, context);
|
|
348
|
+
|
|
349
|
+
if (metavariable !== null) {
|
|
350
|
+
const statementMetavariable = metavariable, ///
|
|
351
|
+
metavariableString = this.string, ///
|
|
352
|
+
statementMetavariableString = statementMetavariable.getString();
|
|
353
|
+
|
|
354
|
+
specificContext.trace(`Unifying the statement's ${statementMetavariableString}' metavariable with the '${metavariableString}' metavariable...`);
|
|
355
|
+
|
|
356
|
+
const specificMetavariable = statementMetavariable, ///
|
|
357
|
+
generalMetavariable = this, ///
|
|
358
|
+
metavariableUnifiedIntrinsically = unifyMetavariableIntrinsically(generalMetavariable, specificMetavariable, substitutions, generalContext, specificContext);
|
|
359
|
+
|
|
360
|
+
statementMetavariableUnified = metavariableUnifiedIntrinsically; ///
|
|
361
|
+
|
|
362
|
+
if (statementMetavariableUnified) {
|
|
363
|
+
specificContext.debug(`...unified the statement's '${statementMetavariableString}' metavariable with the '${metavariableString}' metavariable.`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return statementMetavariableUnified;
|
|
245
370
|
}
|
|
246
371
|
|
|
247
372
|
verify(context) {
|
package/src/dom/reference.js
CHANGED
|
@@ -120,6 +120,16 @@ export default domAssigned(class Reference {
|
|
|
120
120
|
return reference;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
static fromReferenceNode(referenceNode, fileContext) {
|
|
124
|
+
const { Metavariable } = dom,
|
|
125
|
+
localContext = LocalContext.fromFileContext(fileContext),
|
|
126
|
+
context = localContext, ///
|
|
127
|
+
metavariable = Metavariable.fromReferenceNode(referenceNode, context),
|
|
128
|
+
reference = new Reference(metavariable);
|
|
129
|
+
|
|
130
|
+
return reference;
|
|
131
|
+
}
|
|
132
|
+
|
|
123
133
|
static fromProofStepNode(proofStepNode, fileContext) {
|
|
124
134
|
let reference = null;
|
|
125
135
|
|
package/src/dom/statement.js
CHANGED
|
@@ -210,6 +210,10 @@ export default domAssigned(class Statement {
|
|
|
210
210
|
verify(assignments, stated, context) {
|
|
211
211
|
let verified;
|
|
212
212
|
|
|
213
|
+
const statementString = this.string; ///
|
|
214
|
+
|
|
215
|
+
context.trace(`Verifying the '${statementString}' statement...`);
|
|
216
|
+
|
|
213
217
|
verified = verifyMixins.some((verifyMixin) => {
|
|
214
218
|
const statement = this, ///
|
|
215
219
|
verified = verifyMixin(statement, assignments, stated, context);
|
|
@@ -219,6 +223,10 @@ export default domAssigned(class Statement {
|
|
|
219
223
|
}
|
|
220
224
|
});
|
|
221
225
|
|
|
226
|
+
if (verified) {
|
|
227
|
+
context.debug(`...verified the '${statementString}' statement.`);
|
|
228
|
+
}
|
|
229
|
+
|
|
222
230
|
return verified;
|
|
223
231
|
}
|
|
224
232
|
|
package/src/dom/term.js
CHANGED
|
@@ -127,13 +127,13 @@ export default domAssigned(class Term {
|
|
|
127
127
|
verify(context, verifyAhead) {
|
|
128
128
|
let verified;
|
|
129
129
|
|
|
130
|
-
const
|
|
131
|
-
termString = this.string; ///
|
|
130
|
+
const termString = this.string; ///
|
|
132
131
|
|
|
133
132
|
context.trace(`Verifying the '${termString}' term...`);
|
|
134
133
|
|
|
135
134
|
verified = verifyMixins.some((verifyMixin) => {
|
|
136
|
-
const
|
|
135
|
+
const term = this, ///
|
|
136
|
+
verified = verifyMixin(term, context, verifyAhead);
|
|
137
137
|
|
|
138
138
|
if (verified) {
|
|
139
139
|
return true;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import StatementSubstitution from "../../substitution/statement";
|
|
4
4
|
|
|
5
|
-
import { equalityFromStatement, typeAssertionFromStatement } from "../../utilities/verification";
|
|
5
|
+
import { equalityFromStatement, judgementFromStatement, typeAssertionFromStatement } from "../../utilities/verification";
|
|
6
6
|
|
|
7
7
|
function unifyAWithRule(statement, reference, substitutions, context) {
|
|
8
8
|
let unifiedWithRule = false;
|
|
@@ -113,6 +113,26 @@ function unifyAsEquality(statement, reference, substitutions, context) {
|
|
|
113
113
|
return unifiedAsEquality;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
function unifyAsJudgement(statement, reference, substitutions, context) {
|
|
117
|
+
let unifiedAsJudgement = false;
|
|
118
|
+
|
|
119
|
+
if (reference === null) {
|
|
120
|
+
const judgement = judgementFromStatement(statement, context);
|
|
121
|
+
|
|
122
|
+
if (judgement !== null) {
|
|
123
|
+
const statementString = statement.getString();
|
|
124
|
+
|
|
125
|
+
context.trace(`Unifying the '${statementString}' statement as a judgement...`);
|
|
126
|
+
|
|
127
|
+
unifiedAsJudgement = true;
|
|
128
|
+
|
|
129
|
+
context.debug(`...unified the '${statementString}' statement as a judgement.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return unifiedAsJudgement;
|
|
134
|
+
}
|
|
135
|
+
|
|
116
136
|
function unifyAsTypeAssertion(statement, reference, substitutions, context) {
|
|
117
137
|
let unifiedAsTypeAssertion = false;
|
|
118
138
|
|
|
@@ -151,6 +171,7 @@ const unifyMixins = [
|
|
|
151
171
|
unifyAWithReference,
|
|
152
172
|
unifyAWithAxiomLemmaTheoremOrConjecture,
|
|
153
173
|
unifyAsEquality,
|
|
174
|
+
unifyAsJudgement,
|
|
154
175
|
unifyAsTypeAssertion,
|
|
155
176
|
unifyWithProofSteps
|
|
156
177
|
];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import NodeAndTokens from "../../nodeAndTokens";
|
|
4
|
+
|
|
5
|
+
import { ruleFromBNF } from "../../nodeAndTokens";
|
|
6
|
+
|
|
7
|
+
const bnf = `
|
|
8
|
+
|
|
9
|
+
_ ::= referenceSubstitution... <END_OF_LINE> ;
|
|
10
|
+
|
|
11
|
+
`,
|
|
12
|
+
rule = ruleFromBNF(bnf);
|
|
13
|
+
|
|
14
|
+
export default class ReferenceSubstitutionNodeAndTokens extends NodeAndTokens {
|
|
15
|
+
static rule = rule;
|
|
16
|
+
|
|
17
|
+
static fromString(string, context) { return NodeAndTokens.fromString(ReferenceSubstitutionNodeAndTokens, string, context); }
|
|
18
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import dom from "../dom";
|
|
4
|
+
import Substitution from "../substitution";
|
|
5
|
+
import ReferenceSubstitutionNodeAndTokens from "../nodeAndTokens/substitution/reference";
|
|
6
|
+
|
|
7
|
+
import { nodeQuery } from "../utilities/query";
|
|
8
|
+
|
|
9
|
+
const referenceNodeQuery = nodeQuery("/referenceSubstitution/reference[0]"),
|
|
10
|
+
metavariableNodeQuery = nodeQuery("/referenceSubstitution/reference[1]/metavariable!"),
|
|
11
|
+
referenceSubstitutionNodeQuery = nodeQuery("/statement/referenceSubstitution");
|
|
12
|
+
|
|
13
|
+
export default class ReferenceSubstitution extends Substitution {
|
|
14
|
+
constructor(string, node, tokens, reference, metavariable) {
|
|
15
|
+
super(string, node, tokens);
|
|
16
|
+
|
|
17
|
+
this.reference = reference;
|
|
18
|
+
this.metavariable = metavariable;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getReference() {
|
|
22
|
+
return this.reference;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getMetavariable() {
|
|
26
|
+
return this.metavariable;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
isReferenceEqualTo(reference) { return this.reference.isEqualTo(reference); }
|
|
30
|
+
|
|
31
|
+
isMetavariableEqualTo(metavariable) { return this.metavariable.isEqualTo(metavariable); }
|
|
32
|
+
|
|
33
|
+
static fromStatementNode(statementNode, context) {
|
|
34
|
+
let referenceSubstitution = null;
|
|
35
|
+
|
|
36
|
+
const referenceSubstitutionNode = referenceSubstitutionNodeQuery(statementNode);
|
|
37
|
+
|
|
38
|
+
if (referenceSubstitutionNode !== null) {
|
|
39
|
+
const referenceNode = referenceNodeQuery(referenceSubstitutionNode),
|
|
40
|
+
metavariableNode = metavariableNodeQuery(referenceSubstitutionNode);
|
|
41
|
+
|
|
42
|
+
if ((referenceNode !== null) && (metavariableNode !== null)) {
|
|
43
|
+
const { Reference, Metavariable } = dom,
|
|
44
|
+
reference = Reference.fromReferenceNode(referenceNode, context),
|
|
45
|
+
metavariable = Metavariable.fromMetavariableNode(metavariableNode, context),
|
|
46
|
+
node = referenceSubstitutionNode, ///
|
|
47
|
+
tokens = context.nodeAsTokens(node),
|
|
48
|
+
string = stringFromReferenceAndMetavariable(reference, metavariable);
|
|
49
|
+
|
|
50
|
+
referenceSubstitution = new ReferenceSubstitution(string, node, tokens, reference, metavariable);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return referenceSubstitution;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static fromReferenceAndMetavariable(reference, metavariable, context) {
|
|
58
|
+
const string = stringFromReferenceAndMetavariable(reference, metavariable),
|
|
59
|
+
referenceSubstitutionNodeAndTokens = ReferenceSubstitutionNodeAndTokens.fromString(string, context),
|
|
60
|
+
node = referenceSubstitutionNodeAndTokens.getNode(),
|
|
61
|
+
tokens = referenceSubstitutionNodeAndTokens.getTokens(),
|
|
62
|
+
referenceSubstitution = new ReferenceSubstitution(string, node, tokens, reference, metavariable);
|
|
63
|
+
|
|
64
|
+
return referenceSubstitution;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function stringFromReferenceAndMetavariable(reference, metavariable) {
|
|
69
|
+
const referenceString = reference.getString(),
|
|
70
|
+
metavariableString = metavariable.getString(),
|
|
71
|
+
string = `[${referenceString} for [${metavariableString}]]`;
|
|
72
|
+
|
|
73
|
+
return string;
|
|
74
|
+
}
|
|
@@ -5,7 +5,7 @@ import Substitutions from "../substitutions";
|
|
|
5
5
|
import StatementSubstitutionNodeAndTokens from "../nodeAndTokens/substitution/statement";
|
|
6
6
|
|
|
7
7
|
import { unifySubstitution } from "../utilities/unification";
|
|
8
|
-
import { stripBracketsFromStatement } from "../utilities/
|
|
8
|
+
import { stripBracketsFromStatement } from "../utilities/brackets";
|
|
9
9
|
import { statementFromJSON, statementToStatementJSON, metavariableFromJSON, metavariableToMetavariableJSON } from "../utilities/json";
|
|
10
10
|
|
|
11
11
|
export default class StatementSubstitution extends Substitution {
|
package/src/substitution/term.js
CHANGED
|
@@ -5,7 +5,7 @@ import Substitution from "../substitution";
|
|
|
5
5
|
import TermSubstitutionNodeAndTokens from "../nodeAndTokens/substitution/term";
|
|
6
6
|
|
|
7
7
|
import { nodeQuery } from "../utilities/query";
|
|
8
|
-
import { stripBracketsFromTerm } from "../utilities/
|
|
8
|
+
import { stripBracketsFromTerm } from "../utilities/brackets";
|
|
9
9
|
import { stripBracketsFromTermNode } from "../utilities/brackets";
|
|
10
10
|
|
|
11
11
|
const termNodeQuery = nodeQuery("/termSubstitution/term[0]"),
|
package/src/substitution.js
CHANGED
|
@@ -37,6 +37,12 @@ export default class Substitution {
|
|
|
37
37
|
return variable;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
getReference() {
|
|
41
|
+
const reference = null;
|
|
42
|
+
|
|
43
|
+
return reference;
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
getStatement() {
|
|
41
47
|
const statement = null;
|
|
42
48
|
|
|
@@ -93,6 +99,12 @@ export default class Substitution {
|
|
|
93
99
|
return variableEqualTo;
|
|
94
100
|
}
|
|
95
101
|
|
|
102
|
+
isReferenceEqualTo(reference) {
|
|
103
|
+
const referenceEqualTo = false;
|
|
104
|
+
|
|
105
|
+
return referenceEqualTo;
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
isStatementEqualTo(statement) {
|
|
97
109
|
const statementEqualTo = false;
|
|
98
110
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import dom from "../dom";
|
|
4
|
+
import Unifier from "../unifier";
|
|
5
|
+
|
|
6
|
+
import { nodeQuery } from "../utilities/query";
|
|
7
|
+
|
|
8
|
+
const termNodeQuery = nodeQuery("/term"),
|
|
9
|
+
termVariableNodeQuery = nodeQuery("/term/variable!");
|
|
10
|
+
|
|
11
|
+
class IntrinsicLevelUnifier extends Unifier {
|
|
12
|
+
unify(generalNode, specificNode, substitutions, generalContext, specificContext) {
|
|
13
|
+
let unifiedAtMetaLevel;
|
|
14
|
+
|
|
15
|
+
const generalNonTerminalNode = generalNode, ///
|
|
16
|
+
specificNonTerminalNode = specificNode, ///
|
|
17
|
+
nonTerminalNodeUnified = this.unifyNonTerminalNode(generalNonTerminalNode, specificNonTerminalNode, substitutions, generalContext, specificContext);
|
|
18
|
+
|
|
19
|
+
unifiedAtMetaLevel = nonTerminalNodeUnified; ///
|
|
20
|
+
|
|
21
|
+
return unifiedAtMetaLevel;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static maps = [
|
|
25
|
+
{
|
|
26
|
+
generalNodeQuery: termVariableNodeQuery,
|
|
27
|
+
specificNodeQuery: termNodeQuery,
|
|
28
|
+
unify: (generalTermVariableNode, specificTermNode, substitutions, generalContext, specificContext) => {
|
|
29
|
+
let termUnified;
|
|
30
|
+
|
|
31
|
+
const { Term, Variable } = dom,
|
|
32
|
+
termNode = specificTermNode, ///
|
|
33
|
+
variableNode = generalTermVariableNode; ///
|
|
34
|
+
|
|
35
|
+
let context;
|
|
36
|
+
|
|
37
|
+
context = generalContext; ///
|
|
38
|
+
|
|
39
|
+
const variable = Variable.fromVariableNode(variableNode, context);
|
|
40
|
+
|
|
41
|
+
context = specificContext; ///
|
|
42
|
+
|
|
43
|
+
const term = Term.fromTermNode(termNode, context);
|
|
44
|
+
|
|
45
|
+
termUnified = variable.unifyTerm(term, substitutions, generalContext, specificContext);
|
|
46
|
+
|
|
47
|
+
return termUnified;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const intrinsicLevelUnifier = new IntrinsicLevelUnifier();
|
|
54
|
+
|
|
55
|
+
export default intrinsicLevelUnifier;
|
package/src/unifier/metaLevel.js
CHANGED
|
@@ -9,9 +9,11 @@ import { nodeQuery } from "../utilities/query";
|
|
|
9
9
|
|
|
10
10
|
const termNodeQuery = nodeQuery("/term"),
|
|
11
11
|
frameNodeQuery = nodeQuery("/frame"),
|
|
12
|
+
referenceNodeQuery = nodeQuery("/reference"),
|
|
12
13
|
statementNodeQuery = nodeQuery("/statement"),
|
|
13
14
|
termVariableNodeQuery = nodeQuery("/term/variable!"),
|
|
14
15
|
frameMetavariableNodeQuery = nodeQuery("/frame/metavariable!"),
|
|
16
|
+
referenceMetavariableNodeQuery = nodeQuery("/reference/metavariable!"),
|
|
15
17
|
statementMetavariableNodeQuery = nodeQuery("/statement/metavariable!");
|
|
16
18
|
|
|
17
19
|
class MetaLevelUnifier extends Unifier {
|
|
@@ -68,6 +70,31 @@ class MetaLevelUnifier extends Unifier {
|
|
|
68
70
|
return statementUnified;
|
|
69
71
|
}
|
|
70
72
|
},
|
|
73
|
+
{
|
|
74
|
+
generalNodeQuery: referenceMetavariableNodeQuery,
|
|
75
|
+
specificNodeQuery: referenceNodeQuery,
|
|
76
|
+
unify: (generalReferenceMetavariableNode, specificReferenceNode, substitutions, generalContext, specificContext) => {
|
|
77
|
+
let referenceUnified;
|
|
78
|
+
|
|
79
|
+
const { Reference, Metavariable } = dom,
|
|
80
|
+
referenceNode = specificReferenceNode, ///
|
|
81
|
+
metavariableNode = generalReferenceMetavariableNode; ///
|
|
82
|
+
|
|
83
|
+
let context;
|
|
84
|
+
|
|
85
|
+
context = generalContext; ///
|
|
86
|
+
|
|
87
|
+
const metavariable = Metavariable.fromMetavariableNode(metavariableNode, context);
|
|
88
|
+
|
|
89
|
+
context = specificContext; ///
|
|
90
|
+
|
|
91
|
+
const reference = Reference.fromReferenceNode(referenceNode, context);
|
|
92
|
+
|
|
93
|
+
referenceUnified = metavariable.unifyReference(reference, substitutions, generalContext, specificContext);
|
|
94
|
+
|
|
95
|
+
return referenceUnified;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
71
98
|
{
|
|
72
99
|
generalNodeQuery: frameMetavariableNodeQuery,
|
|
73
100
|
specificNodeQuery: frameNodeQuery,
|
|
@@ -34,7 +34,7 @@ class MetavariableUnifier extends Unifier {
|
|
|
34
34
|
termNode = specificTermNode, ///
|
|
35
35
|
typeName = typeNameFromTypeNode(typeNode),
|
|
36
36
|
type = generalContext.findTypeByTypeName(typeName),
|
|
37
|
-
context =
|
|
37
|
+
context = specificContext, ///
|
|
38
38
|
term = Term.fromTermNode(termNode, context),
|
|
39
39
|
termVerifiedGivenType = term.verifyGivenType(type, generalContext, specificContext);
|
|
40
40
|
|