occam-verify-cli 0.0.936 → 0.0.938
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/conclusion.js +7 -10
- package/lib/consequent.js +7 -10
- package/lib/context/local.js +1 -1
- package/lib/equality.js +2 -5
- package/lib/premise.js +15 -21
- package/lib/proofStep.js +3 -6
- package/lib/rule.js +23 -23
- package/lib/substitution/statementForMetavariable.js +3 -6
- package/lib/supposition.js +15 -21
- package/lib/topLevelAssertion.js +27 -23
- package/lib/unifier/equality.js +37 -107
- package/lib/unifier/metaLevel.js +48 -121
- package/lib/unifier/statementAgainstCombinator.js +41 -123
- package/lib/unifier/termAgainstConstructor.js +29 -103
- package/lib/unifier.js +60 -41
- package/lib/unify/metavariableAgainstStatement.js +5 -5
- package/lib/unify/statementAgainstMetaType.js +10 -4
- package/lib/unify/statementAtainstStatement.js +3 -6
- package/lib/unify/termAgainstTerm.js +1 -1
- package/lib/unify/termAgainstType.js +10 -4
- package/lib/utilities/string.js +2 -2
- package/lib/utilities/unifier.js +51 -0
- package/lib/verifier/metaLevel.js +48 -128
- package/lib/verifier/statementAsCombinator.js +48 -128
- package/lib/verifier/termAsConstructor.js +42 -112
- package/lib/verifier.js +50 -33
- package/lib/verify/assertion/contained.js +3 -6
- package/lib/verify/assertion/defined.js +3 -6
- package/lib/verify/assertion/subproof.js +9 -14
- package/lib/verify/statement/qualified.js +7 -7
- package/lib/verify/statement.js +10 -54
- package/lib/verify/statementAsCombinator.js +4 -8
- package/lib/verify/term.js +5 -5
- package/lib/verify/termAsConstructor.js +30 -23
- package/package.json +2 -2
- package/src/conclusion.js +8 -12
- package/src/consequent.js +8 -12
- package/src/context/local.js +7 -7
- package/src/equality.js +2 -8
- package/src/premise.js +20 -28
- package/src/proofStep.js +5 -9
- package/src/rule.js +22 -22
- package/src/substitution/statementForMetavariable.js +4 -8
- package/src/supposition.js +20 -28
- package/src/topLevelAssertion.js +29 -22
- package/src/unifier/equality.js +31 -59
- package/src/unifier/metaLevel.js +50 -83
- package/src/unifier/statementAgainstCombinator.js +33 -83
- package/src/unifier/termAgainstConstructor.js +19 -57
- package/src/unifier.js +57 -31
- package/src/unify/metavariableAgainstStatement.js +5 -3
- package/src/unify/statementAgainstMetaType.js +8 -3
- package/src/unify/statementAtainstStatement.js +4 -8
- package/src/unify/termAgainstTerm.js +1 -1
- package/src/unify/termAgainstType.js +7 -3
- package/src/utilities/string.js +1 -1
- package/src/verifier/metaLevel.js +37 -81
- package/src/verifier/statementAsCombinator.js +39 -82
- package/src/verifier/termAsConstructor.js +33 -62
- package/src/verifier.js +47 -21
- package/src/verify/assertion/contained.js +2 -7
- package/src/verify/assertion/defined.js +2 -7
- package/src/verify/assertion/subproof.js +3 -16
- package/src/verify/statement/qualified.js +7 -7
- package/src/verify/statement.js +10 -78
- package/src/verify/statementAsCombinator.js +3 -11
- package/src/verify/term.js +8 -8
- package/src/verify/termAsConstructor.js +40 -27
- package/lib/unify/argumentAgainstArgument.js +0 -24
- package/lib/utilities/terminalNodes.js +0 -51
- package/src/unify/argumentAgainstArgument.js +0 -15
- /package/src/utilities/{terminalNodes.js → unifier.js} +0 -0
package/src/unifier/equality.js
CHANGED
|
@@ -3,80 +3,52 @@
|
|
|
3
3
|
import Unifier from "../unifier";
|
|
4
4
|
import unifyTermAgainstTerm from "../unify/termAgainstTerm";
|
|
5
5
|
|
|
6
|
-
import { unify } from "../unifier";
|
|
7
6
|
import { nodeQuery } from "../utilities/query";
|
|
8
7
|
|
|
9
|
-
const termNodeQuery = nodeQuery("/term!")
|
|
10
|
-
nonTerminalNodeQuery = nodeQuery("/*");
|
|
8
|
+
const termNodeQuery = nodeQuery("/term!");
|
|
11
9
|
|
|
12
10
|
class EqualityUnifier extends Unifier {
|
|
13
|
-
|
|
14
|
-
let
|
|
11
|
+
unify(leftTermNode, rightTermNode, localContext) {
|
|
12
|
+
let equalityUnified;
|
|
15
13
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
unify: (nodeA, nodeB, localContext, unifyAhead) => {
|
|
21
|
-
let nonTerminalNodUnified;
|
|
14
|
+
const nonTerminalNodeA = leftTermNode, ///
|
|
15
|
+
nonTerminalNodeB = rightTermNode, ///
|
|
16
|
+
nonTerminalNodeUnified = this.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, localContext, () => {
|
|
17
|
+
const unifiedAhead = true;
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
termNodUnifiedAgainstTermNode =
|
|
19
|
+
return unifiedAhead;
|
|
20
|
+
});
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
equalityUnified = nonTerminalNodeUnified; ///
|
|
28
23
|
|
|
29
|
-
|
|
24
|
+
return equalityUnified;
|
|
25
|
+
};
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
unify: (nodeA, nodeB, localContext, unifyAhead) => {
|
|
38
|
-
let nonTerminalNodUnified;
|
|
39
|
-
|
|
40
|
-
const nonTerminalNodeA = nodeA, ///
|
|
41
|
-
nonTerminalNodeB = nodeB; ///
|
|
27
|
+
static maps = [
|
|
28
|
+
{
|
|
29
|
+
nodeQueryA: termNodeQuery,
|
|
30
|
+
nodeQueryB: termNodeQuery,
|
|
31
|
+
unify: (termNodeA, termNodeB, localContext, unifyAhead) => {
|
|
32
|
+
let termVerifiedAgainstTerm;
|
|
42
33
|
|
|
43
|
-
|
|
34
|
+
termVerifiedAgainstTerm = unifyTermAgainstTerm(termNodeA, termNodeB, localContext, unifyAhead);
|
|
44
35
|
|
|
45
|
-
|
|
36
|
+
if (!termVerifiedAgainstTerm) {
|
|
37
|
+
const nonTerminalNodeA = termNodeA, ///
|
|
38
|
+
nonTerminalNodeB = termNodeB, ///
|
|
39
|
+
nonTerminalNodeAChildNodes = nonTerminalNodeA.getChildNodes(),
|
|
40
|
+
nonTerminalNodeBChildNodes = nonTerminalNodeB.getChildNodes(),
|
|
41
|
+
childNodesA = nonTerminalNodeAChildNodes, ///
|
|
42
|
+
childNodesB = nonTerminalNodeBChildNodes, ///
|
|
43
|
+
childNodesVerified = equalityUnifier.unifyChildNodes(childNodesA, childNodesB, localContext, unifyAhead);
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
termVerifiedAgainstTerm = childNodesVerified; ///
|
|
48
46
|
}
|
|
49
|
-
}
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
const nodesVerified = unify(nodeQueryMaps, nonTerminalNodeA, nonTerminalNodeB, localContext, unifyAhead);
|
|
53
|
-
|
|
54
|
-
nonTerminalNodUnified = nodesVerified; ///
|
|
55
|
-
|
|
56
|
-
return nonTerminalNodUnified;
|
|
57
|
-
}
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const termVerifiedAgainstTerm = unifyTermAgainstTerm(termNodeA, termNodeB, localContext, unifyAhead);
|
|
63
|
-
|
|
64
|
-
if (termVerifiedAgainstTerm) {
|
|
65
|
-
termNodUnifiedAgainstTermNode = true;
|
|
66
|
-
} else {
|
|
67
|
-
const nonTerminalNodeA = termNodeA, ///
|
|
68
|
-
nonTerminalNodeB = termNodeB, ///
|
|
69
|
-
nonTerminalNodeAChildNodes = nonTerminalNodeA.getChildNodes(),
|
|
70
|
-
nonTerminalNodeBChildNodes = nonTerminalNodeB.getChildNodes(),
|
|
71
|
-
childNodesA = nonTerminalNodeAChildNodes, ///
|
|
72
|
-
childNodesB = nonTerminalNodeBChildNodes, ///
|
|
73
|
-
childNodesVerified = this.unifyChildNodes(childNodesA, childNodesB, localContext, unifyAhead);
|
|
74
|
-
|
|
75
|
-
termNodUnifiedAgainstTermNode = childNodesVerified; ///
|
|
48
|
+
return termVerifiedAgainstTerm;
|
|
49
|
+
}
|
|
76
50
|
}
|
|
77
|
-
|
|
78
|
-
return termNodUnifiedAgainstTermNode;
|
|
79
|
-
}
|
|
51
|
+
];
|
|
80
52
|
}
|
|
81
53
|
|
|
82
54
|
const equalityUnifier = new EqualityUnifier();
|
package/src/unifier/metaLevel.js
CHANGED
|
@@ -5,104 +5,71 @@ import Unifier from "../unifier";
|
|
|
5
5
|
import unifyVariableAgainstTerm from "../unify/variableAgainstTerm";
|
|
6
6
|
import unifyMetavariableAgainstStatement from "../unify/metavariableAgainstStatement";
|
|
7
7
|
|
|
8
|
-
import { unify } from "../unifier";
|
|
9
8
|
import { nodeQuery } from "../utilities/query";
|
|
10
9
|
|
|
11
10
|
const termNodeQuery = nodeQuery("/term!"),
|
|
12
11
|
statementNodeQuery = nodeQuery("/statement!"),
|
|
13
|
-
nonTerminalNodeQuery = nodeQuery("/*"),
|
|
14
12
|
termVariableNodeQuery = nodeQuery("/term/variable!"),
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
substitutionNodeQuery = nodeQuery("/statement/substitution!"),
|
|
14
|
+
metavariableNodeQuery = nodeQuery("/statement/metavariable!");
|
|
17
15
|
|
|
18
16
|
class MetaLevelUnifier extends Unifier {
|
|
19
|
-
|
|
20
|
-
let
|
|
17
|
+
unify(nodeA, nodeB, substitutions, localContextA, localContextB) {
|
|
18
|
+
let unified;
|
|
21
19
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
unify: (nodeA, nodeB, substitutions, localContextA, localContextB, unifyAhead) => {
|
|
27
|
-
let nonTerminalNodeUnified;
|
|
20
|
+
const nonTerminalNodeA = nodeA, ///
|
|
21
|
+
nonTerminalNodeB = nodeB, ///
|
|
22
|
+
nonTerminalNodeUnified = this.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions, localContextA, localContextB, () => {
|
|
23
|
+
const unifiedAhead = true;
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
statementMetavariableNodeA = nodeA, ///
|
|
32
|
-
statementSubstitutionNodeA = statementSubstitutionNodeQuery(statementNodeA),
|
|
33
|
-
metavariableNodeUnifiedAgainstStatementNode =
|
|
25
|
+
return unifiedAhead;
|
|
26
|
+
});
|
|
34
27
|
|
|
35
|
-
|
|
28
|
+
unified = nonTerminalNodeUnified; ///
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return nonTerminalNodeUnified;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
nodeQueryA: termVariableNodeQuery,
|
|
44
|
-
nodeQueryB: termNodeQuery,
|
|
45
|
-
unify: (nodeA, nodeB, substitutions, localContextA, localContextB, unifyAhead) => {
|
|
46
|
-
let nonTerminalNodeUnified;
|
|
47
|
-
|
|
48
|
-
const termNodeB = nodeB, ///
|
|
49
|
-
termVariableNodeA = nodeA, ///
|
|
50
|
-
termVariableNodeUnifiedAgainstTermNode =
|
|
51
|
-
|
|
52
|
-
this.unifyTermVariableNodeAgainstTermNode(termVariableNodeA, termNodeB, substitutions, localContextA, localContextB, unifyAhead);
|
|
53
|
-
|
|
54
|
-
nonTerminalNodeUnified = termVariableNodeUnifiedAgainstTermNode; ///
|
|
30
|
+
return unified;
|
|
31
|
+
}
|
|
55
32
|
|
|
56
|
-
|
|
33
|
+
static maps = [
|
|
34
|
+
{
|
|
35
|
+
nodeQueryA: statementNodeQuery,
|
|
36
|
+
nodeQueryB: statementNodeQuery,
|
|
37
|
+
unify: (statementNodeA, statementNodeB, substitutions, localContextA, localContextB, unifyAhead) => {
|
|
38
|
+
let statementVerifiedAgainstStatement;
|
|
39
|
+
|
|
40
|
+
const metavariableNodeA = metavariableNodeQuery(statementNodeA);
|
|
41
|
+
|
|
42
|
+
if (metavariableNodeA !== null) {
|
|
43
|
+
const substitutionNodeA = substitutionNodeQuery(statementNodeA),
|
|
44
|
+
metavariableUnifiedAgainstStatement = unifyMetavariableAgainstStatement(metavariableNodeA, statementNodeB, substitutionNodeA, substitutions, localContextA, localContextB, unifyAhead);
|
|
45
|
+
|
|
46
|
+
statementVerifiedAgainstStatement = metavariableUnifiedAgainstStatement; ///
|
|
47
|
+
} else {
|
|
48
|
+
const nonTerminalNodeA = statementNodeA, ///
|
|
49
|
+
nonTerminalNodeB = statementNodeB, ///
|
|
50
|
+
nonTerminalNodeAChildNodes = nonTerminalNodeA.getChildNodes(),
|
|
51
|
+
nonTerminalNodeBChildNodes = nonTerminalNodeB.getChildNodes(),
|
|
52
|
+
childNodesA = nonTerminalNodeAChildNodes, ///
|
|
53
|
+
childNodesB = nonTerminalNodeBChildNodes, ///
|
|
54
|
+
childNodesVerified = metaLevelUnifier.unifyChildNodes(childNodesA, childNodesB, substitutions, localContextA, localContextB, unifyAhead);
|
|
55
|
+
|
|
56
|
+
statementVerifiedAgainstStatement = childNodesVerified; ///
|
|
57
57
|
}
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
nodeQueryA: nonTerminalNodeQuery,
|
|
61
|
-
nodeQueryB: nonTerminalNodeQuery,
|
|
62
|
-
unify: (nodeA, nodeB, substitutions, localContextA, localContextB, unifyAhead) => {
|
|
63
|
-
let nonTerminalNodeUnified;
|
|
64
|
-
|
|
65
|
-
const nonTerminalNodeA = nodeA, ///
|
|
66
|
-
nonTerminalNodeB = nodeB; ///
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
super.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions, localContextA, localContextB, unifyAhead);
|
|
71
|
-
|
|
72
|
-
return nonTerminalNodeUnified;
|
|
73
|
-
}
|
|
59
|
+
return statementVerifiedAgainstStatement;
|
|
74
60
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const substitutionNode = statementSubstitutionNodeA, ///
|
|
88
|
-
metavariableNodeA = statementMetavariableNodeA, ///
|
|
89
|
-
metavariableUnifiedAgainstStatement = unifyMetavariableAgainstStatement(metavariableNodeA, statementNodeB, substitutionNode, substitutions, localContextA, localContextB, unifyAhead);
|
|
90
|
-
|
|
91
|
-
metavariableNodeUnifiedAgainstStatementNode = metavariableUnifiedAgainstStatement; ///
|
|
92
|
-
|
|
93
|
-
return metavariableNodeUnifiedAgainstStatementNode;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
unifyTermVariableNodeAgainstTermNode(termVariableNodeA, termNodeB, substitutions, localContextA, localContextB, unifyAhead) {
|
|
97
|
-
let termVariableNodeUnifiedAgainstTermNode;
|
|
98
|
-
|
|
99
|
-
const variableNodeA = termVariableNodeA, ///
|
|
100
|
-
termUnifiedAgainstVariable = unifyVariableAgainstTerm(variableNodeA, termNodeB, substitutions, localContextA, localContextB, unifyAhead);
|
|
101
|
-
|
|
102
|
-
termVariableNodeUnifiedAgainstTermNode = termUnifiedAgainstVariable; ///
|
|
103
|
-
|
|
104
|
-
return termVariableNodeUnifiedAgainstTermNode;
|
|
105
|
-
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
nodeQueryA: termVariableNodeQuery,
|
|
64
|
+
nodeQueryB: termNodeQuery,
|
|
65
|
+
unify: (termVariableNodeA, termNodeB, substitutions, localContextA, localContextB, unifyAhead) => {
|
|
66
|
+
const variableNodeA = termVariableNodeA, ///
|
|
67
|
+
variableUnifiedAgainstTerm = unifyVariableAgainstTerm(variableNodeA, termNodeB, substitutions, localContextA, localContextB, unifyAhead);
|
|
68
|
+
|
|
69
|
+
return variableUnifiedAgainstTerm;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
];
|
|
106
73
|
}
|
|
107
74
|
|
|
108
75
|
const metaLevelUnifier = new MetaLevelUnifier();
|
|
@@ -1,103 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import shim from "../shim";
|
|
4
3
|
import Unifier from "../unifier";
|
|
5
|
-
import
|
|
4
|
+
import unifyTermAgainstType from "../unify/termAgainstType";
|
|
6
5
|
import unifyStatementAgainstMetaType from "../unify/statementAgainstMetaType";
|
|
7
6
|
|
|
8
|
-
import { unify } from "../unifier";
|
|
9
7
|
import { nodeQuery } from "../utilities/query";
|
|
10
8
|
|
|
11
|
-
const
|
|
9
|
+
const termNodeQuery = nodeQuery("/term!"),
|
|
10
|
+
typeNodeQuery = nodeQuery("/type!"),
|
|
12
11
|
metaTypeNodeQuery = nodeQuery("/metaType!"),
|
|
13
|
-
statementNodeQuery = nodeQuery("/statement!")
|
|
14
|
-
nonTerminalNodeQuery = nodeQuery("/*");
|
|
12
|
+
statementNodeQuery = nodeQuery("/statement!");
|
|
15
13
|
|
|
16
14
|
class StatementAgainstCombinatorUnifier extends Unifier {
|
|
17
|
-
|
|
18
|
-
let
|
|
15
|
+
unify(statementNode, combinatorStatementNode, localContext) {
|
|
16
|
+
let statementUnifiedAgainstCombinator;
|
|
19
17
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
unify: (nodeA, nodeB, localContext, unifyAhead) => {
|
|
25
|
-
let nonTerminalNodeUnified;
|
|
18
|
+
const nonTerminalNodeA = statementNode, ///
|
|
19
|
+
nonTerminalNodeB = combinatorStatementNode, ///
|
|
20
|
+
nonTerminalNodeUnified = this.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, localContext, () => {
|
|
21
|
+
const unifiedAhead = true;
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
statementUnifiedAgainstMetaType =
|
|
23
|
+
return unifiedAhead;
|
|
24
|
+
});
|
|
30
25
|
|
|
31
|
-
|
|
26
|
+
statementUnifiedAgainstCombinator = nonTerminalNodeUnified; ///
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
return statementUnifiedAgainstCombinator;
|
|
29
|
+
};
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
unify: (nodeA, nodeB, localContext, unifyAhead) => {
|
|
42
|
-
let nonTerminalNodeUnified;
|
|
31
|
+
static maps = [
|
|
32
|
+
{
|
|
33
|
+
nodeQueryA: statementNodeQuery,
|
|
34
|
+
nodeQueryB: metaTypeNodeQuery,
|
|
35
|
+
unify: (statementNodeA, metaTypeNodeB, localContext, unifyAhead) => {
|
|
36
|
+
const statementUnifiedAgainstMetaType = unifyStatementAgainstMetaType(statementNodeA, metaTypeNodeB, localContext, unifyAhead);
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
argumentNodeB = nodeB, ///
|
|
46
|
-
argumentNodeUnifiedAgainstArgumentNode =
|
|
47
|
-
|
|
48
|
-
this.unifyArgumentNodeAgainstArgumentNode(argumentNodeA, argumentNodeB, localContext, unifyAhead);
|
|
49
|
-
|
|
50
|
-
nonTerminalNodeUnified = argumentNodeUnifiedAgainstArgumentNode; ///
|
|
51
|
-
|
|
52
|
-
return nonTerminalNodeUnified;
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
nodeQueryA: nonTerminalNodeQuery,
|
|
57
|
-
nodeQueryB: nonTerminalNodeQuery,
|
|
58
|
-
unify: (nodeA, nodeB, localContext, unifyAhead) => {
|
|
59
|
-
let nonTerminalNodeUnified;
|
|
60
|
-
|
|
61
|
-
const nonTerminalNodeA = nodeA, ///
|
|
62
|
-
nonTerminalNodeB = nodeB; ///
|
|
63
|
-
|
|
64
|
-
nonTerminalNodeUnified =
|
|
65
|
-
|
|
66
|
-
super.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, localContext, unifyAhead);
|
|
67
|
-
|
|
68
|
-
return nonTerminalNodeUnified;
|
|
69
|
-
}
|
|
38
|
+
return statementUnifiedAgainstMetaType;
|
|
70
39
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const { verifyStatement } = shim,
|
|
84
|
-
metaTypeNode = metaTypeNodeB, ///
|
|
85
|
-
statementNode = statementNodeA; ///
|
|
86
|
-
|
|
87
|
-
statementUnifiedAgainstMetaType = unifyStatementAgainstMetaType(statementNode, metaTypeNode, localContext, unifyAhead, verifyStatement);
|
|
88
|
-
|
|
89
|
-
return statementUnifiedAgainstMetaType;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
unifyArgumentNodeAgainstArgumentNode(argumentNodeA, argumentNodeB, localContext, unifyAhead) {
|
|
93
|
-
let argumentNodeUnifiedAgainstArgumentNode;
|
|
94
|
-
|
|
95
|
-
const argumentUnifiedAgainstArgument = unifyArgumentAgainstArgument(argumentNodeA, argumentNodeB, localContext, unifyAhead);
|
|
96
|
-
|
|
97
|
-
argumentNodeUnifiedAgainstArgumentNode = argumentUnifiedAgainstArgument; ///
|
|
98
|
-
|
|
99
|
-
return argumentNodeUnifiedAgainstArgumentNode;
|
|
100
|
-
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
nodeQueryA: termNodeQuery,
|
|
43
|
+
nodeQueryB: typeNodeQuery,
|
|
44
|
+
unify: (termNodeA, typeNodeB, localContext, unifyAhead) => {
|
|
45
|
+
const termUnifiedAgainstType = unifyTermAgainstType(termNodeA, typeNodeB, localContext, unifyAhead);
|
|
46
|
+
|
|
47
|
+
return termUnifiedAgainstType;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
];
|
|
101
51
|
}
|
|
102
52
|
|
|
103
53
|
const statementAgainstCombinatorUnifier = new StatementAgainstCombinatorUnifier();
|
|
@@ -1,75 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import shim from "../shim";
|
|
4
3
|
import Unifier from "../unifier";
|
|
5
4
|
import unifyTermAgainstType from "../unify/termAgainstType";
|
|
6
5
|
|
|
7
|
-
import { unify } from "../unifier";
|
|
8
6
|
import { nodeQuery } from "../utilities/query";
|
|
9
7
|
|
|
10
|
-
const termNodeQuery = nodeQuery("/
|
|
11
|
-
typeNodeQuery = nodeQuery("/
|
|
12
|
-
nonTerminalNodeQuery = nodeQuery("/*");
|
|
8
|
+
const termNodeQuery = nodeQuery("/term"),
|
|
9
|
+
typeNodeQuery = nodeQuery("/type");
|
|
13
10
|
|
|
14
11
|
class TermAgainstConstructorUnifier extends Unifier {
|
|
15
|
-
|
|
16
|
-
let
|
|
12
|
+
unify(termNode, constructorTermNode, localContext, unifyAhead) {
|
|
13
|
+
let termUnifiedAgainstConstructor;
|
|
17
14
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
nodeQueryB: typeNodeQuery,
|
|
22
|
-
unify: (nodeA, nodeB, localContext, unifyAhead) => {
|
|
23
|
-
let nonTerminalNodUnified;
|
|
15
|
+
const nonTerminalNodeA = termNode, ///
|
|
16
|
+
nonTerminalNodeB = constructorTermNode, ///
|
|
17
|
+
nonTerminalNodeUnified = this.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, localContext, unifyAhead);
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
typeNodeB = nodeB, ///
|
|
27
|
-
termNodUnifiedAgainstTypeNode =
|
|
19
|
+
termUnifiedAgainstConstructor = nonTerminalNodeUnified; ///
|
|
28
20
|
|
|
29
|
-
|
|
21
|
+
return termUnifiedAgainstConstructor;
|
|
22
|
+
};
|
|
30
23
|
|
|
31
|
-
|
|
24
|
+
static maps = [
|
|
25
|
+
{
|
|
26
|
+
nodeQueryA: termNodeQuery,
|
|
27
|
+
nodeQueryB: typeNodeQuery,
|
|
28
|
+
unify: (termNodeA, typeNodeB, localContext, unifyAhead) => {
|
|
29
|
+
const termUnifiedAgainstType = unifyTermAgainstType(termNodeA, typeNodeB, localContext, unifyAhead);
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
nodeQueryA: nonTerminalNodeQuery,
|
|
38
|
-
nodeQueryB: nonTerminalNodeQuery,
|
|
39
|
-
unify: (nodeA, nodeB, localContext, unifyAhead) => {
|
|
40
|
-
let nonTerminalNodUnified;
|
|
41
|
-
|
|
42
|
-
const nonTerminalNodeA = nodeA, ///
|
|
43
|
-
nonTerminalNodeB = nodeB; ///
|
|
44
|
-
|
|
45
|
-
nonTerminalNodUnified =
|
|
46
|
-
|
|
47
|
-
super.unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, localContext, unifyAhead);
|
|
48
|
-
|
|
49
|
-
return nonTerminalNodUnified;
|
|
50
|
-
}
|
|
31
|
+
return termUnifiedAgainstType;
|
|
51
32
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const nodesVerified = unify(nodeQueryMaps, nonTerminalNodeA, nonTerminalNodeB, localContext, unifyAhead);
|
|
55
|
-
|
|
56
|
-
nonTerminalNodUnified = nodesVerified; ///
|
|
57
|
-
|
|
58
|
-
return nonTerminalNodUnified;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
unifyTermNodeAgainstTypeNode(termNodeA, typeNodeB, localContext, unifyAhead) {
|
|
62
|
-
let termNodUnifiedAgainstTypeNode;
|
|
63
|
-
|
|
64
|
-
const { verifyTerm } = shim,
|
|
65
|
-
termNode = termNodeA, ///
|
|
66
|
-
typeNode = typeNodeB, ///
|
|
67
|
-
typeUnifiedAgainstTerm = unifyTermAgainstType(termNode, typeNode, localContext, unifyAhead, verifyTerm);
|
|
68
|
-
|
|
69
|
-
termNodUnifiedAgainstTypeNode = typeUnifiedAgainstTerm; ///
|
|
70
|
-
|
|
71
|
-
return termNodUnifiedAgainstTypeNode;
|
|
72
|
-
}
|
|
33
|
+
}
|
|
34
|
+
];
|
|
73
35
|
}
|
|
74
36
|
|
|
75
37
|
const termAgainstConstructorUnifier = new TermAgainstConstructorUnifier();
|
package/src/unifier.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { nodeQuery } from "./utilities/query";
|
|
4
|
+
import { terminalNodeMapFromNodes, areTerminalNodeMapsEqual } from "./utilities/unifier";
|
|
5
|
+
|
|
6
|
+
const nonTerminalNodeQuery = nodeQuery("/*");
|
|
4
7
|
|
|
5
8
|
export default class Unifier {
|
|
9
|
+
unify(nodeA, nodeB, ...remainingArguments) {
|
|
10
|
+
let unified;
|
|
11
|
+
|
|
12
|
+
const nodeUnified = this.unifyNode(nodeA, nodeB, ...remainingArguments);
|
|
13
|
+
|
|
14
|
+
unified = nodeUnified; ///
|
|
15
|
+
|
|
16
|
+
return unified;
|
|
17
|
+
}
|
|
18
|
+
|
|
6
19
|
unifyNode(nodeA, nodeB, ...remainingArguments) {
|
|
7
20
|
let nodeUnified = false;
|
|
8
21
|
|
|
@@ -64,20 +77,52 @@ export default class Unifier {
|
|
|
64
77
|
}
|
|
65
78
|
|
|
66
79
|
unifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, ...remainingArguments) {
|
|
67
|
-
let nonTerminalNodeUnified
|
|
80
|
+
let nonTerminalNodeUnified;
|
|
68
81
|
|
|
69
|
-
|
|
70
|
-
nonTerminalNodeBRuleName = nonTerminalNodeB.getRuleName(); ///
|
|
82
|
+
let { maps } = this.constructor;
|
|
71
83
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
maps = [ ///
|
|
85
|
+
...maps,
|
|
86
|
+
{
|
|
87
|
+
nodeQueryA: nonTerminalNodeQuery,
|
|
88
|
+
nodeQueryB: nonTerminalNodeQuery,
|
|
89
|
+
unify: (nodeA, nobeB, ...remainingArguments) => {
|
|
90
|
+
let nonTerminalNodeUnified;
|
|
78
91
|
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
const nonTerminalNodeARuleName = nonTerminalNodeA.getRuleName(), ///
|
|
93
|
+
nonTerminalNodeBRuleName = nonTerminalNodeB.getRuleName(); ///
|
|
94
|
+
|
|
95
|
+
if (nonTerminalNodeARuleName === nonTerminalNodeBRuleName) {
|
|
96
|
+
const nonTerminalNodeAChildNodes = nonTerminalNodeA.getChildNodes(),
|
|
97
|
+
nonTerminalNodeBChildNodes = nonTerminalNodeB.getChildNodes(),
|
|
98
|
+
childNodesA = nonTerminalNodeAChildNodes, ///
|
|
99
|
+
childNodesB = nonTerminalNodeBChildNodes, ///
|
|
100
|
+
childNodesUnified = this.unifyChildNodes(childNodesA, childNodesB, ...remainingArguments);
|
|
101
|
+
|
|
102
|
+
nonTerminalNodeUnified = childNodesUnified; ///
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return nonTerminalNodeUnified;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
let nodeUnified = false;
|
|
111
|
+
|
|
112
|
+
maps.some((map) => {
|
|
113
|
+
const { nodeQueryA, nodeQueryB, unify } = map;
|
|
114
|
+
|
|
115
|
+
const nodeA = nodeQueryA(nonTerminalNodeA), ///
|
|
116
|
+
nodeB = nodeQueryB(nonTerminalNodeB); ///
|
|
117
|
+
|
|
118
|
+
if ((nodeA !== null) && (nodeB !== null)) {
|
|
119
|
+
nodeUnified = unify(nodeA, nodeB, ...remainingArguments);
|
|
120
|
+
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
nonTerminalNodeUnified = nodeUnified; ///
|
|
81
126
|
|
|
82
127
|
return nonTerminalNodeUnified;
|
|
83
128
|
}
|
|
@@ -112,22 +157,3 @@ export default class Unifier {
|
|
|
112
157
|
return childNodesUnified;
|
|
113
158
|
}
|
|
114
159
|
}
|
|
115
|
-
|
|
116
|
-
export function unify(nodeQueryMaps, nonTerminalNodeA, nonTerminalNodeB, ...remainingArguments) {
|
|
117
|
-
let unified = false;
|
|
118
|
-
|
|
119
|
-
nodeQueryMaps.some((nodeQueryMap) => {
|
|
120
|
-
const { nodeQueryA, nodeQueryB, unify } = nodeQueryMap;
|
|
121
|
-
|
|
122
|
-
const nodeA = nodeQueryA(nonTerminalNodeA), ///
|
|
123
|
-
nodeB = nodeQueryB(nonTerminalNodeB); ///
|
|
124
|
-
|
|
125
|
-
if ((nodeA !== null) && (nodeB !== null)) {
|
|
126
|
-
unified = unify(nodeA, nodeB, ...remainingArguments);
|
|
127
|
-
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return unified;
|
|
133
|
-
}
|
|
@@ -4,7 +4,7 @@ import TermForVariableSubstitution from "../substitution/termForVariable";
|
|
|
4
4
|
import unifyStatementAgainstStatement from "../unify/statementAtainstStatement";
|
|
5
5
|
import StatementForMetavariableSubstitution from "../substitution/statementForMetavariable";
|
|
6
6
|
|
|
7
|
-
export default function unifyMetavariableAgainstStatement(metavariableNodeA, statementNodeB,
|
|
7
|
+
export default function unifyMetavariableAgainstStatement(metavariableNodeA, statementNodeB, substitutionNodeA, substitutions, localContextA, localContextB, unifyAhead) {
|
|
8
8
|
let metavariableUnifiedAgainstStatement = false;
|
|
9
9
|
|
|
10
10
|
const substitution = substitutions.find((substitution) => {
|
|
@@ -18,8 +18,9 @@ export default function unifyMetavariableAgainstStatement(metavariableNodeA, sta
|
|
|
18
18
|
if (substitution !== null) {
|
|
19
19
|
const substitutionStatementNode = substitution.getStatementNode();
|
|
20
20
|
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
21
|
+
if (substitutionNodeA !== null) {
|
|
22
|
+
const substitutionNode = substitutionNodeA, ///
|
|
23
|
+
termForVariableSubstitution = TermForVariableSubstitution.fromSubstitutionNode(substitutionNode),
|
|
23
24
|
localContext = localContextB, ///
|
|
24
25
|
substitution = termForVariableSubstitution, ///
|
|
25
26
|
statementNodeA = substitutionStatementNode, ///
|
|
@@ -61,6 +62,7 @@ export default function unifyMetavariableAgainstStatement(metavariableNodeA, sta
|
|
|
61
62
|
let unifiedAhead;
|
|
62
63
|
|
|
63
64
|
const statementNode = statementNodeB, ///
|
|
65
|
+
substitutionNode = substitutionNodeA, ///
|
|
64
66
|
metavariableNode = metavariableNodeA, ///
|
|
65
67
|
statementForMetavariableSubstitution = StatementForMetavariableSubstitution.fromMetavariableNodeStatementNodeAndSubstitutionNode(metavariableNode, statementNode, substitutionNode),
|
|
66
68
|
substitution = statementForMetavariableSubstitution; ///
|