occam-verify-cli 0.0.262
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/README.md +7 -0
- package/bin/abbreviations.js +11 -0
- package/bin/antecedent.js +19 -0
- package/bin/axiom.js +52 -0
- package/bin/combinator.js +27 -0
- package/bin/conclusion.js +19 -0
- package/bin/consequent.js +19 -0
- package/bin/constants.js +9 -0
- package/bin/constructor.js +43 -0
- package/bin/context/file.js +257 -0
- package/bin/context/metaproof.js +90 -0
- package/bin/context/package/fileSystem.js +111 -0
- package/bin/context/package.js +221 -0
- package/bin/context/proof.js +93 -0
- package/bin/fileNames.js +17 -0
- package/bin/loadPackageContexts.js +53 -0
- package/bin/main.js +25 -0
- package/bin/metaAntecedent.js +19 -0
- package/bin/metaConsequent.js +19 -0
- package/bin/metaSubstitution.js +24 -0
- package/bin/options.js +9 -0
- package/bin/premise.js +19 -0
- package/bin/rule.js +64 -0
- package/bin/ruleNames.js +19 -0
- package/bin/type.js +120 -0
- package/bin/utilities/array.js +97 -0
- package/bin/utilities/fileSystem.js +97 -0
- package/bin/utilities/query.js +92 -0
- package/bin/utilities/rule.js +279 -0
- package/bin/utilities/string.js +51 -0
- package/bin/variable.js +54 -0
- package/bin/verify/antecedent.js +35 -0
- package/bin/verify/axiom/IndicativeConditional.js +54 -0
- package/bin/verify/axiom/unqualifiedStatement.js +40 -0
- package/bin/verify/axiom.js +37 -0
- package/bin/verify/conclusion.js +32 -0
- package/bin/verify/consequent.js +32 -0
- package/bin/verify/declaration/combinator.js +17 -0
- package/bin/verify/declaration/constructor.js +19 -0
- package/bin/verify/declaration/topLevel.js +61 -0
- package/bin/verify/declaration/type.js +21 -0
- package/bin/verify/declaration/variable.js +19 -0
- package/bin/verify/equality.js +52 -0
- package/bin/verify/file.js +43 -0
- package/bin/verify/files.js +46 -0
- package/bin/verify/label.js +27 -0
- package/bin/verify/labels.js +17 -0
- package/bin/verify/metaAntecedent.js +35 -0
- package/bin/verify/metaConsequent.js +32 -0
- package/bin/verify/metaDerivation.js +105 -0
- package/bin/verify/metaproof.js +46 -0
- package/bin/verify/metastatement/qualified.js +43 -0
- package/bin/verify/metastatement/unqualified.js +40 -0
- package/bin/verify/package.js +81 -0
- package/bin/verify/premise.js +35 -0
- package/bin/verify/rule/inferenceConditional.js +54 -0
- package/bin/verify/rule/unqualifiedMetastatement.js +40 -0
- package/bin/verify/rule.js +61 -0
- package/bin/verify/statement/qualified.js +17 -0
- package/bin/verify/statement/unqualified.js +27 -0
- package/bin/verify/statement.js +47 -0
- package/bin/verify/statementAsCombinator.js +140 -0
- package/bin/verify/term.js +183 -0
- package/bin/verify/termAsConstructor.js +173 -0
- package/bin/verify/termAsVariable.js +41 -0
- package/bin/verify/type.js +53 -0
- package/bin/verify/typeAssertion.js +69 -0
- package/bin/verify/variable.js +55 -0
- package/index.js +9 -0
- package/license.txt +48 -0
- package/package.json +24 -0
- package/verify.js +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
class Antecedent {
|
|
4
|
+
constructor(statementNodes) {
|
|
5
|
+
this.statementNodes = statementNodes;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
getStatementNodes() {
|
|
9
|
+
return this.statementNodes;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static fromStatementNodes(statementNodes) {
|
|
13
|
+
const antecedent = new Antecedent(statementNodes);
|
|
14
|
+
|
|
15
|
+
return antecedent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = Antecedent;
|
package/bin/axiom.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { labelsAsString } = require("./utilities/string");
|
|
4
|
+
|
|
5
|
+
class Axiom {
|
|
6
|
+
constructor(labels, antecedent, consequent, statementNode) {
|
|
7
|
+
this.labels = labels;
|
|
8
|
+
this.antecedent = antecedent;
|
|
9
|
+
this.consequent = consequent;
|
|
10
|
+
this.statementNode = statementNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getLabels() {
|
|
14
|
+
return this.labels;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getAntecedent() {
|
|
18
|
+
return this.antecedent;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getConsequent() {
|
|
22
|
+
return this.consequent;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getStatementNode() {
|
|
26
|
+
return this.statementNode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
asString() {
|
|
30
|
+
const string = labelsAsString(this.labels);
|
|
31
|
+
|
|
32
|
+
return string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static fromStatementNodeAndLabels(statementNode, labels) {
|
|
36
|
+
const antecedent = null,
|
|
37
|
+
consequent = null,
|
|
38
|
+
axiom = new Axiom(labels, antecedent, consequent, statementNode);
|
|
39
|
+
|
|
40
|
+
return axiom;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static fromAntecedentConsequentAndLabels(antecedent, consequent, labels) {
|
|
44
|
+
const statementNode = null,
|
|
45
|
+
axiom = new Axiom(labels, antecedent, consequent, statementNode);
|
|
46
|
+
|
|
47
|
+
return axiom;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = Axiom;
|
|
52
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { nodeAsString } = require("./utilities/string");
|
|
4
|
+
|
|
5
|
+
class Combinator {
|
|
6
|
+
constructor(statementNode) {
|
|
7
|
+
this.statementNode = statementNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
asString() {
|
|
11
|
+
let string;
|
|
12
|
+
|
|
13
|
+
const statementString = nodeAsString(this.statementNode);
|
|
14
|
+
|
|
15
|
+
string = `${statementString}`;
|
|
16
|
+
|
|
17
|
+
return string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static fromStatementNode(statementNode) {
|
|
21
|
+
const combinator = new Combinator(statementNode);
|
|
22
|
+
|
|
23
|
+
return combinator;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = Combinator;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
class Conclusion {
|
|
4
|
+
constructor(metastatementNode) {
|
|
5
|
+
this.metastatementNode = metastatementNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
getMetastatementNode() {
|
|
9
|
+
return this.metastatementNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static fromMetastatementNode(metastatementNode) {
|
|
13
|
+
const conclusion = new Conclusion(metastatementNode);
|
|
14
|
+
|
|
15
|
+
return conclusion;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = Conclusion;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
class Consequent {
|
|
4
|
+
constructor(statementNode) {
|
|
5
|
+
this.statementNode = statementNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
getStatementNode() {
|
|
9
|
+
return this.statementNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static fromStatementNode(statementNode) {
|
|
13
|
+
const consequent = new Consequent(statementNode);
|
|
14
|
+
|
|
15
|
+
return consequent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = Consequent;
|
package/bin/constants.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { nodeAsString } = require("./utilities/string");
|
|
4
|
+
|
|
5
|
+
class Constructor {
|
|
6
|
+
constructor(termNode, type) {
|
|
7
|
+
this.termNode = termNode;
|
|
8
|
+
this.type = type;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getTermNode() {
|
|
12
|
+
return this.termNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getType() {
|
|
16
|
+
return this.type;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
asString() {
|
|
20
|
+
let string;
|
|
21
|
+
|
|
22
|
+
const termString = nodeAsString(this.termNode);
|
|
23
|
+
|
|
24
|
+
if (this.type === null) {
|
|
25
|
+
string = `${termString}`;
|
|
26
|
+
} else {
|
|
27
|
+
const noSuperType = true,
|
|
28
|
+
typeString = this.type.asString(noSuperType);
|
|
29
|
+
|
|
30
|
+
string = `${termString}:${typeString}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static fromTermNodeAndType(termNode, type) {
|
|
37
|
+
const constructor = new Constructor(termNode, type);
|
|
38
|
+
|
|
39
|
+
return constructor;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = Constructor;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { rewriteNodes } = require("occam-grammar-utilities");
|
|
4
|
+
|
|
5
|
+
const { push } = require("../utilities/array");
|
|
6
|
+
|
|
7
|
+
class FileContext {
|
|
8
|
+
constructor(tokens, node, rules, types, axioms, variables, combinators, constructors, packageContext) {
|
|
9
|
+
this.tokens = tokens;
|
|
10
|
+
this.node = node;
|
|
11
|
+
this.rules = rules;
|
|
12
|
+
this.types = types;
|
|
13
|
+
this.axioms = axioms;
|
|
14
|
+
this.variables = variables;
|
|
15
|
+
this.combinators = combinators;
|
|
16
|
+
this.constructors = constructors;
|
|
17
|
+
this.packageContext = packageContext;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getTokens() {
|
|
21
|
+
return this.tokens;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getNode() {
|
|
25
|
+
return this.node;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getRules(bubble = true) {
|
|
29
|
+
const rules = [
|
|
30
|
+
...this.rules
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
if (bubble) {
|
|
34
|
+
const packageContextRules = this.packageContext.getRules();
|
|
35
|
+
|
|
36
|
+
push(rules, packageContextRules);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return rules;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getTypes(bubble = true) {
|
|
43
|
+
const types = [
|
|
44
|
+
...this.types
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
if (bubble) {
|
|
48
|
+
const packageContextTypes = this.packageContext.getTypes();
|
|
49
|
+
|
|
50
|
+
push(types, packageContextTypes);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return types;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getAxioms(bubble = true) {
|
|
57
|
+
const axioms = [
|
|
58
|
+
...this.axioms
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
if (bubble) {
|
|
62
|
+
const packageContextAxioms = this.packageContext.getAxioms();
|
|
63
|
+
|
|
64
|
+
push(axioms, packageContextAxioms);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return axioms;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getLabels() {
|
|
71
|
+
const axioms = this.getAxioms(),
|
|
72
|
+
labels = axioms.reduce((labels, axiom) => {
|
|
73
|
+
const axiomLabels = axiom.getLabels();
|
|
74
|
+
|
|
75
|
+
push(labels, axiomLabels);
|
|
76
|
+
|
|
77
|
+
return labels;
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
return labels;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getVariables() {
|
|
84
|
+
return this.variables;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getCombinators(bubble = true) {
|
|
88
|
+
const combinators = [
|
|
89
|
+
...this.combinators
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
if (bubble) {
|
|
93
|
+
const packageContextCombinators = this.packageContext.getCombinators();
|
|
94
|
+
|
|
95
|
+
push(combinators, packageContextCombinators);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return combinators;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getConstructors(bubble = true) {
|
|
102
|
+
const constructors = [
|
|
103
|
+
...this.constructors
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
if (bubble) {
|
|
107
|
+
const packageContextConstructors = this.packageContext.getConstructors();
|
|
108
|
+
|
|
109
|
+
push(constructors, packageContextConstructors);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return constructors;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getPackageContext() {
|
|
116
|
+
return this.packageContext;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
findTypeByTypeName(typeName) {
|
|
120
|
+
const types = this.getTypes(),
|
|
121
|
+
type = types.find((type) => {
|
|
122
|
+
const matches = type.matchTypeName(typeName);
|
|
123
|
+
|
|
124
|
+
if (matches) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}) || null;
|
|
128
|
+
|
|
129
|
+
return type;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
findRuleByReferenceName(referenceName) {
|
|
133
|
+
const label = referenceName, ///
|
|
134
|
+
rules = this.getRules(),
|
|
135
|
+
rule = rules.find((rule) => {
|
|
136
|
+
const ruleLabels = rule.getLabels(),
|
|
137
|
+
ruleLabelsIncludesLabel = ruleLabels.includes(label);
|
|
138
|
+
|
|
139
|
+
if (ruleLabelsIncludesLabel) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
}) || null;
|
|
143
|
+
|
|
144
|
+
return rule;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
findAxiomByReferenceName(referenceName) {
|
|
148
|
+
const label = referenceName, ///
|
|
149
|
+
axioms = this.getAxioms(),
|
|
150
|
+
axiom = axioms.find((axiom) => {
|
|
151
|
+
const axiomLabels = axiom.getLabels(),
|
|
152
|
+
axiomLabelsIncludesLabel = axiomLabels.includes(label);
|
|
153
|
+
|
|
154
|
+
if (axiomLabelsIncludesLabel) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
}) || null;
|
|
158
|
+
|
|
159
|
+
return axiom;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
findVariableByVariableName(variableName) {
|
|
163
|
+
const name = variableName, ///
|
|
164
|
+
variable = this.variables.find((variable) => {
|
|
165
|
+
const matches = variable.matchName(name);
|
|
166
|
+
|
|
167
|
+
if (matches) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
}) || null;
|
|
171
|
+
|
|
172
|
+
return variable;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
isDerived() {
|
|
176
|
+
const derived = false;
|
|
177
|
+
|
|
178
|
+
return derived;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
isLabelPresent(label) {
|
|
182
|
+
const labels = this.getLabels(),
|
|
183
|
+
labelsIncludesLabel = labels.includes(label),
|
|
184
|
+
labelPresent = labelsIncludesLabel; ///
|
|
185
|
+
|
|
186
|
+
return labelPresent;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
isTypePresentByTypeName(typeName) {
|
|
190
|
+
const type = this.findTypeByTypeName(typeName),
|
|
191
|
+
typePresent = (type !== null);
|
|
192
|
+
|
|
193
|
+
return typePresent;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
isMetastatementNodePresent(metaStatementNode) {
|
|
197
|
+
const metastatementNodePresent = false;
|
|
198
|
+
|
|
199
|
+
return metastatementNodePresent;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
isVariablePresentByVariableName(variableName) {
|
|
203
|
+
const variable = this.findVariableByVariableName(variableName),
|
|
204
|
+
variablePresent = (variable !== null);
|
|
205
|
+
|
|
206
|
+
return variablePresent;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
addType(type) {
|
|
210
|
+
this.types.push(type);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
addRule(rule) {
|
|
214
|
+
this.rules.push(rule);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
addAxiom(axiom) {
|
|
218
|
+
this.axioms.push(axiom);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
addVariable(variable) {
|
|
222
|
+
this.variables.push(variable);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
addCombinator(combinator) {
|
|
226
|
+
this.combinators.push(combinator);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
addConstructor(constructor) {
|
|
230
|
+
this.constructors.push(constructor);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
setInAntecedent(inAntecedent) {
|
|
234
|
+
///
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static fromPackageContextAndFilePath(packageContext, filePath) {
|
|
238
|
+
const fileContent = packageContext.getFileContent(filePath),
|
|
239
|
+
content = fileContent, ///
|
|
240
|
+
tokens = packageContext.tokenise(content),
|
|
241
|
+
node = packageContext.parse(tokens);
|
|
242
|
+
|
|
243
|
+
rewriteNodes(node);
|
|
244
|
+
|
|
245
|
+
const rules = [],
|
|
246
|
+
types = [],
|
|
247
|
+
axioms = [],
|
|
248
|
+
variables = [],
|
|
249
|
+
combinators = [],
|
|
250
|
+
constructors = [],
|
|
251
|
+
fileContext = new FileContext(tokens, node, rules, types, axioms, variables, combinators, constructors, packageContext);
|
|
252
|
+
|
|
253
|
+
return fileContext;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
module.exports = FileContext;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { nodeAsString } = require("../utilities/string");
|
|
4
|
+
|
|
5
|
+
class MetaproofContext {
|
|
6
|
+
constructor(context, derived, metastatementNodes) {
|
|
7
|
+
this.context = context;
|
|
8
|
+
this.derived = derived;
|
|
9
|
+
this.metastatementNodes = metastatementNodes;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getContext() {
|
|
13
|
+
return this.context;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
isDerived() {
|
|
17
|
+
return this.derived;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getMetastatementNodes() {
|
|
21
|
+
return this.metastatementNodes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getRules() { return this.context.getRules(); }
|
|
25
|
+
|
|
26
|
+
getTypes() { return this.context.getTypes(); }
|
|
27
|
+
|
|
28
|
+
getAxioms() { return this.context.getAxioms(); }
|
|
29
|
+
|
|
30
|
+
getCombinators() { return this.context.getCombinators(); }
|
|
31
|
+
|
|
32
|
+
getConstructors() { return this.context.getConstructors(); }
|
|
33
|
+
|
|
34
|
+
findTypeByTypeName(typeName) { return this.context.findTypeByTypeName(typeName); }
|
|
35
|
+
|
|
36
|
+
findRuleByReferenceName(referenceName) { return this.context.findRuleByReferenceName(referenceName); }
|
|
37
|
+
|
|
38
|
+
findVariableByVariableName(variableName) { return this.context.findVariableByVariableName(variableName); }
|
|
39
|
+
|
|
40
|
+
isLabelPresent(label) { return this.context.isLabelPresent(label); }
|
|
41
|
+
|
|
42
|
+
isTypePresentByTypeName(typeName) { return this.context.isTypePresentByTypeName(typeName); }
|
|
43
|
+
|
|
44
|
+
isMetastatementNodePresent(metaStatementNode) {
|
|
45
|
+
const metastatementNodeA = metaStatementNode; ///
|
|
46
|
+
|
|
47
|
+
let metastatementNodePresent = this.metastatementNodes.some((metaStatementNode) => {
|
|
48
|
+
const metastatementNodeB = metaStatementNode, ///
|
|
49
|
+
metastatementNodeAString = nodeAsString(metastatementNodeA),
|
|
50
|
+
metastatementNodeBString = nodeAsString(metastatementNodeB),
|
|
51
|
+
matches = (metastatementNodeAString === metastatementNodeBString);
|
|
52
|
+
|
|
53
|
+
if (matches) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (!metastatementNodePresent) {
|
|
59
|
+
metastatementNodePresent = this.context.isMetastatementNodePresent(metaStatementNode);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return metastatementNodePresent;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
isVariablePresentByVariableName(variableName) { return this.context.isVariablePresentByVariableName(variableName); }
|
|
66
|
+
|
|
67
|
+
setDerived(derived) {
|
|
68
|
+
if (derived) {
|
|
69
|
+
this.metastatementNodes.pop();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.derived = derived;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
addRule(rule) { this.context.addRule(rule); }
|
|
76
|
+
|
|
77
|
+
addMetastatementNode(metastatementNode) {
|
|
78
|
+
this.metastatementNodes.push(metastatementNode);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static fromContext(context) {
|
|
82
|
+
const derived = false,
|
|
83
|
+
metastatementNodes = [],
|
|
84
|
+
metaproofContext = new MetaproofContext(context, derived, metastatementNodes);
|
|
85
|
+
|
|
86
|
+
return metaproofContext;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports = MetaproofContext;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { fileSystemUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const PackageContext = require("../../context/package");
|
|
6
|
+
|
|
7
|
+
const { filePathsFromPackageName, dependencyPackageNamesFromPackageName } = require("../../utilities/fileSystem"),
|
|
8
|
+
{ TERM_BNF_FILE_NAME,
|
|
9
|
+
STATEMENT_BNF_FILE_NAME,
|
|
10
|
+
METASTATEMENT_BNF_FILE_NAME,
|
|
11
|
+
TYPE_PATTERN_FILE_NAME,
|
|
12
|
+
SYMBOL_PATTERN_FILE_NAME,
|
|
13
|
+
OPERATOR_PATTERN_FILE_NAME } = require("../../fileNames");
|
|
14
|
+
|
|
15
|
+
const { readFile, checkFileExists } = fileSystemUtilities;
|
|
16
|
+
|
|
17
|
+
class FileSystemPackageContext extends PackageContext {
|
|
18
|
+
getFilePaths() {
|
|
19
|
+
const packageName = this.getPackageName(),
|
|
20
|
+
filePaths = filePathsFromPackageName(packageName);
|
|
21
|
+
|
|
22
|
+
return filePaths;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getFileContent(filePath) {
|
|
26
|
+
const fileContent = readFile(filePath);
|
|
27
|
+
|
|
28
|
+
return fileContent;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getDependencyPackageNames() {
|
|
32
|
+
const packageName = this.getPackageName(),
|
|
33
|
+
dependencyPackageNames = dependencyPackageNamesFromPackageName(packageName);
|
|
34
|
+
|
|
35
|
+
return dependencyPackageNames;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getTermBNF() {
|
|
39
|
+
const packageName = this.getPackageName(),
|
|
40
|
+
directoryName = packageName, ///
|
|
41
|
+
fileName = TERM_BNF_FILE_NAME, ///
|
|
42
|
+
fileContent = fileContentFromDirectoryNameAndFileName(directoryName, fileName),
|
|
43
|
+
termBNF = fileContent; ///
|
|
44
|
+
|
|
45
|
+
return termBNF;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getStatementBNF() {
|
|
49
|
+
const packageName = this.getPackageName(),
|
|
50
|
+
directoryName = packageName, ///
|
|
51
|
+
fileName = STATEMENT_BNF_FILE_NAME, ///
|
|
52
|
+
fileContent = fileContentFromDirectoryNameAndFileName(directoryName, fileName),
|
|
53
|
+
termBNF = fileContent; ///
|
|
54
|
+
|
|
55
|
+
return termBNF;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getMetastatementBNF() {
|
|
59
|
+
const packageName = this.getPackageName(),
|
|
60
|
+
directoryName = packageName, ///
|
|
61
|
+
fileName = METASTATEMENT_BNF_FILE_NAME, ///
|
|
62
|
+
fileContent = fileContentFromDirectoryNameAndFileName(directoryName, fileName),
|
|
63
|
+
termBNF = fileContent; ///
|
|
64
|
+
|
|
65
|
+
return termBNF;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getTypePattern() {
|
|
69
|
+
const packageName = this.getPackageName(),
|
|
70
|
+
directoryName = packageName, ///
|
|
71
|
+
fileName = TYPE_PATTERN_FILE_NAME, ///
|
|
72
|
+
fileContent = fileContentFromDirectoryNameAndFileName(directoryName, fileName),
|
|
73
|
+
termBNF = fileContent; ///
|
|
74
|
+
|
|
75
|
+
return termBNF;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getSymbolPattern() {
|
|
79
|
+
const packageName = this.getPackageName(),
|
|
80
|
+
directoryName = packageName, ///
|
|
81
|
+
fileName = SYMBOL_PATTERN_FILE_NAME, ///
|
|
82
|
+
fileContent = fileContentFromDirectoryNameAndFileName(directoryName, fileName),
|
|
83
|
+
termBNF = fileContent; ///
|
|
84
|
+
|
|
85
|
+
return termBNF;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getOperatorPattern() {
|
|
89
|
+
const packageName = this.getPackageName(),
|
|
90
|
+
directoryName = packageName, ///
|
|
91
|
+
fileName = OPERATOR_PATTERN_FILE_NAME, ///
|
|
92
|
+
fileContent = fileContentFromDirectoryNameAndFileName(directoryName, fileName),
|
|
93
|
+
termBNF = fileContent; ///
|
|
94
|
+
|
|
95
|
+
return termBNF;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static fromPackageName(packageName) { return PackageContext.fromPackageName(FileSystemPackageContext, packageName); }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = FileSystemPackageContext;
|
|
102
|
+
|
|
103
|
+
function fileContentFromDirectoryNameAndFileName(directoryName, fileName) {
|
|
104
|
+
const filePath = `${directoryName}/${fileName}`,
|
|
105
|
+
fileExists = checkFileExists(filePath),
|
|
106
|
+
fileContent = fileExists ?
|
|
107
|
+
readFile(filePath) :
|
|
108
|
+
null;
|
|
109
|
+
|
|
110
|
+
return fileContent;
|
|
111
|
+
}
|