occam-verify-cli 0.0.1063 → 0.0.1066
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/bin/action/verify.js +2 -0
- package/lib/assertion/contained.js +1 -2
- package/lib/assertion/defined.js +31 -47
- package/lib/assertion/subproof.js +3 -3
- package/lib/combinator/bracketed.js +135 -0
- package/lib/conclusion.js +5 -8
- package/lib/consequent.js +5 -8
- package/lib/constants.js +3 -3
- package/lib/constructor/bracketed.js +30 -11
- package/lib/context/file.js +39 -3
- package/lib/context/local.js +59 -7
- package/lib/metavariable.js +30 -33
- package/lib/mixins/statement/unify.js +2 -2
- package/lib/mixins/statement/verify.js +6 -6
- package/lib/premise.js +5 -8
- package/lib/proofStep.js +2 -2
- package/lib/ruleNames.js +1 -5
- package/lib/statement/unqualified.js +14 -1
- package/lib/statement.js +27 -19
- package/lib/substitution/frameForMetavariable.js +17 -2
- package/lib/substitution/statementForMetavariable.js +22 -27
- package/lib/substitution/termForVariable.js +28 -10
- package/lib/supposition.js +5 -8
- package/lib/unifier/intrinsicLevel.js +4 -4
- package/lib/unifier/metaLevel.js +8 -13
- package/lib/unifier/metavariable.js +4 -4
- package/lib/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +3 -3
- package/lib/unify/statementWithSttaemetnGivenEquivalences.js +5 -5
- 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/utilities/unify.js +4 -21
- package/lib/variable.js +14 -2
- package/package.json +1 -1
- package/src/assertion/contained.js +0 -2
- package/src/assertion/defined.js +34 -61
- package/src/assertion/subproof.js +2 -2
- package/src/combinator/bracketed.js +49 -0
- package/src/conclusion.js +5 -18
- package/src/consequent.js +5 -18
- package/src/constants.js +2 -2
- package/src/constructor/bracketed.js +32 -9
- package/src/context/file.js +35 -5
- package/src/context/local.js +64 -7
- package/src/metavariable.js +46 -33
- package/src/mixins/statement/unify.js +1 -1
- package/src/mixins/statement/verify.js +7 -6
- package/src/premise.js +5 -18
- package/src/proofStep.js +1 -1
- package/src/ruleNames.js +0 -1
- package/src/statement/unqualified.js +17 -0
- package/src/statement.js +54 -36
- package/src/substitution/frameForMetavariable.js +26 -1
- package/src/substitution/statementForMetavariable.js +27 -34
- package/src/substitution/termForVariable.js +45 -13
- package/src/supposition.js +5 -18
- package/src/unifier/intrinsicLevel.js +3 -3
- package/src/unifier/metaLevel.js +15 -21
- package/src/unifier/metavariable.js +3 -3
- package/src/unify/simpleSubstitutionStatementWithComplexSubstitutionStatement.js +2 -2
- package/src/unify/statementWithSttaemetnGivenEquivalences.js +4 -4
- 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/utilities/unify.js +0 -14
- package/src/variable.js +20 -1
- 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/substitution/statement.js +0 -163
- package/lib/unify/frameWithMetaType.js +0 -24
- package/lib/verifier/substitution.js +0 -161
- package/lib/verify/frameGivenMetaType.js +0 -37
- 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/substitution/statement.js +0 -81
- package/src/unify/frameWithMetaType.js +0 -14
- package/src/verifier/substitution.js +0 -75
- package/src/verify/frameGivenMetaType.js +0 -31
package/src/context/local.js
CHANGED
|
@@ -10,8 +10,9 @@ import { mergeEquivalences, findEquivalenceByTerm, groundedTermsAndDefinedVariab
|
|
|
10
10
|
const { last, reverse } = arrayUtilities;
|
|
11
11
|
|
|
12
12
|
class LocalContext {
|
|
13
|
-
constructor(context, variables, proofSteps, judgements, equivalences, metavariables) {
|
|
13
|
+
constructor(context, tokens, variables, proofSteps, judgements, equivalences, metavariables) {
|
|
14
14
|
this.context = context;
|
|
15
|
+
this.tokens = tokens;
|
|
15
16
|
this.variables = variables;
|
|
16
17
|
this.proofSteps = proofSteps;
|
|
17
18
|
this.judgements = judgements;
|
|
@@ -23,6 +24,10 @@ class LocalContext {
|
|
|
23
24
|
return this.context;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
getTokens() {
|
|
28
|
+
return this.tokens;
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
getVariables() {
|
|
27
32
|
let variables = this.context.getVariables();
|
|
28
33
|
|
|
@@ -394,9 +399,47 @@ class LocalContext {
|
|
|
394
399
|
|
|
395
400
|
findMetatheoremByReference(reference) { return this.context.findMetatheoremByReference(reference); }
|
|
396
401
|
|
|
397
|
-
nodeAsString(node
|
|
402
|
+
nodeAsString(node, tokens = null) {
|
|
403
|
+
if (tokens === null) {
|
|
404
|
+
tokens = this.tokens;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const string = this.context.nodeAsString(node, tokens);
|
|
408
|
+
|
|
409
|
+
return string;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
nodesAsString(node, tokens = null) {
|
|
413
|
+
if (tokens === null) {
|
|
414
|
+
tokens = this.tokens;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const string = this.context.nodesAsString(node, tokens);
|
|
418
|
+
|
|
419
|
+
return string;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
nodeAsTokens(node, tokens = null) {
|
|
423
|
+
if (tokens === null) {
|
|
424
|
+
tokens = this.tokens;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
tokens = this.context.nodeAsTokens(node, tokens); ///
|
|
428
|
+
|
|
429
|
+
return tokens;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
nodesAsTokens(node, tokens = null) {
|
|
433
|
+
if (tokens === null) {
|
|
434
|
+
tokens = this.tokens;
|
|
435
|
+
}
|
|
398
436
|
|
|
399
|
-
|
|
437
|
+
tokens = this.context.nodesAsTokens(node, tokens); ///
|
|
438
|
+
|
|
439
|
+
return tokens;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
tokensAsString(tokens) { return this.context.tokensAsString(tokens); }
|
|
400
443
|
|
|
401
444
|
trace(message, node) { this.context.trace(message, node); }
|
|
402
445
|
|
|
@@ -410,25 +453,39 @@ class LocalContext {
|
|
|
410
453
|
|
|
411
454
|
static fromFileContext(fileContext) {
|
|
412
455
|
const context = fileContext, ///
|
|
456
|
+
tokens = null,
|
|
413
457
|
variables = [],
|
|
414
458
|
proofSteps = [],
|
|
415
|
-
equivalences = [],
|
|
416
459
|
judgements = [],
|
|
460
|
+
equivalences = [],
|
|
417
461
|
metavariables = [],
|
|
418
|
-
localContext = new LocalContext(context, variables, proofSteps, judgements, equivalences, metavariables);
|
|
462
|
+
localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences, metavariables);
|
|
419
463
|
|
|
420
464
|
return localContext;
|
|
421
465
|
}
|
|
422
466
|
|
|
423
467
|
static fromLocalContext(localContext) {
|
|
424
468
|
const context = localContext, ///
|
|
469
|
+
tokens = null,
|
|
425
470
|
variables = [],
|
|
426
471
|
proofSteps = [],
|
|
427
|
-
equivalences = [],
|
|
428
472
|
judgements = [],
|
|
473
|
+
equivalences = [],
|
|
429
474
|
metavariables = [];
|
|
430
475
|
|
|
431
|
-
localContext = new LocalContext(context, variables, proofSteps, judgements, equivalences, metavariables); ///
|
|
476
|
+
localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences, metavariables); ///
|
|
477
|
+
|
|
478
|
+
return localContext;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
static fromFileContextAndTokens(fileContext, tokens) {
|
|
482
|
+
const context = fileContext, ///
|
|
483
|
+
variables = [],
|
|
484
|
+
proofSteps = [],
|
|
485
|
+
judgements = [],
|
|
486
|
+
equivalences = [],
|
|
487
|
+
metavariables = [],
|
|
488
|
+
localContext = new LocalContext(context, tokens, variables, proofSteps, judgements, equivalences, metavariables); ///
|
|
432
489
|
|
|
433
490
|
return localContext;
|
|
434
491
|
}
|
package/src/metavariable.js
CHANGED
|
@@ -13,7 +13,7 @@ import { metavariableNodeFromMetavariableString } from "./utilities/node";
|
|
|
13
13
|
const argumentNodeQuery = nodeQuery("/metavariable/argument"),
|
|
14
14
|
metaTypeNodeQuery = nodeQuery("/metavariableDeclaration/metaType"),
|
|
15
15
|
metavariableNodeQuery = nodeQuery("/metavariableDeclaration/metavariable"),
|
|
16
|
-
statementMetavariableNodeQuery = nodeQuery("/statement/metavariable");
|
|
16
|
+
statementMetavariableNodeQuery = nodeQuery("/statement/metavariable!");
|
|
17
17
|
|
|
18
18
|
class Metavariable {
|
|
19
19
|
constructor(fileContext, string, node, name, metaType) {
|
|
@@ -174,40 +174,38 @@ class Metavariable {
|
|
|
174
174
|
substitutionString = substitution.getString(),
|
|
175
175
|
metavariableString = this.string; ///
|
|
176
176
|
|
|
177
|
-
localContext.trace(`Unifying the '${statementString}' statement with the '${metavariableString}' metavariable
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
// }
|
|
207
|
-
// }
|
|
177
|
+
localContext.trace(`Unifying the '${statementString}' statement with the '${metavariableString}' metavariable given the '${substitutionString}' substitution...`);
|
|
178
|
+
|
|
179
|
+
const statementNode = statement.getNode(),
|
|
180
|
+
metavariableNode = this.node, ///
|
|
181
|
+
substitutionNode = substitution.getNode(),
|
|
182
|
+
complexSubstitution = substitutions.findComplexSubstitutionByMetavariableNodeAndSubstitutionNode(metavariableNode, substitutionNode);
|
|
183
|
+
|
|
184
|
+
if (complexSubstitution !== null) {
|
|
185
|
+
const statementNodeMatches = complexSubstitution.matchStatementNode(statementNode);
|
|
186
|
+
|
|
187
|
+
if (statementNodeMatches) {
|
|
188
|
+
statementUnifiedGivenSubstitution = true;
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
const metavariable = metavariableFromStatementNode(statementNode, localContext);
|
|
192
|
+
|
|
193
|
+
if (this === metavariable) { ///
|
|
194
|
+
statementUnifiedGivenSubstitution = false; ///
|
|
195
|
+
} else {
|
|
196
|
+
const metavariable = this, ///
|
|
197
|
+
statementForMetavariableSubstitution = StatementForMetavariableSubstitution.fromStatementMetavariableAndSubstitution(statement, metavariable, substitution, localContext);
|
|
198
|
+
|
|
199
|
+
substitution = statementForMetavariableSubstitution; ///
|
|
200
|
+
|
|
201
|
+
substitutions.addSubstitution(substitution, localContext);
|
|
202
|
+
|
|
203
|
+
statementUnifiedGivenSubstitution = true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
208
206
|
|
|
209
207
|
if (statementUnifiedGivenSubstitution) {
|
|
210
|
-
localContext.trace(`...unified the '${statementString}' statement with the '${metavariableString}' metavariable
|
|
208
|
+
localContext.trace(`...unified the '${statementString}' statement with the '${metavariableString}' metavariable given the '${substitutionString}' substitution.`);
|
|
211
209
|
}
|
|
212
210
|
|
|
213
211
|
return statementUnifiedGivenSubstitution;
|
|
@@ -294,6 +292,21 @@ function metaTypeFromJSON(json, fileContext) {
|
|
|
294
292
|
return metaType;
|
|
295
293
|
}
|
|
296
294
|
|
|
295
|
+
function metavariableFromStatementNode(statementNode, localContext) {
|
|
296
|
+
let metavariable = null;
|
|
297
|
+
|
|
298
|
+
const statementMetavariableNode = statementMetavariableNodeQuery(statementNode)
|
|
299
|
+
|
|
300
|
+
if (statementMetavariableNode !== null) {
|
|
301
|
+
const metavariableNode = statementMetavariableNode, ///
|
|
302
|
+
metavariableName = metavariableNameFromMetavariableNode(metavariableNode);
|
|
303
|
+
|
|
304
|
+
metavariable = localContext.findMetavariableByMetavariableName(metavariableName);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return metavariable;
|
|
308
|
+
}
|
|
309
|
+
|
|
297
310
|
function statementMetavariableFromStatementNode(statementNode, localContext) {
|
|
298
311
|
let statementMetavariable = null;
|
|
299
312
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import BracketedCombinator from "../../
|
|
3
|
+
import BracketedCombinator from "../../combinator/bracketed";
|
|
4
4
|
import statementWithCombinatorUnifier from "../../unifier/statementWithCombinator";
|
|
5
5
|
|
|
6
6
|
function unifyWithBracketedCombinator(statement, assignments, stated, localContext) {
|
|
@@ -6,7 +6,8 @@ import TypeAssertion from "../../assertion/type";
|
|
|
6
6
|
import DefinedAssertion from "../../assertion/defined";
|
|
7
7
|
import SubproofAssertion from "../../assertion/subproof";
|
|
8
8
|
import ContainedAssertion from "../../assertion/contained";
|
|
9
|
-
import
|
|
9
|
+
import TermForVariableSubstitution from "../../substitution/termForVariable";
|
|
10
|
+
import FrameForMetavariableSubstitution from "../../substitution/frameForMetavariable";
|
|
10
11
|
|
|
11
12
|
import verifyFrame from "../../verify/frame";
|
|
12
13
|
import verifyJudgement from "../../verify/judgement";
|
|
@@ -41,12 +42,12 @@ function verifyAsMetavariable(statement, assignments, stated, localContext) {
|
|
|
41
42
|
if (metavariableVerified) {
|
|
42
43
|
let substitutionVerified = true;
|
|
43
44
|
|
|
44
|
-
const
|
|
45
|
+
const substitution = FrameForMetavariableSubstitution.fromStatementNode(statementNode, localContext) ||
|
|
46
|
+
TermForVariableSubstitution.fromStatementNode(statementNode, localContext) ||
|
|
47
|
+
null;
|
|
45
48
|
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
substitutionVerified = statementSubstitutionVerified; ///
|
|
49
|
+
if (substitution !== null) {
|
|
50
|
+
substitutionVerified = substitution.verify(assignments, stated, localContext);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
verifiedAsMetavariable = substitutionVerified; ///
|
package/src/premise.js
CHANGED
|
@@ -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
|
|
|
@@ -80,26 +78,15 @@ export default class Premise {
|
|
|
80
78
|
unifyStatement(statement, substitutions, localContext) {
|
|
81
79
|
let statementUnified;
|
|
82
80
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
premiseStatement = premise.getStatement(),
|
|
86
|
-
premiseStatementString = premiseStatement.getString();
|
|
87
|
-
|
|
88
|
-
localContext.trace(`Unifying the '${statementString}' statement with the premise's '${premiseStatementString}' statement...`);
|
|
81
|
+
const statementString = statement.getString(),
|
|
82
|
+
premiseString = this.getString();
|
|
89
83
|
|
|
90
|
-
|
|
91
|
-
premiseStatementNode = premiseStatement.getNode(),
|
|
92
|
-
nodeA = premiseStatementNode, ///
|
|
93
|
-
nodeB = statementNode, ///
|
|
94
|
-
fileContextA = this.fileContext, ///
|
|
95
|
-
localContextA = LocalContext.fromFileContext(fileContextA),
|
|
96
|
-
localContextB = localContext, ///
|
|
97
|
-
unified = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
|
|
84
|
+
localContext.trace(`Unifying the '${statementString}' statement with the '${premiseString}' premise...`);
|
|
98
85
|
|
|
99
|
-
statementUnified =
|
|
86
|
+
statementUnified = this.unqualifiedStatement.unifyStatement(statement, substitutions, this.fileContext, localContext);
|
|
100
87
|
|
|
101
88
|
if (statementUnified) {
|
|
102
|
-
localContext.debug(`...unified the '${statementString}' statement with the
|
|
89
|
+
localContext.debug(`...unified the '${statementString}' statement with the '${premiseString}' premise.`);
|
|
103
90
|
}
|
|
104
91
|
|
|
105
92
|
return statementUnified;
|
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 =
|
|
74
|
+
const stated = false,
|
|
75
75
|
assignments = [],
|
|
76
76
|
unqualifiedStatementVerified = this.unqualifiedStatement.verify(assignments, stated, localContext);
|
|
77
77
|
|
package/src/ruleNames.js
CHANGED
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
|
|
3
3
|
export const VARIABLE_RULE_NAME = "variable";
|
|
4
4
|
export const METAVARIABLE_RULE_NAME = "metavariable";
|
|
5
|
-
export const SUBSTITUTION_RULE_NAME = "substitution";
|
|
6
5
|
export const UNQUALIFIED_STATEMENT_RULE_NAME = "unqualifiedStatement";
|
|
7
6
|
export const CONSTRUCTOR_DECLARATION_RULE_NAME = "constructorDeclaration";
|
|
@@ -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,22 +3,26 @@
|
|
|
3
3
|
import shim from "./shim";
|
|
4
4
|
import unifyMixins from "./mixins/statement/unify";
|
|
5
5
|
import verifyMixins from "./mixins/statement/verify";
|
|
6
|
-
import
|
|
6
|
+
import LocalContext from "./context/local";
|
|
7
|
+
import metaLevelUnifier from "./unifier/metaLevel";
|
|
7
8
|
import statementAsCombinatorVerifier from "./verifier/statementAsCombinator";
|
|
8
9
|
|
|
9
10
|
import { nodeQuery, nodesQuery } from "./utilities/query";
|
|
10
11
|
import { STATEMENT_META_TYPE_NAME } from "./metaTypeNames";
|
|
11
|
-
import {
|
|
12
|
+
import { statementTokensFromUnqualifiedStatementTokens, unqualifiedStatementTokensFromUnqualifiedStatementString } from "./utilities/tokens";
|
|
13
|
+
import { statementNodeFromUnqualifiedStatementNode,
|
|
14
|
+
unqualifiedStatementStringFromStatementString,
|
|
15
|
+
unqualifiedStatementNodeFromUnqualifiedStatementTokens } from "./utilities/node";
|
|
12
16
|
|
|
13
17
|
const statementNodeQuery = nodeQuery("/*//statement"),
|
|
14
18
|
statementVariableNodesQuery = nodesQuery("/statement//variable"),
|
|
15
19
|
statementMetavariableNodesQuery = nodesQuery("/statement//metavariable");
|
|
16
20
|
|
|
17
21
|
class Statement {
|
|
18
|
-
constructor(string, node,
|
|
22
|
+
constructor(string, node, tokens) {
|
|
19
23
|
this.string = string;
|
|
20
24
|
this.node = node;
|
|
21
|
-
this.
|
|
25
|
+
this.tokens = tokens;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
getString() {
|
|
@@ -29,8 +33,8 @@ class Statement {
|
|
|
29
33
|
return this.node;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
return this.
|
|
36
|
+
getTokens() {
|
|
37
|
+
return this.tokens;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
isEqualTo(statement) {
|
|
@@ -95,6 +99,32 @@ class Statement {
|
|
|
95
99
|
return metavariableContained;
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
unifyStatement(statement, substitutions, fileContext, localContext) {
|
|
103
|
+
let statementUnified;
|
|
104
|
+
|
|
105
|
+
const statementA = this, ///
|
|
106
|
+
statementB = statement, ///
|
|
107
|
+
statementAString = statementA.getString(),
|
|
108
|
+
statementBString = statementB.getString();
|
|
109
|
+
|
|
110
|
+
localContext.trace(`Unifying the '${statementBString}' statement with the '${statementAString}' statement...`);
|
|
111
|
+
|
|
112
|
+
const statementANode = statementA.getNode(),
|
|
113
|
+
statementBNode = statementB.getNode(),
|
|
114
|
+
nodeA = statementANode, ///
|
|
115
|
+
nodeB = statementBNode, ///
|
|
116
|
+
fileContextA = fileContext, ///
|
|
117
|
+
localContextA = LocalContext.fromFileContextAndTokens(fileContextA, this.tokens),
|
|
118
|
+
localContextB = localContext, ///
|
|
119
|
+
unifiedAtMetaLevel = metaLevelUnifier.unify(nodeA, nodeB, substitutions, localContextA, localContextB);
|
|
120
|
+
|
|
121
|
+
statementUnified = unifiedAtMetaLevel; ///
|
|
122
|
+
|
|
123
|
+
localContext.debug(`...unified the '${statementBString}' statement with the '${statementAString}' statement.`);
|
|
124
|
+
|
|
125
|
+
return statementUnified;
|
|
126
|
+
}
|
|
127
|
+
|
|
98
128
|
verify(assignments, stated, localContext) {
|
|
99
129
|
let verified = false;
|
|
100
130
|
|
|
@@ -173,13 +203,8 @@ class Statement {
|
|
|
173
203
|
}
|
|
174
204
|
|
|
175
205
|
toJSON() {
|
|
176
|
-
const
|
|
177
|
-
this.substitution.toJSON() :
|
|
178
|
-
null,
|
|
179
|
-
substitution = substitutionJSON, ///
|
|
180
|
-
string = this.string, ///
|
|
206
|
+
const string = this.string, ///
|
|
181
207
|
json = {
|
|
182
|
-
substitution,
|
|
183
208
|
string
|
|
184
209
|
};
|
|
185
210
|
|
|
@@ -191,18 +216,14 @@ class Statement {
|
|
|
191
216
|
statementString = string, ///
|
|
192
217
|
lexer = fileContext.getLexer(),
|
|
193
218
|
parser = fileContext.getParser(),
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
substitution = statementSubstitution; ///
|
|
204
|
-
|
|
205
|
-
const statement = new Statement(string, node, substitution);
|
|
219
|
+
unqualifiedStatementString = unqualifiedStatementStringFromStatementString(statementString),
|
|
220
|
+
unqualifiedStatementTokens = unqualifiedStatementTokensFromUnqualifiedStatementString(unqualifiedStatementString, lexer),
|
|
221
|
+
unqualifiedStatementNode = unqualifiedStatementNodeFromUnqualifiedStatementTokens(unqualifiedStatementTokens, parser),
|
|
222
|
+
statementTokens = statementTokensFromUnqualifiedStatementTokens(unqualifiedStatementTokens),
|
|
223
|
+
statementNode = statementNodeFromUnqualifiedStatementNode(unqualifiedStatementNode),
|
|
224
|
+
node = statementNode, ///
|
|
225
|
+
tokens = statementTokens, ///
|
|
226
|
+
statement = new Statement(string, node, tokens);
|
|
206
227
|
|
|
207
228
|
return statement;
|
|
208
229
|
}
|
|
@@ -212,11 +233,10 @@ class Statement {
|
|
|
212
233
|
|
|
213
234
|
if (statementNode !== null) {
|
|
214
235
|
const node = statementNode, ///
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
substitution = statementSubstitution; ///
|
|
236
|
+
tokens = localContext.nodeAsTokens(node),
|
|
237
|
+
string = localContext.tokensAsString(tokens);
|
|
218
238
|
|
|
219
|
-
statement = new Statement(string, node,
|
|
239
|
+
statement = new Statement(string, node, tokens);
|
|
220
240
|
}
|
|
221
241
|
|
|
222
242
|
return statement;
|
|
@@ -225,10 +245,9 @@ class Statement {
|
|
|
225
245
|
static fromDefinedAssertionNode(definedAssertionNode, localContext) {
|
|
226
246
|
const statementNode = statementNodeQuery(definedAssertionNode),
|
|
227
247
|
node = statementNode, ///
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
statement = new Statement(string, node, substitution);
|
|
248
|
+
tokens = localContext.nodeAsTokens(node),
|
|
249
|
+
string = localContext.tokensAsString(tokens),
|
|
250
|
+
statement = new Statement(string, node, tokens);
|
|
232
251
|
|
|
233
252
|
return statement;
|
|
234
253
|
}
|
|
@@ -236,10 +255,9 @@ class Statement {
|
|
|
236
255
|
static fromContainedAssertionNode(containedAssertionNode, localContext) {
|
|
237
256
|
const statementNode = statementNodeQuery(containedAssertionNode),
|
|
238
257
|
node = statementNode, ///
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
statement = new Statement(string, node, substitution);
|
|
258
|
+
tokens = localContext.nodeAsTokens(node),
|
|
259
|
+
string = localContext.tokensAsString(tokens),
|
|
260
|
+
statement = new Statement(string, node, tokens);
|
|
243
261
|
|
|
244
262
|
return statement;
|
|
245
263
|
}
|
|
@@ -4,7 +4,8 @@ import Substitution from "../substitution";
|
|
|
4
4
|
|
|
5
5
|
import { nodeQuery } from "../utilities/query";
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const substitutionNodeQuery = nodeQuery("/statement/substitution"),
|
|
8
|
+
substitutionFrameNodeQuery = nodeQuery("/substitution/frame!"),
|
|
8
9
|
frameMetavariableNodeQuery = nodeQuery("/frame/metavariable!"),
|
|
9
10
|
substitutionMetavariableNodeQuery = nodeQuery("/substitution/metavariable!");
|
|
10
11
|
|
|
@@ -87,6 +88,30 @@ export default class FrameForMetavariableSubstitution extends Substitution {
|
|
|
87
88
|
return frameForMetavariableSubstitution;
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
static fromStatementNode(statementNode, localContext) {
|
|
92
|
+
let frameForMetavariableSubstitution = null;
|
|
93
|
+
|
|
94
|
+
const substitutionNode = substitutionNodeQuery(statementNode);
|
|
95
|
+
|
|
96
|
+
if (substitutionNode !== null) {
|
|
97
|
+
const substitutionFrameNode = substitutionFrameNodeQuery(substitutionNode);
|
|
98
|
+
|
|
99
|
+
if (substitutionFrameNode !== null) {
|
|
100
|
+
const substitutionMetavariableNode = substitutionMetavariableNodeQuery(substitutionNode),
|
|
101
|
+
metavariableNode = substitutionMetavariableNode, ///
|
|
102
|
+
frameNode = substitutionFrameNode, ///
|
|
103
|
+
localContextA = localContext, ///
|
|
104
|
+
localContextB = localContext, ///
|
|
105
|
+
string = stringFromFrameNodeAndMetavariableNode(frameNode, metavariableNode, localContextA, localContextB);
|
|
106
|
+
|
|
107
|
+
frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return frameForMetavariableSubstitution;
|
|
113
|
+
}
|
|
114
|
+
|
|
90
115
|
static fromFrameNodeAndMetavariableNode(frameNode, metavariableNode, localContextA, localContextB) {
|
|
91
116
|
const string = stringFromFrameNodeAndMetavariableNode(frameNode, metavariableNode, localContextA, localContextB),
|
|
92
117
|
frameForMetavariableSubstitution = new FrameForMetavariableSubstitution(string, frameNode, metavariableNode);
|
|
@@ -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
|
|
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
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
string = `[${statementString} for ${metavariableString}]`;
|
|
94
|
+
function substitutionFromSubstitution(substitution, localContext) {
|
|
95
|
+
if (substitution === null) {
|
|
96
|
+
const termForVariableSubstitution = TermForVariableSubstitution.fromSubstitution(substitution, localContext);
|
|
98
97
|
|
|
99
|
-
|
|
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
|
-
|
|
104
|
-
|
|
106
|
+
if (frameForMetavariableSubstitution !== null) {
|
|
107
|
+
substitution = frameForMetavariableSubstitution; ///
|
|
108
|
+
}
|
|
109
|
+
}
|
|
105
110
|
|
|
106
|
-
|
|
111
|
+
return substitution;
|
|
112
|
+
}
|
|
107
113
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
|
119
|
+
return string;
|
|
125
120
|
}
|
|
126
121
|
|
|
127
|
-
function stringFromStatementMetavariableAndSubstitution(
|
|
122
|
+
function stringFromStatementMetavariableAndSubstitution(statement, metavariable, substitution) {
|
|
128
123
|
let string;
|
|
129
124
|
|
|
130
|
-
const
|
|
131
|
-
|
|
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 = `[${
|
|
129
|
+
string = `[${statementString} for ${metavariableString}]`;
|
|
137
130
|
} else {
|
|
138
|
-
const substitutionString = substitution.
|
|
131
|
+
const substitutionString = substitution.getString();
|
|
139
132
|
|
|
140
|
-
string = `[${
|
|
133
|
+
string = `[${statementString} for ${metavariableString}${substitutionString}]`;
|
|
141
134
|
}
|
|
142
135
|
|
|
143
136
|
return string;
|