occam-verify-cli 0.0.1016 → 0.0.1020
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/argument.js +12 -11
- package/lib/assignment/equality.js +3 -3
- package/lib/axiom.js +102 -6
- package/lib/combinator.js +12 -12
- package/lib/conclusion.js +3 -4
- package/lib/consequent.js +75 -14
- package/lib/constructor/bracketed.js +3 -3
- package/lib/constructor.js +68 -18
- package/lib/context/file.js +49 -89
- package/lib/context/local.js +34 -58
- package/lib/declaration/combinator.js +3 -3
- package/lib/declaration/metavariable.js +15 -4
- package/lib/declaration/type.js +3 -3
- package/lib/declaration/variable.js +146 -0
- package/lib/equality.js +95 -19
- package/lib/index.js +6 -1
- package/lib/label.js +9 -9
- package/lib/lemma.js +107 -6
- package/lib/metavariable.js +14 -21
- package/lib/mixins/statement/qualified/unify.js +3 -3
- package/lib/mixins/statement/verify.js +4 -5
- package/lib/mixins/term/unify.js +82 -0
- package/lib/mixins/term/verify.js +44 -0
- package/lib/node/term/constructor/bracketed.js +15 -11
- package/lib/premise.js +3 -5
- package/lib/proofStep.js +2 -2
- package/lib/reference.js +9 -9
- package/lib/rule.js +5 -5
- package/lib/ruleNames.js +5 -5
- package/lib/statement/qualified.js +6 -3
- package/lib/statement.js +22 -39
- package/lib/supposition.js +75 -50
- package/lib/term.js +62 -16
- package/lib/topLevelAssertion.js +98 -33
- package/lib/type.js +22 -31
- package/lib/unifier/equality.js +12 -4
- package/lib/unifier/intrinsicLevel.js +1 -4
- package/lib/unifier/metaLevel.js +1 -4
- package/lib/unifier/metavariable.js +10 -7
- package/lib/unifier/statementWithCombinator.js +18 -9
- package/lib/unifier/termWithConstructor.js +11 -4
- package/lib/unify/frameWithMetaType.js +2 -2
- package/lib/utilities/name.js +9 -2
- package/lib/utilities/node.js +14 -14
- package/lib/utilities/tokens.js +7 -7
- package/lib/utilities/unify.js +3 -3
- package/lib/variable.js +155 -20
- package/lib/verifier/statementAsCombinator.js +2 -2
- package/lib/verifier/termAsConstructor.js +2 -2
- package/lib/verifier/topLevel.js +7 -7
- package/lib/verify/assertion/type.js +3 -4
- package/lib/verify/conjecture.js +2 -3
- package/lib/verify/frame.js +2 -6
- package/lib/verify/lemma.js +2 -3
- package/lib/verify/metaLemma.js +2 -3
- package/lib/verify/metatheorem.js +2 -3
- package/lib/verify/metavariableGivenMetaType.js +3 -3
- package/lib/verify/theorem.js +2 -3
- package/package.json +1 -1
- package/src/argument.js +11 -9
- package/src/assignment/equality.js +3 -4
- package/src/axiom.js +78 -1
- package/src/combinator.js +10 -9
- package/src/conclusion.js +2 -4
- package/src/consequent.js +88 -13
- package/src/constructor/bracketed.js +4 -1
- package/src/constructor.js +18 -14
- package/src/context/file.js +50 -93
- package/src/context/local.js +13 -31
- package/src/declaration/combinator.js +2 -2
- package/src/declaration/metavariable.js +20 -6
- package/src/declaration/type.js +2 -2
- package/src/declaration/variable.js +78 -0
- package/src/equality.js +123 -22
- package/src/index.js +6 -0
- package/src/label.js +7 -7
- package/src/lemma.js +91 -1
- package/src/metavariable.js +13 -22
- package/src/mixins/statement/qualified/unify.js +2 -2
- package/src/mixins/statement/verify.js +5 -5
- package/src/mixins/term/unify.js +110 -0
- package/src/mixins/term/verify.js +47 -0
- package/src/node/term/constructor/bracketed.js +4 -3
- package/src/premise.js +2 -5
- package/src/proofStep.js +1 -1
- package/src/reference.js +7 -7
- package/src/rule.js +4 -4
- package/src/ruleNames.js +1 -1
- package/src/statement/qualified.js +7 -3
- package/src/statement.js +28 -60
- package/src/supposition.js +106 -53
- package/src/term.js +70 -14
- package/src/topLevelAssertion.js +120 -33
- package/src/type.js +39 -41
- package/src/unifier/equality.js +15 -3
- package/src/unifier/intrinsicLevel.js +0 -4
- package/src/unifier/metaLevel.js +0 -4
- package/src/unifier/metavariable.js +16 -8
- package/src/unifier/statementWithCombinator.js +33 -11
- package/src/unifier/termWithConstructor.js +17 -4
- package/src/unify/frameWithMetaType.js +1 -1
- package/src/utilities/name.js +9 -1
- package/src/utilities/node.js +14 -14
- package/src/utilities/tokens.js +4 -4
- package/src/utilities/unify.js +2 -2
- package/src/variable.js +158 -22
- package/src/verifier/statementAsCombinator.js +1 -1
- package/src/verifier/termAsConstructor.js +1 -1
- package/src/verifier/topLevel.js +9 -6
- package/src/verify/assertion/type.js +1 -1
- package/src/verify/conjecture.js +1 -1
- package/src/verify/frame.js +1 -7
- package/src/verify/lemma.js +1 -1
- package/src/verify/metaLemma.js +1 -1
- package/src/verify/metatheorem.js +1 -1
- package/src/verify/metavariableGivenMetaType.js +2 -2
- package/src/verify/theorem.js +1 -1
- package/lib/tokens/constructorTerm/bracketed.js +0 -17
- package/lib/unify/termWithBracketedConstructor.js +0 -39
- package/lib/unify/termWithConstructor.js +0 -37
- package/lib/unify/termWithConstructors.js +0 -34
- package/lib/unify/termWithTerm.js +0 -27
- package/lib/unify/termWithType.js +0 -24
- package/lib/verify/axiom.js +0 -45
- package/lib/verify/consequent.js +0 -38
- package/lib/verify/declaration/variable.js +0 -67
- package/lib/verify/equality.js +0 -92
- package/lib/verify/proofStep.js +0 -28
- package/lib/verify/term.js +0 -97
- package/lib/verify/termAsConstructor.js +0 -58
- package/lib/verify/termGivenType.js +0 -34
- package/lib/verify/terms.js +0 -38
- package/lib/verify/type.js +0 -23
- package/lib/verify/variable.js +0 -25
- package/src/tokens/constructorTerm/bracketed.js +0 -10
- package/src/unify/termWithBracketedConstructor.js +0 -39
- package/src/unify/termWithConstructor.js +0 -39
- package/src/unify/termWithConstructors.js +0 -27
- package/src/unify/termWithTerm.js +0 -24
- package/src/unify/termWithType.js +0 -14
- package/src/verify/axiom.js +0 -56
- package/src/verify/consequent.js +0 -40
- package/src/verify/declaration/variable.js +0 -85
- package/src/verify/equality.js +0 -118
- package/src/verify/proofStep.js +0 -21
- package/src/verify/term.js +0 -123
- package/src/verify/termAsConstructor.js +0 -66
- package/src/verify/termGivenType.js +0 -32
- package/src/verify/terms.js +0 -38
- package/src/verify/type.js +0 -19
- package/src/verify/variable.js +0 -21
package/src/topLevelAssertion.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import Label from "./label";
|
|
4
|
+
import Consequent from "./consequent";
|
|
5
|
+
import Supposition from "./supposition";
|
|
3
6
|
import Substitutions from "./substitutions";
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import unifySuppositionsWithProofSteps from "./unify/suppositionsWithProofSteps";
|
|
7
|
+
|
|
8
|
+
import { reverse, correlate } from "./utilities/array";
|
|
7
9
|
|
|
8
10
|
export default class TopLevelAssertion {
|
|
9
|
-
constructor(labels, suppositions, consequent,
|
|
11
|
+
constructor(fileContext, labels, suppositions, consequent, proof) {
|
|
12
|
+
this.fileContext = fileContext;
|
|
10
13
|
this.labels = labels;
|
|
11
14
|
this.suppositions = suppositions;
|
|
12
15
|
this.consequent = consequent;
|
|
13
|
-
this.
|
|
14
|
-
|
|
16
|
+
this.proof = proof;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getFileContext() {
|
|
20
|
+
return this.fileContext;
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
getLabels() {
|
|
@@ -26,50 +32,131 @@ export default class TopLevelAssertion {
|
|
|
26
32
|
return this.consequent;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
return this.
|
|
35
|
+
getProof() {
|
|
36
|
+
return this.proof;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
matchMetavariableNode(metavariableNode) {
|
|
40
|
+
const metavariableNodeMatches = this.labels.some((label) => {
|
|
41
|
+
const metavariableNodeMatches = label.matchMetavariableNode(metavariableNode);
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
if (metavariableNodeMatches) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
39
47
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
proofStepsB = proofSteps, ///
|
|
43
|
-
fileContextA = this.fileContext, ///
|
|
44
|
-
suppositionsA = this.suppositions, ///
|
|
45
|
-
localContextB = localContext, ///
|
|
46
|
-
suppositionsUnified = unifySuppositionsWithProofSteps(suppositionsA, proofStepsB, substitutions, fileContextA, localContextB);
|
|
48
|
+
return metavariableNodeMatches;
|
|
49
|
+
}
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
consequentUnified = unifyConsequentWithStatement(consequentA, statementNode, substitutions, fileContextA, localContext);
|
|
51
|
+
unifyStatement(statement, localContext) {
|
|
52
|
+
let statementUnified = false;
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
const proofSteps = localContext.getProofSteps(),
|
|
55
|
+
substitutions = Substitutions.fromNothing(),
|
|
56
|
+
proofStepsUnified = this.unifyProofSteps(proofSteps, substitutions, localContext);
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
if (proofStepsUnified) {
|
|
59
|
+
statementUnified = this.consequent.unifyStatement(statement, substitutions, localContext);
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
return statementUnified;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const metavariableNodeMatches = label.matchMetavariableNode(metavariableNode);
|
|
65
|
+
unifyProofSteps(proofSteps, substitutions, localContext) {
|
|
66
|
+
let proofStepsUnified;
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
let suppositions = this.suppositions;
|
|
69
|
+
|
|
70
|
+
suppositions = reverse(suppositions); ///
|
|
71
|
+
|
|
72
|
+
proofSteps = reverse(proofSteps); ///
|
|
73
|
+
|
|
74
|
+
proofStepsUnified = correlate(suppositions, proofSteps, (supposition, proofStep) => {
|
|
75
|
+
const proofStepUnified = supposition.unifyProofStep(proofStep, substitutions, localContext);
|
|
76
|
+
|
|
77
|
+
if (proofStepUnified) {
|
|
67
78
|
return true;
|
|
68
79
|
}
|
|
69
80
|
});
|
|
70
81
|
|
|
71
|
-
return
|
|
82
|
+
return proofStepsUnified;
|
|
72
83
|
}
|
|
73
84
|
|
|
74
|
-
|
|
85
|
+
toJSON() {
|
|
86
|
+
const labelsJSON = this.labels.map((label) => {
|
|
87
|
+
const labelJSON = label.toJSON();
|
|
88
|
+
|
|
89
|
+
return labelJSON;
|
|
90
|
+
}),
|
|
91
|
+
suppositionsJSON = this.suppositions.map((supposition) => {
|
|
92
|
+
const suppositionJSON = supposition.toJSON();
|
|
93
|
+
|
|
94
|
+
return suppositionJSON;
|
|
95
|
+
}),
|
|
96
|
+
consequentJSON = this.consequent.toJSON(),
|
|
97
|
+
labels = labelsJSON, ///
|
|
98
|
+
suppositions = suppositionsJSON, ///
|
|
99
|
+
consequent = consequentJSON, ///
|
|
100
|
+
json = {
|
|
101
|
+
labels,
|
|
102
|
+
suppositions,
|
|
103
|
+
consequent
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return json;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static fromJSON(Class, json, fileContext) {
|
|
110
|
+
let rule;
|
|
111
|
+
|
|
112
|
+
let { labels } = json;
|
|
113
|
+
|
|
114
|
+
const labelsJSON = labels; ///
|
|
115
|
+
|
|
116
|
+
labels = labelsJSON.map((labelJSON) => {
|
|
117
|
+
const json = labelJSON, ///
|
|
118
|
+
label = Label.fromJSON(json, fileContext);
|
|
119
|
+
|
|
120
|
+
return label;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
let { suppositions } = json;
|
|
124
|
+
|
|
125
|
+
const suppositionsJSON = suppositions; ///
|
|
126
|
+
|
|
127
|
+
suppositions = suppositionsJSON.map((suppositionJSON) => {
|
|
128
|
+
const json = suppositionJSON, ///
|
|
129
|
+
supposition = Supposition.fromJSON(json, fileContext);
|
|
130
|
+
|
|
131
|
+
return supposition;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
let { consequent } = json;
|
|
135
|
+
|
|
136
|
+
const consequentJSON = consequent; ///
|
|
137
|
+
|
|
138
|
+
json = consequentJSON; ///
|
|
139
|
+
|
|
140
|
+
consequent = Consequent.fromJSON(json, fileContext);
|
|
141
|
+
|
|
142
|
+
const proof = null;
|
|
143
|
+
|
|
144
|
+
rule = new Class(fileContext, labels, suppositions, consequent, proof);
|
|
145
|
+
|
|
146
|
+
return rule;
|
|
147
|
+
}
|
|
75
148
|
}
|
|
149
|
+
|
|
150
|
+
export function labelsStringFromLabels(labels) {
|
|
151
|
+
const labelsString = labels.reduce((labelsString, label) => {
|
|
152
|
+
const labelString = label.getString();
|
|
153
|
+
|
|
154
|
+
labelsString = (labelsString === null) ?
|
|
155
|
+
labelString: ///
|
|
156
|
+
`${labelString}, ${labelString}`;
|
|
157
|
+
|
|
158
|
+
return labelsString;
|
|
159
|
+
}, null);
|
|
160
|
+
|
|
161
|
+
return labelsString;
|
|
162
|
+
}
|
package/src/type.js
CHANGED
|
@@ -74,7 +74,7 @@ class Type {
|
|
|
74
74
|
const equalTo = this.isEqualTo(type),
|
|
75
75
|
subTypeOf = this.isSubTypeOf(type),
|
|
76
76
|
superTypeOf = this.isSuperTypeOf(type),
|
|
77
|
-
comparableTo = equalTo || subTypeOf || superTypeOf;
|
|
77
|
+
comparableTo = (equalTo || subTypeOf || superTypeOf);
|
|
78
78
|
|
|
79
79
|
return comparableTo;
|
|
80
80
|
}
|
|
@@ -82,7 +82,7 @@ class Type {
|
|
|
82
82
|
isEqualToOrSubTypeOf(type) {
|
|
83
83
|
const equalTo = this.isEqualTo(type),
|
|
84
84
|
subTypeOf = this.isSubTypeOf(type),
|
|
85
|
-
equalToOrSubTypeOf = equalTo || subTypeOf;
|
|
85
|
+
equalToOrSubTypeOf = (equalTo || subTypeOf);
|
|
86
86
|
|
|
87
87
|
return equalToOrSubTypeOf;
|
|
88
88
|
}
|
|
@@ -90,7 +90,7 @@ class Type {
|
|
|
90
90
|
isEqualToOrSuperTypeOf(type) {
|
|
91
91
|
const equalTo = this.isEqualTo(type),
|
|
92
92
|
superTypeOf = this.isSuperTypeOf(type),
|
|
93
|
-
equalToOrSuperTypeOf = equalTo || superTypeOf;
|
|
93
|
+
equalToOrSuperTypeOf = (equalTo || superTypeOf);
|
|
94
94
|
|
|
95
95
|
return equalToOrSuperTypeOf;
|
|
96
96
|
}
|
|
@@ -124,37 +124,31 @@ class Type {
|
|
|
124
124
|
verify(fileContext) {
|
|
125
125
|
let verified = false;
|
|
126
126
|
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
if (nameObjectTypeName) {
|
|
130
|
-
verified = true;
|
|
131
|
-
} else {
|
|
132
|
-
const typeString = this.string; ///
|
|
127
|
+
const typeString = this.string; ///
|
|
133
128
|
|
|
134
|
-
|
|
129
|
+
fileContext.trace(`Verifying the '${typeString}' type...`);
|
|
135
130
|
|
|
136
|
-
|
|
131
|
+
const typePresent = fileContext.isTypePresentByTypeName(this.name);
|
|
137
132
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
133
|
+
if (typePresent) {
|
|
134
|
+
verified = true;
|
|
135
|
+
} else {
|
|
136
|
+
fileContext.debug(`The type '${typeString}' is not present.`);
|
|
137
|
+
}
|
|
143
138
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
139
|
+
if (verified) {
|
|
140
|
+
fileContext.debug(`...verified the '${typeString}' type.`);
|
|
147
141
|
}
|
|
148
142
|
|
|
149
143
|
return verified;
|
|
150
144
|
}
|
|
151
145
|
|
|
152
|
-
|
|
153
|
-
let
|
|
146
|
+
verifyAtTopLevel(fileContext) {
|
|
147
|
+
let verifiedAtTopLevel = false;
|
|
154
148
|
|
|
155
149
|
const typeString = this.string; ///
|
|
156
150
|
|
|
157
|
-
fileContext.trace(`Verifying the '${typeString}' type
|
|
151
|
+
fileContext.trace(`Verifying the '${typeString}' type at top level...`);
|
|
158
152
|
|
|
159
153
|
const typePresent = fileContext.isTypePresentByTypeName(this.name);
|
|
160
154
|
|
|
@@ -162,13 +156,13 @@ class Type {
|
|
|
162
156
|
fileContext.debug(`The type '${typeString}' is already present.`);
|
|
163
157
|
} else {
|
|
164
158
|
if (this.superType === null) {
|
|
165
|
-
|
|
159
|
+
verifiedAtTopLevel = true;
|
|
166
160
|
} else {
|
|
167
161
|
const name = this.superType.getName(),
|
|
168
|
-
|
|
162
|
+
superTypePresent = fileContext.isTypePresentByTypeName(name);
|
|
169
163
|
|
|
170
164
|
if (superTypePresent) {
|
|
171
|
-
|
|
165
|
+
verifiedAtTopLevel = true;
|
|
172
166
|
} else {
|
|
173
167
|
const superTypeString = this.superType.getString();
|
|
174
168
|
|
|
@@ -177,11 +171,11 @@ class Type {
|
|
|
177
171
|
}
|
|
178
172
|
}
|
|
179
173
|
|
|
180
|
-
if (
|
|
181
|
-
fileContext.debug(`...
|
|
174
|
+
if (verifiedAtTopLevel) {
|
|
175
|
+
fileContext.debug(`...verified the '${typeString}' type at top level.`);
|
|
182
176
|
}
|
|
183
177
|
|
|
184
|
-
return
|
|
178
|
+
return verifiedAtTopLevel;
|
|
185
179
|
}
|
|
186
180
|
|
|
187
181
|
toJSON() {
|
|
@@ -213,22 +207,23 @@ class Type {
|
|
|
213
207
|
|
|
214
208
|
const typeName = name, ///
|
|
215
209
|
string = stringFromTypeNameAndSuperType(typeName, superType),
|
|
216
|
-
|
|
210
|
+
typeNameObjectTypeName = (typeName === OBJECT_TYPE_NAME),
|
|
211
|
+
type = typeNameObjectTypeName ?
|
|
212
|
+
objectType :
|
|
213
|
+
new Type(string, name, superType);
|
|
217
214
|
|
|
218
215
|
return type;
|
|
219
216
|
}
|
|
220
217
|
|
|
221
218
|
static fromTypeNode(typeNode) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
type = new Type(string, name, superType);
|
|
231
|
-
}
|
|
219
|
+
const typeName = typeNameFromTypeNode(typeNode),
|
|
220
|
+
name = typeName, ///
|
|
221
|
+
string = name, ///
|
|
222
|
+
superType = null,
|
|
223
|
+
typeNameObjectTypeName = (typeName === OBJECT_TYPE_NAME),
|
|
224
|
+
type = typeNameObjectTypeName ?
|
|
225
|
+
objectType :
|
|
226
|
+
new Type(string, name, superType);
|
|
232
227
|
|
|
233
228
|
return type;
|
|
234
229
|
}
|
|
@@ -237,7 +232,9 @@ class Type {
|
|
|
237
232
|
const typeNode = typeNodeQuery(typeDeclarationNode),
|
|
238
233
|
superTypeNode = superTypeNodeQuery(typeDeclarationNode),
|
|
239
234
|
typeName = typeNameFromTypeNode(typeNode),
|
|
240
|
-
superType =
|
|
235
|
+
superType = (superTypeNode === null) ?
|
|
236
|
+
objectType :
|
|
237
|
+
Type.fromTypeNode(superTypeNode),
|
|
241
238
|
string = stringFromTypeNameAndSuperType(typeName, superType),
|
|
242
239
|
name = typeName, ///
|
|
243
240
|
type = new Type(string, name, superType);
|
|
@@ -268,8 +265,9 @@ export default Type;
|
|
|
268
265
|
class ObjectType extends Type {
|
|
269
266
|
static fromNothing() {
|
|
270
267
|
const name = OBJECT_TYPE_NAME,
|
|
268
|
+
string = name, //
|
|
271
269
|
superType = null,
|
|
272
|
-
objectType = new ObjectType(name, superType);
|
|
270
|
+
objectType = new ObjectType(string, name, superType);
|
|
273
271
|
|
|
274
272
|
return objectType;
|
|
275
273
|
}
|
package/src/unifier/equality.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Unifier from "../unifier";
|
|
4
|
-
import unifyTermWithTerm from "../unify/termWithTerm";
|
|
5
4
|
|
|
6
5
|
import { nodeQuery } from "../utilities/query";
|
|
6
|
+
import { findEquivalenceByTermNodes } from "../utilities/equivalences";
|
|
7
7
|
|
|
8
8
|
const termNodeQuery = nodeQuery("/term!");
|
|
9
9
|
|
|
@@ -28,9 +28,21 @@ class EqualityUnifier extends Unifier {
|
|
|
28
28
|
let termUnifiedWithTerm;
|
|
29
29
|
|
|
30
30
|
const leftTermNode = termNodeA, ///
|
|
31
|
-
rightTermNode = termNodeB
|
|
31
|
+
rightTermNode = termNodeB, ///
|
|
32
|
+
leftTermNodeMatchesRightTermNode = leftTermNode.match(rightTermNode);
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
if (leftTermNodeMatchesRightTermNode) {
|
|
35
|
+
termUnifiedWithTerm = true;
|
|
36
|
+
} else {
|
|
37
|
+
const equivalences = localContext.getEquivalences(),
|
|
38
|
+
termNodes = [
|
|
39
|
+
leftTermNode,
|
|
40
|
+
rightTermNode
|
|
41
|
+
],
|
|
42
|
+
equivalence = findEquivalenceByTermNodes(equivalences, termNodes);
|
|
43
|
+
|
|
44
|
+
termUnifiedWithTerm = (equivalence !== null);
|
|
45
|
+
}
|
|
34
46
|
|
|
35
47
|
if (!termUnifiedWithTerm) {
|
|
36
48
|
const nonTerminalNodeA = termNodeA, ///
|
package/src/unifier/metaLevel.js
CHANGED
|
@@ -91,10 +91,6 @@ class MetaLevelUnifier extends Unifier {
|
|
|
91
91
|
|
|
92
92
|
const metaLevelUnifier = new MetaLevelUnifier();
|
|
93
93
|
|
|
94
|
-
Object.assign(shim, {
|
|
95
|
-
metaLevelUnifier
|
|
96
|
-
});
|
|
97
|
-
|
|
98
94
|
export default metaLevelUnifier;
|
|
99
95
|
|
|
100
96
|
function unifyStatementWithStatement(statementNodeA, statementNodeB, substitutions, localContextA, localContextB) {
|
|
@@ -4,7 +4,6 @@ import shim from "../shim";
|
|
|
4
4
|
import Unifier from "../unifier";
|
|
5
5
|
|
|
6
6
|
import { nodeQuery } from "../utilities/query";
|
|
7
|
-
import unifyTermWithType from "../unify/termWithType";
|
|
8
7
|
|
|
9
8
|
const typeNodeQuery = nodeQuery("/type!"),
|
|
10
9
|
termNodeQuery = nodeQuery("/term!");
|
|
@@ -27,11 +26,24 @@ class MetavariableUnifier extends Unifier {
|
|
|
27
26
|
nodeQueryA: termNodeQuery,
|
|
28
27
|
nodeQueryB: typeNodeQuery,
|
|
29
28
|
unify: (termNodeA, typeNodeB, localContext) => {
|
|
30
|
-
|
|
29
|
+
let unified = false;
|
|
30
|
+
|
|
31
|
+
const { Term, Type } = shim,
|
|
31
32
|
typeNode = typeNodeB, ///
|
|
32
|
-
|
|
33
|
+
type = Type.fromTypeNode(typeNode, localContext),
|
|
34
|
+
typeVerified = type.verify(localContext);
|
|
35
|
+
|
|
36
|
+
if (typeVerified) {
|
|
37
|
+
const termNode = termNodeA, ///
|
|
38
|
+
term = Term.fromTermNode(termNode, localContext),
|
|
39
|
+
termVerifiedGivenType = term.verifyGivenType(type, localContext);
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
if (termVerifiedGivenType) {
|
|
42
|
+
unified = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return unified;
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
];
|
|
@@ -39,8 +51,4 @@ class MetavariableUnifier extends Unifier {
|
|
|
39
51
|
|
|
40
52
|
const metavariableUnifier = new MetavariableUnifier();
|
|
41
53
|
|
|
42
|
-
Object.assign(shim, {
|
|
43
|
-
metavariableUnifier
|
|
44
|
-
});
|
|
45
|
-
|
|
46
54
|
export default metavariableUnifier;
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import shim from "../shim";
|
|
4
4
|
import Unifier from "../unifier";
|
|
5
|
-
import unifyTermWithType from "../unify/termWithType";
|
|
6
|
-
import unifyFrameWithMetaType from "../unify/frameWithMetaType";
|
|
7
5
|
|
|
8
6
|
import { nodeQuery } from "../utilities/query";
|
|
9
7
|
|
|
@@ -31,36 +29,60 @@ class StatementWithCombinatorUnifier extends Unifier {
|
|
|
31
29
|
nodeQueryA: statementNodeQuery,
|
|
32
30
|
nodeQueryB: metaTypeNodeQuery,
|
|
33
31
|
unify: (statementNodeA, metaTypeNodeB, assignments, stated, localContext) => {
|
|
34
|
-
|
|
32
|
+
let unified;
|
|
33
|
+
|
|
34
|
+
const { Statement, MetaType } = shim,
|
|
35
35
|
metaTypeNode = metaTypeNodeB, ///
|
|
36
36
|
statementNode = statementNodeA, ///
|
|
37
37
|
metaType = MetaType.fromMetaTypeNode(metaTypeNode, localContext),
|
|
38
38
|
statement = Statement.fromStatementNode(statementNode, localContext),
|
|
39
|
-
|
|
39
|
+
statementVerifiedGivenType = statement.verifyGivenMetaType(metaType, assignments, stated, localContext);
|
|
40
|
+
|
|
41
|
+
unified = statementVerifiedGivenType;
|
|
40
42
|
|
|
41
|
-
return
|
|
43
|
+
return unified;
|
|
42
44
|
}
|
|
43
45
|
},
|
|
44
46
|
{
|
|
45
47
|
nodeQueryA: frameNodeQuery,
|
|
46
48
|
nodeQueryB: metaTypeNodeQuery,
|
|
47
49
|
unify: (frameNodeA, metaTypeNodeB, assignments, stated, localContext) => {
|
|
48
|
-
|
|
50
|
+
let unified;
|
|
51
|
+
|
|
52
|
+
const { Frame, MetaType } = shim,
|
|
53
|
+
metaTypeNode = metaTypeNodeB, ///
|
|
49
54
|
frameNode = frameNodeA, ///
|
|
50
|
-
|
|
55
|
+
metaType = MetaType.fromMetaTypeNode(metaTypeNode, localContext),
|
|
56
|
+
frame = Frame.fromTermNode(frameNode, localContext),
|
|
57
|
+
frameVerifiedGivenType = frame.verifyGivenMetaType(metaType, localContext);
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
unified = frameVerifiedGivenType;
|
|
60
|
+
|
|
61
|
+
return unified;
|
|
53
62
|
}
|
|
54
63
|
},
|
|
55
64
|
{
|
|
56
65
|
nodeQueryA: termNodeQuery,
|
|
57
66
|
nodeQueryB: typeNodeQuery,
|
|
58
67
|
unify: (termNodeA, typeNodeB, assignments, stated, localContext) => {
|
|
59
|
-
|
|
68
|
+
let unified = false;
|
|
69
|
+
|
|
70
|
+
const { Term, Type } = shim,
|
|
60
71
|
typeNode = typeNodeB, ///
|
|
61
|
-
|
|
72
|
+
type = Type.fromTypeNode(typeNode, localContext),
|
|
73
|
+
typeVerified = type.verify(localContext);
|
|
74
|
+
|
|
75
|
+
if (typeVerified) {
|
|
76
|
+
const termNode = termNodeA, ///
|
|
77
|
+
term = Term.fromTermNode(termNode, localContext),
|
|
78
|
+
termVerifiedGivenType = term.verifyGivenType(type, localContext);
|
|
79
|
+
|
|
80
|
+
if (termVerifiedGivenType) {
|
|
81
|
+
unified = true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
62
84
|
|
|
63
|
-
return
|
|
85
|
+
return unified;
|
|
64
86
|
}
|
|
65
87
|
}
|
|
66
88
|
];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import shim from "../shim";
|
|
3
4
|
import Unifier from "../unifier";
|
|
4
|
-
import unifyTermWithType from "../unify/termWithType";
|
|
5
5
|
|
|
6
6
|
import { nodeQuery } from "../utilities/query";
|
|
7
7
|
|
|
@@ -26,11 +26,24 @@ class TermWithConstructorUnifier extends Unifier {
|
|
|
26
26
|
nodeQueryA: termNodeQuery,
|
|
27
27
|
nodeQueryB: typeNodeQuery,
|
|
28
28
|
unify: (termNodeA, typeNodeB, localContext) => {
|
|
29
|
-
|
|
29
|
+
let unified = false;
|
|
30
|
+
|
|
31
|
+
const { Term, Type } = shim,
|
|
30
32
|
typeNode = typeNodeB, ///
|
|
31
|
-
|
|
33
|
+
type = Type.fromTypeNode(typeNode, localContext),
|
|
34
|
+
typeVerified = type.verify(localContext);
|
|
35
|
+
|
|
36
|
+
if (typeVerified) {
|
|
37
|
+
const termNode = termNodeA, ///
|
|
38
|
+
term = Term.fromTermNode(termNode, localContext),
|
|
39
|
+
termVerifiedGivenType = term.verifyGivenType(type, localContext);
|
|
40
|
+
|
|
41
|
+
if (termVerifiedGivenType) {
|
|
42
|
+
unified = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
32
45
|
|
|
33
|
-
return
|
|
46
|
+
return unified;
|
|
34
47
|
}
|
|
35
48
|
}
|
|
36
49
|
];
|
|
@@ -5,7 +5,7 @@ import verifyFrameGivenMetaType from "../verify/frameGivenMetaType";
|
|
|
5
5
|
export default function unifyFrameWithMetaType(frameNode, metaTypeNode, assignments, stated, localContext) {
|
|
6
6
|
let frameUnifiedWithMetaType;
|
|
7
7
|
|
|
8
|
-
const metaType = localContext.
|
|
8
|
+
const metaType = localContext.findMetaTypeByMetaTypeName(metaTypeNode),
|
|
9
9
|
frameVerifiedGivenMetaType = verifyFrameGivenMetaType(frameNode, metaType, assignments, stated, localContext);
|
|
10
10
|
|
|
11
11
|
frameUnifiedWithMetaType = frameVerifiedGivenMetaType; ///
|
package/src/utilities/name.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { nodeQuery } from "../utilities/query";
|
|
4
4
|
|
|
5
5
|
const typeTerminalNodeQuery = nodeQuery("/type/@type"),
|
|
6
|
-
nameTerminalNodeQuery = nodeQuery("/metavariable/@name"),
|
|
6
|
+
nameTerminalNodeQuery = nodeQuery("/variable|metavariable/@name"),
|
|
7
7
|
metaTypeTerminalNodeQuery = nodeQuery("/metaType/@meta-type");
|
|
8
8
|
|
|
9
9
|
export function typeNameFromTypeNode(typeNode) {
|
|
@@ -14,6 +14,14 @@ export function typeNameFromTypeNode(typeNode) {
|
|
|
14
14
|
return typeName;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export function variableNameFromVariableNode(variableNode) {
|
|
18
|
+
const nameTerminalNode = nameTerminalNodeQuery(variableNode),
|
|
19
|
+
nameTerminalNodeContent = nameTerminalNode.getContent(),
|
|
20
|
+
variableName = nameTerminalNodeContent; ///
|
|
21
|
+
|
|
22
|
+
return variableName;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
export function metaTypeNameFromMetaTypeNode(metaTypeNode) {
|
|
18
26
|
const metaTypeTerminalNode = metaTypeTerminalNodeQuery(metaTypeNode),
|
|
19
27
|
metaTypeTerminalNodeContent = metaTypeTerminalNode.getContent(),
|
package/src/utilities/node.js
CHANGED
|
@@ -4,11 +4,12 @@ import { parsersUtilities } from "occam-custom-grammars";
|
|
|
4
4
|
|
|
5
5
|
import { nodeQuery } from "../utilities/query";
|
|
6
6
|
import { combinedCustomGrammarFromNothing } from "./customGrammar";
|
|
7
|
-
import {
|
|
7
|
+
import { VARIABLE_RULE_NAME,
|
|
8
8
|
METAVARIABLE_RULE_NAME,
|
|
9
9
|
UNQUALIFIED_STATEMENT_RULE_NAME,
|
|
10
10
|
CONSTRUCTOR_DECLARATION_RULE_NAME } from "../ruleNames";
|
|
11
|
-
import {
|
|
11
|
+
import { variableTokensFromVariableString,
|
|
12
|
+
metavariableTokensFromMetavariableString,
|
|
12
13
|
unqualifiedStatementTokensFromUnqualifiedStatementString,
|
|
13
14
|
constructorDeclarationTokensFromConstructorDeclarationString } from "../utilities/tokens";
|
|
14
15
|
|
|
@@ -30,6 +31,13 @@ export function termNodeFromTermString(termString, lexer, parser) {
|
|
|
30
31
|
return termNode;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
export function variableNodeFromVariableString(variableString, lexer, parser) {
|
|
35
|
+
const variableTokens = variableTokensFromVariableString(variableString, lexer),
|
|
36
|
+
variableNode = variableNodeFromVariableTokens(variableTokens, parser);
|
|
37
|
+
|
|
38
|
+
return variableNode;
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
export function statementNodeFromStatementString(statementString, lexer, parser) {
|
|
34
42
|
const unqualifiedStatementString = `${statementString}
|
|
35
43
|
`,
|
|
@@ -47,19 +55,11 @@ export function metavariableNodeFromMetavariableString(metavariableString, lexer
|
|
|
47
55
|
return metavariableNode;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
export function
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return unqualifiedStatementNode;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function termNodeFromTermTokens(termTokens, parser) {
|
|
58
|
-
const tokens = termTokens, ///
|
|
59
|
-
ruleName = TERM_RULE_NAME,
|
|
60
|
-
termNode = nodeFromTokensRuleNameAndParser(tokens, ruleName, parser);
|
|
58
|
+
export function variableNodeFromVariableTokens(variableTokens, parser) {
|
|
59
|
+
const ruleName = VARIABLE_RULE_NAME,
|
|
60
|
+
variableNode = nodeFromTokensRuleNameAndParser(variableTokens, ruleName, parser);
|
|
61
61
|
|
|
62
|
-
return
|
|
62
|
+
return variableNode;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export function metavariableNodeFromMetavariableTokens(metavariableTokens, parser) {
|
package/src/utilities/tokens.js
CHANGED
|
@@ -9,11 +9,11 @@ const { nominalLexerFromCombinedCustomGrammar } = lexersUtilities;
|
|
|
9
9
|
const combinedCustomGrammar = combinedCustomGrammarFromNothing(),
|
|
10
10
|
nominalLexer = nominalLexerFromCombinedCustomGrammar(combinedCustomGrammar);
|
|
11
11
|
|
|
12
|
-
export function
|
|
13
|
-
const
|
|
14
|
-
|
|
12
|
+
export function variableTokensFromVariableString(variableString, lexer) {
|
|
13
|
+
const variableContent = `${variableString}`,
|
|
14
|
+
variableTokens = tokensFromContentAndLexer(variableContent, lexer);
|
|
15
15
|
|
|
16
|
-
return
|
|
16
|
+
return variableTokens;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function metavariableTokensFromMetavariableString(metavariableString, lexer) {
|