occam-verify-cli 0.0.1010 → 0.0.1012
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/combinator.js +9 -2
- package/lib/constructor/bracketed.js +52 -8
- package/lib/constructor.js +64 -18
- package/lib/declaration/constructor.js +90 -0
- package/lib/declaration/metavariable.js +15 -8
- package/lib/declaration/type.js +90 -0
- package/lib/error.js +70 -0
- package/lib/rule.js +8 -7
- package/lib/ruleNames.js +5 -1
- package/lib/statement.js +5 -5
- package/lib/term.js +97 -5
- package/lib/type.js +85 -18
- package/lib/utilities/node.js +10 -3
- package/lib/utilities/releaseContext.js +5 -10
- package/lib/utilities/tokens.js +8 -1
- package/lib/verifier/termAsConstructor.js +3 -4
- package/lib/verifier/topLevel.js +10 -10
- package/package.json +1 -1
- package/src/combinator.js +13 -3
- package/src/constructor/bracketed.js +15 -12
- package/src/constructor.js +73 -17
- package/src/declaration/constructor.js +49 -0
- package/src/declaration/metavariable.js +12 -7
- package/src/declaration/type.js +49 -0
- package/src/error.js +35 -0
- package/src/rule.js +6 -6
- package/src/ruleNames.js +1 -0
- package/src/statement.js +4 -4
- package/src/term.js +119 -4
- package/src/type.js +113 -17
- package/src/utilities/node.js +20 -7
- package/src/utilities/releaseContext.js +5 -14
- package/src/utilities/tokens.js +7 -0
- package/src/verifier/termAsConstructor.js +7 -6
- package/src/verifier/topLevel.js +12 -9
- package/lib/tokens/combinatorFrame/bracketed.js +0 -17
- package/lib/verify/declaration/combinator.js +0 -19
- package/lib/verify/declaration/constructor.js +0 -32
- package/lib/verify/declaration/type.js +0 -65
- package/lib/verify/error.js +0 -18
- package/src/tokens/combinatorFrame/bracketed.js +0 -10
- package/src/verify/declaration/combinator.js +0 -6
- package/src/verify/declaration/constructor.js +0 -36
- package/src/verify/declaration/type.js +0 -85
- package/src/verify/error.js +0 -11
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Constructor from "../constructor";
|
|
4
|
+
|
|
5
|
+
export default class ConstructorDeclaration {
|
|
6
|
+
constructor(fileContext, constructor) {
|
|
7
|
+
this.fileContext = fileContext;
|
|
8
|
+
this.constructor = constructor;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getFileContext() {
|
|
12
|
+
return this.fileContext;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getConstructor() {
|
|
16
|
+
return this.constructor;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getString() { return this.constructor.getString(); }
|
|
20
|
+
|
|
21
|
+
verify() {
|
|
22
|
+
let verified;
|
|
23
|
+
|
|
24
|
+
const constructorDeclarationString = this.getString(); ///
|
|
25
|
+
|
|
26
|
+
this.fileContext.trace(`Verifying the '${constructorDeclarationString}' constructor declaration...`);
|
|
27
|
+
|
|
28
|
+
const constructorVerified = this.constructor.verify(this.fileContext);
|
|
29
|
+
|
|
30
|
+
if (constructorVerified) {
|
|
31
|
+
this.fileContext.addConstructor(this.constructor);
|
|
32
|
+
|
|
33
|
+
verified = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (verified) {
|
|
37
|
+
this.fileContext.debug(`...verified the '${constructorDeclarationString}' constructor declaration.`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return verified;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static fromConstructorDeclarationNode(constructorDeclarationNode, fileContext) {
|
|
44
|
+
const constructor = Constructor.fromConstructorDeclarationNode(constructorDeclarationNode, fileContext),
|
|
45
|
+
constructorDeclaration = new ConstructorDeclaration(fileContext, constructor);
|
|
46
|
+
|
|
47
|
+
return constructorDeclaration;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -8,11 +8,16 @@ import { nodeQuery } from "../utilities/query";
|
|
|
8
8
|
const metaTypeNodeQuery = nodeQuery("/metavariableDeclaration/metaType");
|
|
9
9
|
|
|
10
10
|
export default class MetavariableDeclaration {
|
|
11
|
-
constructor(string, metavariable) {
|
|
11
|
+
constructor(fileContext, string, metavariable) {
|
|
12
|
+
this.fileContext = fileContext;
|
|
12
13
|
this.string = string;
|
|
13
14
|
this.metavariable = metavariable;
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
getFileContext() {
|
|
18
|
+
return this.fileContext;
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
getString() {
|
|
17
22
|
return this.string;
|
|
18
23
|
}
|
|
@@ -21,23 +26,23 @@ export default class MetavariableDeclaration {
|
|
|
21
26
|
return this.metavariable;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
verify(
|
|
29
|
+
verify() {
|
|
25
30
|
let verified;
|
|
26
31
|
|
|
27
32
|
const metavariableDeclarationString = this.string; ///
|
|
28
33
|
|
|
29
|
-
fileContext.trace(`Verifying the '${metavariableDeclarationString}' metavariable declaration...`);
|
|
34
|
+
this.fileContext.trace(`Verifying the '${metavariableDeclarationString}' metavariable declaration...`);
|
|
30
35
|
|
|
31
|
-
const metavariableVerified = this.metavariable.verify(fileContext);
|
|
36
|
+
const metavariableVerified = this.metavariable.verify(this.fileContext);
|
|
32
37
|
|
|
33
38
|
if (metavariableVerified) {
|
|
34
|
-
fileContext.addMetavariable(this.metavariable);
|
|
39
|
+
this.fileContext.addMetavariable(this.metavariable);
|
|
35
40
|
|
|
36
41
|
verified = true;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
if (verified) {
|
|
40
|
-
fileContext.debug(`...verified the '${metavariableDeclarationString}' metavariable declaration.`);
|
|
45
|
+
this.fileContext.debug(`...verified the '${metavariableDeclarationString}' metavariable declaration.`);
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
return verified;
|
|
@@ -50,7 +55,7 @@ export default class MetavariableDeclaration {
|
|
|
50
55
|
metavariableString = metavariable.getString(),
|
|
51
56
|
metaTypeString = metaType.getString(),
|
|
52
57
|
string = `${metavariableString}:${metaTypeString}`,
|
|
53
|
-
metavariableDeclaration = new MetavariableDeclaration(string, metavariable);
|
|
58
|
+
metavariableDeclaration = new MetavariableDeclaration(fileContext, string, metavariable);
|
|
54
59
|
|
|
55
60
|
return metavariableDeclaration;
|
|
56
61
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Type from "../type";
|
|
4
|
+
|
|
5
|
+
export default class TypeDeclaration {
|
|
6
|
+
constructor(fileContext, type) {
|
|
7
|
+
this.fileContext = fileContext;
|
|
8
|
+
this.type = type;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getFileContext() {
|
|
12
|
+
return this.fileContext;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getType() {
|
|
16
|
+
return this.type;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getString() { return this.type.getString(); }
|
|
20
|
+
|
|
21
|
+
verify() {
|
|
22
|
+
let verified = false;
|
|
23
|
+
|
|
24
|
+
const typeDeclarationString = this.getString(); ///
|
|
25
|
+
|
|
26
|
+
this.fileContext.trace(`Verifying the '${typeDeclarationString}' type declaration...`);
|
|
27
|
+
|
|
28
|
+
const typeVerified = this.type.verify(this.fileContext);
|
|
29
|
+
|
|
30
|
+
if (typeVerified) {
|
|
31
|
+
this.fileContext.addType(this.type);
|
|
32
|
+
|
|
33
|
+
verified = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (verified) {
|
|
37
|
+
this.fileContext.debug(`...verified the '${typeDeclarationString}' type declaration.`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return verified;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static fromTypeDeclarationNode(typeDeclarationNode, fileContext) {
|
|
44
|
+
const type = Type.fromTypeDeclarationNode(typeDeclarationNode, fileContext),
|
|
45
|
+
typeDeclaration = new TypeDeclaration(fileContext, type);
|
|
46
|
+
|
|
47
|
+
return typeDeclaration;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/error.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export default class Error {
|
|
4
|
+
constructor(fileContext, string) {
|
|
5
|
+
this.fileContext = fileContext;
|
|
6
|
+
this.string = string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getFileContext() {
|
|
10
|
+
return this.fileContext;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getString() {
|
|
14
|
+
return this.string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
verify(errorNode) {
|
|
18
|
+
let verified = false;
|
|
19
|
+
|
|
20
|
+
const errorString = this.string; ///
|
|
21
|
+
|
|
22
|
+
this.fileContext.debug(`The '${errorString}' error cannot be verified.`, errorNode);
|
|
23
|
+
|
|
24
|
+
return verified;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static fromErrorNode(errorNode, fileContext) {
|
|
28
|
+
const node = errorNode, ///
|
|
29
|
+
string = fileContext.nodeAsString(node),
|
|
30
|
+
error = new Error(fileContext, string);
|
|
31
|
+
|
|
32
|
+
return error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
package/src/rule.js
CHANGED
|
@@ -90,15 +90,15 @@ export default class Rule {
|
|
|
90
90
|
return proofStepsUnified;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
verify(
|
|
93
|
+
verify() {
|
|
94
94
|
let verified = false;
|
|
95
95
|
|
|
96
96
|
const labelsString = labelsStringFromLabels(this.labels);
|
|
97
97
|
|
|
98
|
-
fileContext.trace(`Verifying the '${labelsString}' rule...`);
|
|
98
|
+
this.fileContext.trace(`Verifying the '${labelsString}' rule...`);
|
|
99
99
|
|
|
100
100
|
const labelsVerified = this.labels.every((label) => {
|
|
101
|
-
const labelVVerified = label.verify(fileContext);
|
|
101
|
+
const labelVVerified = label.verify(this.fileContext);
|
|
102
102
|
|
|
103
103
|
if (labelVVerified) {
|
|
104
104
|
return true;
|
|
@@ -106,7 +106,7 @@ export default class Rule {
|
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
if (labelsVerified) {
|
|
109
|
-
const localContext = LocalContext.fromFileContext(fileContext),
|
|
109
|
+
const localContext = LocalContext.fromFileContext(this.fileContext),
|
|
110
110
|
premisesVerified = this.premises.every((premise) => {
|
|
111
111
|
const premiseVerified = premise.verify(localContext);
|
|
112
112
|
|
|
@@ -130,7 +130,7 @@ export default class Rule {
|
|
|
130
130
|
if (proofVerified) {
|
|
131
131
|
const rule = this; ///
|
|
132
132
|
|
|
133
|
-
fileContext.addRule(rule);
|
|
133
|
+
this.fileContext.addRule(rule);
|
|
134
134
|
|
|
135
135
|
verified = true;
|
|
136
136
|
}
|
|
@@ -139,7 +139,7 @@ export default class Rule {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
if (verified) {
|
|
142
|
-
fileContext.debug(`...verified the '${labelsString}' rule.`);
|
|
142
|
+
this.fileContext.debug(`...verified the '${labelsString}' rule.`);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
return verified;
|
package/src/ruleNames.js
CHANGED
package/src/statement.js
CHANGED
|
@@ -75,18 +75,18 @@ class Statement {
|
|
|
75
75
|
return unifiedWithMetaType;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
verifyAsCombinator(
|
|
78
|
+
verifyAsCombinator(fileContext) {
|
|
79
79
|
let verifiedAsCombinator;
|
|
80
80
|
|
|
81
81
|
const statementNode = this.node, ///
|
|
82
82
|
statementString = this.string; ///
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
fileContext.trace(`Verifying the '${statementString}' statement as a combinator...`);
|
|
85
85
|
|
|
86
|
-
verifiedAsCombinator = statementAsCombinatorVerifier.verifyStatement(statementNode,
|
|
86
|
+
verifiedAsCombinator = statementAsCombinatorVerifier.verifyStatement(statementNode, fileContext);
|
|
87
87
|
|
|
88
88
|
if (verifiedAsCombinator) {
|
|
89
|
-
|
|
89
|
+
fileContext.debug(`...verified the '${statementString}' statement as a combinator.`, statementNode);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
return verifiedAsCombinator;
|
package/src/term.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import shim from "./shim";
|
|
4
|
+
import termAsConstructorVerifier from "./verifier/termAsConstructor";
|
|
5
|
+
|
|
3
6
|
import { filter } from "./utilities/array";
|
|
4
7
|
import { nodesQuery } from "./utilities/query"
|
|
8
|
+
import { termNodeFromTermString } from "./utilities/node";
|
|
5
9
|
|
|
6
10
|
const variableNodesQuery = nodesQuery("//variable");
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
constructor(node, type) {
|
|
12
|
+
class Term {
|
|
13
|
+
constructor(string, node, type) {
|
|
14
|
+
this.string = string;
|
|
10
15
|
this.node = node;
|
|
11
16
|
this.type = type;
|
|
12
17
|
}
|
|
13
18
|
|
|
19
|
+
getString() {
|
|
20
|
+
return this.string;
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
getNode() {
|
|
15
24
|
return this.node;
|
|
16
25
|
}
|
|
@@ -81,10 +90,116 @@ export default class Term {
|
|
|
81
90
|
return implicitlyGrounded;
|
|
82
91
|
}
|
|
83
92
|
|
|
84
|
-
|
|
93
|
+
verify(localContext, verifyAhead) {
|
|
94
|
+
let verified = false;
|
|
95
|
+
|
|
96
|
+
debugger
|
|
97
|
+
|
|
98
|
+
return verified;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
verifyType(fileContext) {
|
|
102
|
+
let typeVerified;
|
|
103
|
+
|
|
104
|
+
if (this.type === null) {
|
|
105
|
+
typeVerified = true;
|
|
106
|
+
} else {
|
|
107
|
+
const typeName = this.type.getName();
|
|
108
|
+
|
|
109
|
+
fileContext.trace(`Verifying the '${typeName}' type...`);
|
|
110
|
+
|
|
111
|
+
const type = fileContext.findTypeByTypeName(typeName);
|
|
112
|
+
|
|
113
|
+
if (type === null) {
|
|
114
|
+
fileContext.debug(`The '${typeName}' type is missing.`);
|
|
115
|
+
} else {
|
|
116
|
+
this.type = type; ///
|
|
117
|
+
|
|
118
|
+
typeVerified = true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (typeVerified) {
|
|
122
|
+
fileContext.debug(`...verified the '${typeName}' type.`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return typeVerified;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
verifyAsConstructor(fileContext) {
|
|
130
|
+
let verifiedAsConstructor;
|
|
131
|
+
|
|
132
|
+
const termNode = this.node, ///
|
|
133
|
+
termString = this.string; ///
|
|
134
|
+
|
|
135
|
+
fileContext.trace(`Verifying the '${termString}' term as a constructor...`);
|
|
136
|
+
|
|
137
|
+
verifiedAsConstructor = termAsConstructorVerifier.verifyTerm(termNode, fileContext);
|
|
138
|
+
|
|
139
|
+
if (verifiedAsConstructor) {
|
|
140
|
+
fileContext.debug(`...verified the '${termString}' term as a constructor.`, termNode);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return verifiedAsConstructor;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
toJSON() {
|
|
147
|
+
const typeJSON = (this.type !== null) ?
|
|
148
|
+
this.type.toJSON() :
|
|
149
|
+
null,
|
|
150
|
+
string = this.string,
|
|
151
|
+
type = typeJSON, ///
|
|
152
|
+
json = {
|
|
153
|
+
string,
|
|
154
|
+
type
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return json;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static fromJSON(json, fileContext) {
|
|
161
|
+
const { string } = json,
|
|
162
|
+
termString = string, ///
|
|
163
|
+
lexer = fileContext.getLexer(),
|
|
164
|
+
parser = fileContext.getParser(),
|
|
165
|
+
termNode = termNodeFromTermString(termString, lexer, parser),
|
|
166
|
+
node = termNode;
|
|
167
|
+
|
|
168
|
+
let { type } = json;
|
|
169
|
+
|
|
170
|
+
const typeJSON = type; ///
|
|
171
|
+
|
|
172
|
+
json = typeJSON; ///
|
|
173
|
+
|
|
174
|
+
type = (json !== null) ?
|
|
175
|
+
Type.fromJSON(json, fileContext) :
|
|
176
|
+
null;
|
|
177
|
+
|
|
178
|
+
const term = new Term(string, node, type);
|
|
179
|
+
|
|
180
|
+
return term;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static fromTermNode(termNode, fileContext) {
|
|
184
|
+
const node = termNode, ///
|
|
185
|
+
string = fileContext.nodeAsString(node),
|
|
186
|
+
type = null,
|
|
187
|
+
term = new Term(string, node, type);
|
|
188
|
+
|
|
189
|
+
return term;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static fromTermNodeAndType(termNode, type, fileContext) {
|
|
85
193
|
const node = termNode, ///
|
|
86
|
-
|
|
194
|
+
string = fileContext.nodeAsString(node),
|
|
195
|
+
term = new Term(string, node, type);
|
|
87
196
|
|
|
88
197
|
return term;
|
|
89
198
|
}
|
|
90
199
|
}
|
|
200
|
+
|
|
201
|
+
Object.assign(shim, {
|
|
202
|
+
Term
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
export default Term;
|
package/src/type.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import shim from "./shim";
|
|
4
4
|
|
|
5
|
+
import { nodeQuery } from "./utilities/query";
|
|
6
|
+
import { OBJECT_TYPE_NAME } from "./typeNames";
|
|
5
7
|
import { typeNameFromTypeNode } from "./utilities/name";
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const typeNodeQuery = nodeQuery("/typeDeclaration/type[0]"),
|
|
10
|
+
superTypeNodeQuery = nodeQuery("/typeDeclaration/type[1]");
|
|
11
|
+
|
|
12
|
+
class Type {
|
|
13
|
+
constructor(string, name, superType) {
|
|
14
|
+
this.string = string;
|
|
9
15
|
this.name = name;
|
|
10
16
|
this.superType = superType;
|
|
11
17
|
}
|
|
12
18
|
|
|
19
|
+
getString() {
|
|
20
|
+
return this.string;
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
getName() {
|
|
14
24
|
return this.name;
|
|
15
25
|
}
|
|
@@ -111,36 +121,122 @@ export default class Type {
|
|
|
111
121
|
return typeNodeMatches;
|
|
112
122
|
}
|
|
113
123
|
|
|
114
|
-
|
|
115
|
-
let
|
|
124
|
+
verify(fileContext) {
|
|
125
|
+
let verified = false;
|
|
116
126
|
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
const typeString = this.string; ///
|
|
128
|
+
|
|
129
|
+
fileContext.trace(`Verifying the '${typeString}' type...`);
|
|
130
|
+
|
|
131
|
+
const typePresent = fileContext.isTypePresentByTypeName(this.name);
|
|
132
|
+
|
|
133
|
+
if (typePresent) {
|
|
134
|
+
fileContext.debug(`The type '${typeString}' is already present.`);
|
|
119
135
|
} else {
|
|
120
|
-
|
|
136
|
+
if (this.superType === null) {
|
|
137
|
+
verified = true;
|
|
138
|
+
} else {
|
|
139
|
+
const name = this.superType.getName(),
|
|
140
|
+
superTypePresent = fileContext.isTypePresentByTypeName(name);
|
|
141
|
+
|
|
142
|
+
if (superTypePresent) {
|
|
143
|
+
verified = true;
|
|
144
|
+
} else {
|
|
145
|
+
const superTypeString = this.superType.getString();
|
|
146
|
+
|
|
147
|
+
fileContext.debug(`The super-type '${superTypeString}' is not present.`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
121
151
|
|
|
122
|
-
|
|
152
|
+
if (verified) {
|
|
153
|
+
fileContext.debug(`...verified the '${typeString}' type.`);
|
|
123
154
|
}
|
|
124
155
|
|
|
125
|
-
return
|
|
156
|
+
return verified;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
toJSON() {
|
|
160
|
+
const superTypeJSON = (this.superType !== null) ?
|
|
161
|
+
this.superType.toJSON() :
|
|
162
|
+
null,
|
|
163
|
+
name = this.name,
|
|
164
|
+
superType = superTypeJSON, ///
|
|
165
|
+
json = {
|
|
166
|
+
name,
|
|
167
|
+
superType
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return json;
|
|
126
171
|
}
|
|
127
172
|
|
|
128
|
-
static
|
|
129
|
-
const name =
|
|
130
|
-
|
|
131
|
-
|
|
173
|
+
static fromJSON(json, fileContext) {
|
|
174
|
+
const { name } = json;
|
|
175
|
+
|
|
176
|
+
let { superType } = json;
|
|
177
|
+
|
|
178
|
+
const superTypeJSON = superType; ///
|
|
179
|
+
|
|
180
|
+
json = superTypeJSON; ///
|
|
181
|
+
|
|
182
|
+
superType = (json !== null) ?
|
|
183
|
+
Type.fromJSON(json, fileContext) :
|
|
184
|
+
null;
|
|
185
|
+
|
|
186
|
+
const typeName = name, ///
|
|
187
|
+
string = stringFromTypeNameAndSuperType(typeName, superType),
|
|
188
|
+
type = new Type(string, name, superType);
|
|
189
|
+
|
|
190
|
+
return type;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
static fromTypeNode(typeNode) {
|
|
194
|
+
let type = null;
|
|
195
|
+
|
|
196
|
+
if (typeNode !== null) {
|
|
197
|
+
const typeName = typeNameFromTypeNode(typeNode),
|
|
198
|
+
name = typeName, ///
|
|
199
|
+
string = name, ///
|
|
200
|
+
superType = null;
|
|
201
|
+
|
|
202
|
+
type = new Type(string, name, superType);
|
|
203
|
+
}
|
|
132
204
|
|
|
133
205
|
return type;
|
|
134
206
|
}
|
|
135
207
|
|
|
136
|
-
static
|
|
137
|
-
const
|
|
138
|
-
|
|
208
|
+
static fromTypeDeclarationNode(typeDeclarationNode, fileContext) {
|
|
209
|
+
const typeNode = typeNodeQuery(typeDeclarationNode),
|
|
210
|
+
superTypeNode = superTypeNodeQuery(typeDeclarationNode),
|
|
211
|
+
typeName = typeNameFromTypeNode(typeNode),
|
|
212
|
+
superType = Type.fromTypeNode(superTypeNode),
|
|
213
|
+
string = stringFromTypeNameAndSuperType(typeName, superType),
|
|
214
|
+
name = typeName, ///
|
|
215
|
+
type = new Type(string, name, superType);
|
|
139
216
|
|
|
140
217
|
return type;
|
|
141
218
|
}
|
|
142
219
|
}
|
|
143
220
|
|
|
221
|
+
function stringFromTypeNameAndSuperType(typeName, superType) {
|
|
222
|
+
let string = typeName; ///
|
|
223
|
+
|
|
224
|
+
if (superType !== null) {
|
|
225
|
+
const typeString = string, ///
|
|
226
|
+
superTypeString = superType.getString();
|
|
227
|
+
|
|
228
|
+
string = `${typeString}:${superTypeString}`;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return string;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
Object.assign(shim, {
|
|
235
|
+
Type
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
export default Type;
|
|
239
|
+
|
|
144
240
|
class ObjectType extends Type {
|
|
145
241
|
static fromNothing() {
|
|
146
242
|
const name = OBJECT_TYPE_NAME,
|
package/src/utilities/node.js
CHANGED
|
@@ -6,21 +6,26 @@ import { nodeQuery } from "../utilities/query";
|
|
|
6
6
|
import { combinedCustomGrammarFromNothing } from "./customGrammar";
|
|
7
7
|
import { TERM_RULE_NAME,
|
|
8
8
|
METAVARIABLE_RULE_NAME,
|
|
9
|
-
UNQUALIFIED_STATEMENT_RULE_NAME
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
unqualifiedStatementTokensFromUnqualifiedStatementString
|
|
9
|
+
UNQUALIFIED_STATEMENT_RULE_NAME,
|
|
10
|
+
CONSTRUCTOR_DECLARATION_RULE_NAME } from "../ruleNames";
|
|
11
|
+
import { metavariableTokensFromMetavariableString,
|
|
12
|
+
unqualifiedStatementTokensFromUnqualifiedStatementString,
|
|
13
|
+
constructorDeclarationTokensFromConstructorDeclarationString } from "../utilities/tokens";
|
|
13
14
|
|
|
14
15
|
const { nominalParserFromCombinedCustomGrammar } = parsersUtilities;
|
|
15
16
|
|
|
16
17
|
const combinedCustomGrammar = combinedCustomGrammarFromNothing(),
|
|
17
18
|
nominalParser = nominalParserFromCombinedCustomGrammar(combinedCustomGrammar);
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
+
const termNodeQuery = nodeQuery("/constructorDeclaration/term"),
|
|
21
|
+
statementNodeQuery = nodeQuery("/unqualifiedStatement/statement");
|
|
20
22
|
|
|
21
23
|
export function termNodeFromTermString(termString, lexer, parser) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
+
const constructorDeclarationString = `Constructor ${termString}
|
|
25
|
+
`,
|
|
26
|
+
constructorDeclarationTokens = constructorDeclarationTokensFromConstructorDeclarationString(constructorDeclarationString, lexer),
|
|
27
|
+
constructorDeclarationNode = constructorDeclarationNodeFromConstructorDeclarationTokens(constructorDeclarationTokens, parser),
|
|
28
|
+
termNode = termNodeQuery(constructorDeclarationNode, constructorDeclarationNode);
|
|
24
29
|
|
|
25
30
|
return termNode;
|
|
26
31
|
}
|
|
@@ -72,6 +77,14 @@ export function unqualifiedStatementNodeFromUnqualifiedStatementTokens(unqualifi
|
|
|
72
77
|
return unqualifiedStatementNode;
|
|
73
78
|
}
|
|
74
79
|
|
|
80
|
+
export function constructorDeclarationNodeFromConstructorDeclarationTokens(constructorDeclarationTokens, parser) {
|
|
81
|
+
const tokens = constructorDeclarationTokens, ///
|
|
82
|
+
ruleName = CONSTRUCTOR_DECLARATION_RULE_NAME,
|
|
83
|
+
constructorDeclarationNode = nodeFromTokensRuleNameAndParser(tokens, ruleName, parser);
|
|
84
|
+
|
|
85
|
+
return constructorDeclarationNode;
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
function nodeFromTokensRuleNameAndParser(tokens, ruleName, parser = nominalParser) {
|
|
76
89
|
const ruleMap = parser.getRuleMap(),
|
|
77
90
|
rule = ruleMap[ruleName],
|
|
@@ -86,8 +86,6 @@ export function createReleaseContext(dependency, dependentNames, context, callba
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
export function initialiseReleaseContext(dependency, context) {
|
|
89
|
-
let releaseContextInitialised = false;
|
|
90
|
-
|
|
91
89
|
const { releaseContextMap } = context,
|
|
92
90
|
dependencyName = dependency.getName(),
|
|
93
91
|
releaseName = dependencyName, ///
|
|
@@ -98,7 +96,7 @@ export function initialiseReleaseContext(dependency, context) {
|
|
|
98
96
|
|
|
99
97
|
log.warning(`Unable to initialise the '${dependencyName}' context because it has not been created.`);
|
|
100
98
|
} else {
|
|
101
|
-
releaseContextInitialised = releaseContext.isInitialised();
|
|
99
|
+
const releaseContextInitialised = releaseContext.isInitialised();
|
|
102
100
|
|
|
103
101
|
if (!releaseContextInitialised) {
|
|
104
102
|
initialiseDependencyReleaseContexts(dependency, releaseContext, context);
|
|
@@ -113,8 +111,6 @@ export function initialiseReleaseContext(dependency, context) {
|
|
|
113
111
|
log.info(`...initialised the '${dependencyName}' context.`);
|
|
114
112
|
}
|
|
115
113
|
}
|
|
116
|
-
|
|
117
|
-
return releaseContextInitialised;
|
|
118
114
|
}
|
|
119
115
|
|
|
120
116
|
export default {
|
|
@@ -277,14 +273,9 @@ function createDependencyReleaseContexts(dependency, releaseContext, dependentNa
|
|
|
277
273
|
}
|
|
278
274
|
|
|
279
275
|
function initialiseDependencyReleaseContexts(dependency, releaseContext, context) {
|
|
280
|
-
const dependencies = releaseContext.getDependencies()
|
|
281
|
-
dependencyReleaseContextsInitialised = dependencies.everyDependency((dependency) => { ///
|
|
282
|
-
const releaseContextInitialised = initialiseReleaseContext(dependency, context);
|
|
283
|
-
|
|
284
|
-
if (releaseContextInitialised) {
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
});
|
|
276
|
+
const dependencies = releaseContext.getDependencies();
|
|
288
277
|
|
|
289
|
-
|
|
278
|
+
dependencies.forEachDependency((dependency) => { ///
|
|
279
|
+
initialiseReleaseContext(dependency, context);
|
|
280
|
+
});
|
|
290
281
|
}
|
package/src/utilities/tokens.js
CHANGED
|
@@ -30,6 +30,13 @@ export function unqualifiedStatementTokensFromUnqualifiedStatementString(unquali
|
|
|
30
30
|
return unqualifiedStatementTokens;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export function constructorDeclarationTokensFromConstructorDeclarationString(constructorDeclarationString, lexer) {
|
|
34
|
+
const content = constructorDeclarationString, ///
|
|
35
|
+
constructorDeclarationTokens = tokensFromContentAndLexer(content, lexer);
|
|
36
|
+
|
|
37
|
+
return constructorDeclarationTokens;
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
function tokensFromContentAndLexer(content, lexer = nominalLexer) {
|
|
34
41
|
const tokens = lexer.tokenise(content);
|
|
35
42
|
|