occam-furtle 2.0.279 → 2.0.282
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 +0 -11
- package/lib/constants.js +29 -1
- package/lib/context/block.js +15 -1
- package/lib/context/file.js +127 -50
- package/lib/element/assignment/array.js +186 -0
- package/lib/element/assignment/object.js +244 -0
- package/lib/element/assignment/variable.js +144 -0
- package/lib/element/assignments/variable.js +158 -0
- package/lib/element/block/return.js +198 -0
- package/lib/element/comparison.js +179 -0
- package/lib/element/declaration/procedure.js +139 -0
- package/lib/{dom → element}/error.js +12 -4
- package/lib/element/every.js +179 -0
- package/lib/element/expression/bitwise.js +186 -0
- package/lib/element/expression/bracketed.js +149 -0
- package/lib/element/expression/negated.js +166 -0
- package/lib/element/expression.js +578 -0
- package/lib/element/expressions.js +210 -0
- package/lib/{dom → element}/label.js +4 -4
- package/lib/element/parameter/named.js +198 -0
- package/lib/element/parameter.js +165 -0
- package/lib/element/parameters/named.js +220 -0
- package/lib/element/parameters.js +198 -0
- package/lib/element/procedure/anonymous.js +181 -0
- package/lib/element/procedure.js +212 -0
- package/lib/element/procedureCall.js +166 -0
- package/lib/element/query/node.js +186 -0
- package/lib/element/query/nodes.js +179 -0
- package/lib/element/reduce.js +181 -0
- package/lib/element/reference.js +138 -0
- package/lib/element/some.js +179 -0
- package/lib/element/statement/return.js +138 -0
- package/lib/element/step.js +154 -0
- package/lib/element/ternary.js +171 -0
- package/lib/element/variable.js +279 -0
- package/lib/elements.js +27 -0
- package/lib/index.js +10 -2
- package/lib/log.js +202 -0
- package/lib/preamble.js +32 -32
- package/lib/process/verify.js +289 -0
- package/lib/utilities/context.js +46 -5
- package/package.json +3 -1
- package/src/constants.js +16 -0
- package/src/context/block.js +10 -0
- package/src/context/file.js +96 -54
- package/src/{dom → element}/assignment/array.js +6 -6
- package/src/{dom → element}/assignment/object.js +8 -8
- package/src/{dom → element}/assignment/variable.js +4 -4
- package/src/{dom → element}/assignments/variable.js +5 -5
- package/src/{dom → element}/block/return.js +5 -5
- package/src/{dom → element}/comparison.js +5 -5
- package/src/{dom → element}/declaration/procedure.js +22 -4
- package/src/{dom → element}/error.js +13 -4
- package/src/{dom → element}/every.js +6 -6
- package/src/{dom → element}/expression/bitwise.js +5 -5
- package/src/{dom → element}/expression/bracketed.js +4 -4
- package/src/{dom → element}/expression/negated.js +5 -5
- package/src/{dom → element}/expression.js +4 -4
- package/src/{dom → element}/expressions.js +6 -6
- package/src/{dom → element}/label.js +4 -4
- package/src/{dom → element}/parameter/named.js +4 -4
- package/src/{dom → element}/parameter.js +4 -4
- package/src/{dom → element}/parameters/named.js +5 -5
- package/src/{dom → element}/parameters.js +5 -5
- package/src/{dom → element}/procedure/anonymous.js +4 -4
- package/src/{dom → element}/procedure.js +5 -5
- package/src/{dom → element}/procedureCall.js +4 -4
- package/src/{dom → element}/query/node.js +5 -5
- package/src/{dom → element}/query/nodes.js +5 -5
- package/src/{dom → element}/reduce.js +5 -5
- package/src/{dom → element}/reference.js +4 -4
- package/src/{dom → element}/some.js +6 -6
- package/src/{dom → element}/statement/return.js +4 -4
- package/src/{dom → element}/step.js +4 -4
- package/src/{dom → element}/ternary.js +4 -4
- package/src/{dom → element}/variable.js +5 -5
- package/src/elements.js +13 -0
- package/src/index.js +5 -1
- package/src/log.js +139 -0
- package/src/preamble.js +31 -31
- package/src/process/verify.js +157 -0
- package/src/utilities/context.js +45 -2
- package/test/Free and bound variables.ftl +112 -0
- package/test/context/file.js +127 -0
- package/{src/example → test}/context/release.js +60 -12
- package/test/helpers/constants.js +17 -0
- package/{src/example/utilities → test/helpers}/expressions.js +8 -4
- package/{src/example/utilities → test/helpers}/furtle.js +8 -4
- package/{src/example/utilities → test/helpers}/grammar.js +8 -4
- package/{src/example/utilities → test/helpers}/nominal.js +10 -5
- package/{src/example/utilities → test/helpers}/procedure.js +6 -2
- package/test/main.js +55 -0
- package/example/Free and bound variables.ftl +0 -75
- package/lib/dom/assignment/array.js +0 -186
- package/lib/dom/assignment/object.js +0 -244
- package/lib/dom/assignment/variable.js +0 -144
- package/lib/dom/assignments/variable.js +0 -158
- package/lib/dom/block/return.js +0 -198
- package/lib/dom/comparison.js +0 -179
- package/lib/dom/declaration/procedure.js +0 -125
- package/lib/dom/every.js +0 -179
- package/lib/dom/expression/bitwise.js +0 -186
- package/lib/dom/expression/bracketed.js +0 -149
- package/lib/dom/expression/negated.js +0 -166
- package/lib/dom/expression.js +0 -578
- package/lib/dom/expressions.js +0 -210
- package/lib/dom/parameter/named.js +0 -198
- package/lib/dom/parameter.js +0 -165
- package/lib/dom/parameters/named.js +0 -220
- package/lib/dom/parameters.js +0 -198
- package/lib/dom/procedure/anonymous.js +0 -181
- package/lib/dom/procedure.js +0 -212
- package/lib/dom/procedureCall.js +0 -166
- package/lib/dom/query/node.js +0 -186
- package/lib/dom/query/nodes.js +0 -179
- package/lib/dom/reduce.js +0 -181
- package/lib/dom/reference.js +0 -138
- package/lib/dom/some.js +0 -179
- package/lib/dom/statement/return.js +0 -138
- package/lib/dom/step.js +0 -154
- package/lib/dom/ternary.js +0 -171
- package/lib/dom/variable.js +0 -279
- package/lib/dom.js +0 -27
- package/lib/example/context/file.js +0 -130
- package/lib/example/context/release.js +0 -160
- package/lib/example/utilities/expressions.js +0 -29
- package/lib/example/utilities/furtle.js +0 -19
- package/lib/example/utilities/grammar.js +0 -26
- package/lib/example/utilities/nominal.js +0 -25
- package/lib/example/utilities/procedure.js +0 -18
- package/src/dom.js +0 -13
- package/src/example/context/file.js +0 -69
- /package/{example → test}/customGrammars.json +0 -0
package/lib/utilities/context.js
CHANGED
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get chainContext () {
|
|
8
13
|
return chainContext;
|
|
14
|
+
},
|
|
15
|
+
get default () {
|
|
16
|
+
return _default;
|
|
17
|
+
},
|
|
18
|
+
get lineIndexFromNodeAndTokens () {
|
|
19
|
+
return lineIndexFromNodeAndTokens;
|
|
9
20
|
}
|
|
10
21
|
});
|
|
11
22
|
var _constants = require("../constants");
|
|
@@ -16,13 +27,43 @@ function _type_of(obj) {
|
|
|
16
27
|
function chainContext(context) {
|
|
17
28
|
return new Proxy(context, {
|
|
18
29
|
get: function(instance, name, receiver) {
|
|
30
|
+
var levelsIncludeName = _constants.LEVELS.includes(name);
|
|
31
|
+
if (levelsIncludeName) {
|
|
32
|
+
return function(message) {
|
|
33
|
+
var node = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
|
|
34
|
+
var level = name, depth = instance.getDepth(), indent = _constants.DOUBLE_SPACE.repeat(depth);
|
|
35
|
+
message = "".concat(indent).concat(message);
|
|
36
|
+
var fileContext = instance.getFileContext();
|
|
37
|
+
fileContext.writeToLog(level, message, node);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
19
40
|
if (name in instance) {
|
|
20
41
|
return Reflect.get(instance, name, receiver);
|
|
21
42
|
}
|
|
22
|
-
var _$context = instance.
|
|
43
|
+
var _$context = instance.getContext(), value = _$context[name];
|
|
23
44
|
return (typeof value === "undefined" ? "undefined" : _type_of(value)) === _constants.FUNCTION ? value.bind(_$context) : value;
|
|
24
45
|
}
|
|
25
46
|
});
|
|
26
47
|
}
|
|
48
|
+
function lineIndexFromNodeAndTokens(node, tokens, lineIndex) {
|
|
49
|
+
if (node !== null) {
|
|
50
|
+
lineIndex = 0;
|
|
51
|
+
var firstSignificantTokenIndex = node.getFirstSignificantTokenIndex(tokens);
|
|
52
|
+
tokens.some(function(token, tokenIndex) {
|
|
53
|
+
var tokenEndOfLineToken = token.isEndOfLineToken();
|
|
54
|
+
if (tokenEndOfLineToken) {
|
|
55
|
+
lineIndex += 1;
|
|
56
|
+
}
|
|
57
|
+
if (tokenIndex === firstSignificantTokenIndex) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return lineIndex;
|
|
63
|
+
}
|
|
64
|
+
var _default = {
|
|
65
|
+
chainContext: chainContext,
|
|
66
|
+
lineIndexFromNodeAndTokens: lineIndexFromNodeAndTokens
|
|
67
|
+
};
|
|
27
68
|
|
|
28
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
69
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsaXRpZXMvY29udGV4dC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJcInVzZSBzdHJpY3RcIjtcblxuaW1wb3J0IHsgTEVWRUxTLCBGVU5DVElPTiwgRE9VQkxFX1NQQUNFIH0gZnJvbSBcIi4uL2NvbnN0YW50c1wiO1xuXG5leHBvcnQgZnVuY3Rpb24gY2hhaW5Db250ZXh0KGNvbnRleHQpIHtcbiAgcmV0dXJuIG5ldyBQcm94eShjb250ZXh0LCB7XG4gICAgZ2V0OiAoaW5zdGFuY2UsIG5hbWUsIHJlY2VpdmVyKSA9PiB7XG4gICAgICBjb25zdCBsZXZlbHNJbmNsdWRlTmFtZSA9IExFVkVMUy5pbmNsdWRlcyhuYW1lKTtcblxuICAgICAgaWYgKGxldmVsc0luY2x1ZGVOYW1lKSB7XG4gICAgICAgIHJldHVybiAobWVzc2FnZSwgbm9kZSA9IG51bGwpID0+IHtcbiAgICAgICAgICBjb25zdCBsZXZlbCA9IG5hbWUsIC8vL1xuICAgICAgICAgICAgICAgIGRlcHRoID0gaW5zdGFuY2UuZ2V0RGVwdGgoKSxcbiAgICAgICAgICAgICAgICBpbmRlbnQgPSBET1VCTEVfU1BBQ0UucmVwZWF0KGR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FnQjtZQUVsRCxJQUFJRCxxQkFBcUI7Z0JBQ3ZCTixhQUFhO1lBQ2Y7WUFFQSxJQUFJSyxlQUFlSiw0QkFBNEI7Z0JBQzdDLE9BQU87WUFDVDtRQUNGO0lBQ0Y7SUFFQSxPQUFPRDtBQUNUO0lBRUEsV0FBZTtJQUNiNUIsY0FBQUE7SUFDQUMsNEJBQUFBO0FBQ0YifQ==
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "occam-furtle",
|
|
3
3
|
"author": "James Smith",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.282",
|
|
5
5
|
"license": "MIT, Anti-996",
|
|
6
6
|
"homepage": "https://github.com/djalbat/occam-furtle",
|
|
7
7
|
"description": "Occam's Furtle language.",
|
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@swc/core": "1.13.20",
|
|
18
|
+
"chai": "^4.1.0",
|
|
18
19
|
"express": "^5.1.0",
|
|
19
20
|
"lively-cli": "^2.0.77",
|
|
21
|
+
"mocha": "^6.0.2",
|
|
20
22
|
"occam-custom-grammars": "^5.0.1340",
|
|
21
23
|
"occam-entities": "^1.0.444",
|
|
22
24
|
"occam-query": "^4.1.142",
|
package/src/constants.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import { levels } from "necessary";
|
|
4
|
+
|
|
5
|
+
const { TRACE_LEVEL, DEBUG_LEVEL, INFO_LEVEL, WARNING_LEVEL, ERROR_LEVEL } = levels;
|
|
6
|
+
|
|
7
|
+
export const LEVELS = [
|
|
8
|
+
TRACE_LEVEL,
|
|
9
|
+
DEBUG_LEVEL,
|
|
10
|
+
INFO_LEVEL,
|
|
11
|
+
WARNING_LEVEL,
|
|
12
|
+
ERROR_LEVEL
|
|
13
|
+
];
|
|
14
|
+
|
|
3
15
|
export const NULL = "null";
|
|
4
16
|
export const TRUE = "true";
|
|
5
17
|
export const FALSE = "false";
|
|
@@ -9,4 +21,8 @@ export const UNDERSCORE = "_";
|
|
|
9
21
|
export const CONJUNCTION = "&&";
|
|
10
22
|
export const DISJUNCTION = "||";
|
|
11
23
|
export const EMPTY_STRING = "";
|
|
24
|
+
export const SINGLE_SPACE = " ";
|
|
25
|
+
export const DOUBLE_SPACE = " ";
|
|
12
26
|
export const NOT_EQUAL_TO = "!=";
|
|
27
|
+
export const LEVEL_MAXIMUM_LENGTH = 7;
|
|
28
|
+
export const LINE_INDEX_MAXIMUM_LENGTH = 4;
|
package/src/context/block.js
CHANGED
|
@@ -74,6 +74,16 @@ export default class BlockContext {
|
|
|
74
74
|
this.variables.push(variable);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
getFileContext() { return this.context.getFileContext(); }
|
|
78
|
+
|
|
79
|
+
getDepth() {
|
|
80
|
+
let depth = this.context.getDepth();
|
|
81
|
+
|
|
82
|
+
depth++;
|
|
83
|
+
|
|
84
|
+
return depth;
|
|
85
|
+
}
|
|
86
|
+
|
|
77
87
|
static fromVariables(variables, context) {
|
|
78
88
|
const blockContext = new BlockContext(context, variables);
|
|
79
89
|
|
package/src/context/file.js
CHANGED
|
@@ -3,26 +3,24 @@
|
|
|
3
3
|
import { arrayUtilities } from "necessary";
|
|
4
4
|
import { lexersUtilities, parsersUtilities } from "occam-grammars";
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import { nodesQuery } from "../utilities/query";
|
|
9
|
-
import { chainContext } from "../utilities/context";
|
|
6
|
+
import { LEVELS } from "../constants";
|
|
7
|
+
import { verifyFile } from "../process/verify";
|
|
10
8
|
import { nodeAsString, nodesAsString } from "../utilities/string";
|
|
9
|
+
import { chainContext, lineIndexFromNodeAndTokens } from "../utilities/context";
|
|
11
10
|
|
|
12
11
|
const { push } = arrayUtilities,
|
|
13
12
|
{ furtleLexerFromNothing } = lexersUtilities,
|
|
14
|
-
{ furtleParserFromNothing } = parsersUtilities
|
|
13
|
+
{ furtleParserFromNothing } = parsersUtilities,
|
|
14
|
+
[ TRACE_LEVEL, DEBUG_LEVEL, INFO_LEVEL, WARNING_LEVEL, ERROR_LEVEL ] = LEVELS;
|
|
15
15
|
|
|
16
16
|
const furtleLexer = furtleLexerFromNothing(),
|
|
17
17
|
furtleParser = furtleParserFromNothing();
|
|
18
18
|
|
|
19
|
-
const errorNodesQuery = nodesQuery("/document/error"),
|
|
20
|
-
procedureDeclarationNodesQuery = nodesQuery("/document/procedureDeclaration");
|
|
21
|
-
|
|
22
19
|
export default class FileContext {
|
|
23
|
-
constructor(context, filePath, node, tokens, procedures) {
|
|
20
|
+
constructor(context, filePath, lineIndex, node, tokens, procedures) {
|
|
24
21
|
this.context = context;
|
|
25
22
|
this.filePath = filePath;
|
|
23
|
+
this.lineIndex = lineIndex;
|
|
26
24
|
this.node = node;
|
|
27
25
|
this.tokens = tokens;
|
|
28
26
|
this.procedures = procedures;
|
|
@@ -38,6 +36,10 @@ export default class FileContext {
|
|
|
38
36
|
return this.filePath;
|
|
39
37
|
}
|
|
40
38
|
|
|
39
|
+
getLineIndex() {
|
|
40
|
+
return this.lineIndex;
|
|
41
|
+
}
|
|
42
|
+
|
|
41
43
|
getNode() {
|
|
42
44
|
return this.node;
|
|
43
45
|
}
|
|
@@ -150,27 +152,18 @@ export default class FileContext {
|
|
|
150
152
|
return metavariables;
|
|
151
153
|
}
|
|
152
154
|
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
+
addProcedure(procedure) {
|
|
156
|
+
const procedureString = procedure.getString();
|
|
155
157
|
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
addProcedures() {
|
|
160
|
-
const context = this; ///
|
|
161
|
-
|
|
162
|
-
const { ProcedureDeclaration } = dom,
|
|
163
|
-
procedureDeclarationNodes = procedureDeclarationNodesQuery(this.node);
|
|
158
|
+
this.procedures.push(procedure);
|
|
164
159
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
procedure = procedureDeclaration.getProcedure(),
|
|
168
|
-
procedureString = procedure.getString();
|
|
160
|
+
this.debug(`Added the '${procedureString}' procedure to the context.`);
|
|
161
|
+
}
|
|
169
162
|
|
|
170
|
-
|
|
163
|
+
getVariables() {
|
|
164
|
+
const variables = [];
|
|
171
165
|
|
|
172
|
-
|
|
173
|
-
});
|
|
166
|
+
return variables;
|
|
174
167
|
}
|
|
175
168
|
|
|
176
169
|
nodeAsString(node) {
|
|
@@ -185,49 +178,86 @@ export default class FileContext {
|
|
|
185
178
|
return string;
|
|
186
179
|
}
|
|
187
180
|
|
|
188
|
-
trace(message
|
|
181
|
+
trace(message, node = null) {
|
|
182
|
+
const level = TRACE_LEVEL;
|
|
189
183
|
|
|
190
|
-
|
|
184
|
+
this.writeToLog(level, message, node);
|
|
185
|
+
}
|
|
191
186
|
|
|
192
|
-
|
|
187
|
+
debug(message, node = null) {
|
|
188
|
+
const level = DEBUG_LEVEL;
|
|
193
189
|
|
|
194
|
-
|
|
190
|
+
this.writeToLog(level, message, node);
|
|
191
|
+
}
|
|
195
192
|
|
|
196
|
-
|
|
193
|
+
info(message, node = null) {
|
|
194
|
+
const level = INFO_LEVEL;
|
|
197
195
|
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
this.writeToLog(level, message, node);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
warning(message, node = null) {
|
|
200
|
+
const level = WARNING_LEVEL;
|
|
201
|
+
|
|
202
|
+
this.writeToLog(level, message, node);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
error(message, node = null) {
|
|
206
|
+
const level = ERROR_LEVEL;
|
|
207
|
+
|
|
208
|
+
this.writeToLog(level, message, node);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
writeToLog(level, message, node) {
|
|
212
|
+
const lineIndex = lineIndexFromNodeAndTokens(node, this.tokens, this.lineIndex),
|
|
213
|
+
filePath = (lineIndex === null) ?
|
|
214
|
+
this.filePath :
|
|
215
|
+
null;
|
|
216
|
+
|
|
217
|
+
this.context.writeToLog(level, message, filePath, lineIndex);
|
|
200
218
|
|
|
201
|
-
this.
|
|
219
|
+
this.lineIndex = lineIndex;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
getFileContext() {
|
|
223
|
+
const fileContext = this; ///
|
|
224
|
+
|
|
225
|
+
return fileContext;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
getDepth() {
|
|
229
|
+
let depth = this.context.getDepth();
|
|
230
|
+
|
|
231
|
+
depth++;
|
|
232
|
+
|
|
233
|
+
return depth;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
verify() {
|
|
237
|
+
let verifies = false;
|
|
202
238
|
|
|
203
239
|
this.prepare();
|
|
204
240
|
|
|
205
241
|
if (this.node === null) {
|
|
206
242
|
this.warning(`Unable to verify the '${this.filePath}' file because it cannot be parsed.`);
|
|
207
243
|
} else {
|
|
208
|
-
|
|
209
|
-
errorNodesLength = errorNodes.length;
|
|
244
|
+
this.debug(`Verifying the '${this.filePath}' file...`);
|
|
210
245
|
|
|
211
|
-
|
|
212
|
-
|
|
246
|
+
const context = this, ///
|
|
247
|
+
fileNode = this.node; ///
|
|
213
248
|
|
|
214
|
-
|
|
215
|
-
} else {
|
|
216
|
-
this.warning(`The '${this.filePath}' file cannot be verified because there are errors.`);
|
|
249
|
+
verifies = verifyFile(fileNode, context);
|
|
217
250
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
251
|
+
verifies ?
|
|
252
|
+
this.complete() :
|
|
253
|
+
this.clear();
|
|
221
254
|
|
|
222
|
-
|
|
223
|
-
|
|
255
|
+
if (verifies) {
|
|
256
|
+
this.info(`...verified the '${this.filePath}' file.`);
|
|
257
|
+
}
|
|
224
258
|
}
|
|
225
259
|
|
|
226
|
-
return
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
clear() {
|
|
230
|
-
this.procedures = [];
|
|
260
|
+
return verifies;
|
|
231
261
|
}
|
|
232
262
|
|
|
233
263
|
prepare() {
|
|
@@ -245,6 +275,16 @@ export default class FileContext {
|
|
|
245
275
|
this.node = parser.parse(this.tokens);
|
|
246
276
|
}
|
|
247
277
|
|
|
278
|
+
clear() {
|
|
279
|
+
this.lineIndex = null;
|
|
280
|
+
|
|
281
|
+
this.procedures = [];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
complete() {
|
|
285
|
+
this.lineIndex = null;
|
|
286
|
+
}
|
|
287
|
+
|
|
248
288
|
initialise(json) {
|
|
249
289
|
const { content } = json,
|
|
250
290
|
lexer = this.getLexer(),
|
|
@@ -273,19 +313,21 @@ export default class FileContext {
|
|
|
273
313
|
|
|
274
314
|
static fromFile(file, context) {
|
|
275
315
|
const filePath = file.getPath(),
|
|
316
|
+
lineIndex = null,
|
|
276
317
|
tokens = null,
|
|
277
318
|
node = null,
|
|
278
319
|
procedures = [],
|
|
279
|
-
fileContext = new FileContext(context, filePath, node, tokens, procedures);
|
|
320
|
+
fileContext = new FileContext(context, filePath, lineIndex, node, tokens, procedures);
|
|
280
321
|
|
|
281
322
|
return fileContext;
|
|
282
323
|
}
|
|
283
324
|
|
|
284
325
|
static fromFilePath(filePath, context) {
|
|
285
|
-
const
|
|
326
|
+
const lineIndex = null,
|
|
327
|
+
tokens = null,
|
|
286
328
|
node = null,
|
|
287
329
|
procedures = null,
|
|
288
|
-
fileContext = new FileContext(context, filePath, node, tokens, procedures);
|
|
330
|
+
fileContext = new FileContext(context, filePath, lineIndex, node, tokens, procedures);
|
|
289
331
|
|
|
290
332
|
return fileContext;
|
|
291
333
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import elements from "../../elements";
|
|
4
4
|
import Exception from "../../exception";
|
|
5
5
|
|
|
6
|
+
import { define } from "../../elements";
|
|
6
7
|
import { nodeQuery } from "../../utilities/query";
|
|
7
|
-
import { domAssigned } from "../../dom";
|
|
8
8
|
import { NODE_TYPE, NODES_TYPE } from "../../types";
|
|
9
9
|
|
|
10
10
|
const stepArrayAssignmentNodeQuery = nodeQuery("/step/arrayAssignment");
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default define(class ArrayAssigment {
|
|
13
13
|
constructor(string, variable, parameters) {
|
|
14
14
|
this.string = string;
|
|
15
15
|
this.variable = variable;
|
|
@@ -59,7 +59,7 @@ export default domAssigned(class ArrayAssigment {
|
|
|
59
59
|
|
|
60
60
|
this.parameters.forEachParameter((parameter, index) => {
|
|
61
61
|
if (parameter !== null) {
|
|
62
|
-
const { Expression } =
|
|
62
|
+
const { Expression } = elements,
|
|
63
63
|
node = nodes[index],
|
|
64
64
|
expression = Expression.fromNode(node, context);
|
|
65
65
|
|
|
@@ -85,7 +85,7 @@ export default domAssigned(class ArrayAssigment {
|
|
|
85
85
|
throw exception;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const { Variable } =
|
|
88
|
+
const { Variable } = elements,
|
|
89
89
|
variable = Variable.fromParameter(parameter, context);
|
|
90
90
|
|
|
91
91
|
variable.assign(expression, context);
|
|
@@ -111,7 +111,7 @@ export default domAssigned(class ArrayAssigment {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
function arrayAssignmentFromArrayAssignmentNode(arrayAssignmentNode, context) {
|
|
114
|
-
const { Variable, Parameters, ArrayAssignment } =
|
|
114
|
+
const { Variable, Parameters, ArrayAssignment } = elements,
|
|
115
115
|
parameters = Parameters.fromArrayAssignmentNode(arrayAssignmentNode, context),
|
|
116
116
|
variable = Variable.fromArrayAssignmentNode(arrayAssignmentNode, context),
|
|
117
117
|
string = stringFromVariableAndParameters(variable, parameters, context),
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import elements from "../../elements";
|
|
4
4
|
import Exception from "../../exception";
|
|
5
5
|
import nodeProperties from "../../nodeProperties";
|
|
6
6
|
|
|
7
|
+
import { define } from "../../elements";
|
|
7
8
|
import { nodeQuery } from "../../utilities/query";
|
|
8
|
-
import { domAssigned } from "../../dom";
|
|
9
9
|
import { NODE_TYPE, NODES_TYPE, STRING_TYPE, BOOLEAN_TYPE } from "../../types";
|
|
10
10
|
import { CONTENT_PARAMETER_NAME, TERMINAL_PARAMETER_NAME, CHILD_NODES_PARAMETER_NAME } from "../../parameterNames";
|
|
11
11
|
|
|
12
12
|
const stepObjectAssignmentNodeQuery = nodeQuery("/step/objectAssignment");
|
|
13
13
|
|
|
14
|
-
export default
|
|
14
|
+
export default define(class ObjectAssigment {
|
|
15
15
|
constructor(string, variable, namedParameters) {
|
|
16
16
|
this.string = string;
|
|
17
17
|
this.variable = variable;
|
|
@@ -83,7 +83,7 @@ export default domAssigned(class ObjectAssigment {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const { Variable } =
|
|
86
|
+
const { Variable } = elements,
|
|
87
87
|
variable = Variable.fromNamedParameter(namedParameter, context);
|
|
88
88
|
|
|
89
89
|
variable.assign(expression, context);
|
|
@@ -113,7 +113,7 @@ export default domAssigned(class ObjectAssigment {
|
|
|
113
113
|
throw exception;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
const { Expression } =
|
|
116
|
+
const { Expression } = elements,
|
|
117
117
|
terminalNode = node, ///
|
|
118
118
|
content = terminalNode.getContent(),
|
|
119
119
|
string = content; ///
|
|
@@ -138,7 +138,7 @@ export default domAssigned(class ObjectAssigment {
|
|
|
138
138
|
nodeTerminalNode = node.isTerminalNode(),
|
|
139
139
|
terminal = nodeTerminalNode; ///
|
|
140
140
|
|
|
141
|
-
const { Expression } =
|
|
141
|
+
const { Expression } = elements,
|
|
142
142
|
boolean = terminal; ///
|
|
143
143
|
|
|
144
144
|
expression = Expression.fromBoolean(boolean, context); ///
|
|
@@ -168,7 +168,7 @@ export default domAssigned(class ObjectAssigment {
|
|
|
168
168
|
throw exception;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
const { Expression } =
|
|
171
|
+
const { Expression } = elements,
|
|
172
172
|
nonTerminalNode = node, ///
|
|
173
173
|
childNodes = nonTerminalNode.getChildNodes(),
|
|
174
174
|
nodes = childNodes; ///
|
|
@@ -196,7 +196,7 @@ export default domAssigned(class ObjectAssigment {
|
|
|
196
196
|
});
|
|
197
197
|
|
|
198
198
|
function objectAssignmentFromObjectAssignmentNode(objectAssignmentNode, context) {
|
|
199
|
-
const { Variable, NamedParameters, ObjectAssigment } =
|
|
199
|
+
const { Variable, NamedParameters, ObjectAssigment } = elements,
|
|
200
200
|
namedParameters = NamedParameters.fromObjectAssignmentNode(objectAssignmentNode, context),
|
|
201
201
|
variable = Variable.fromObjectAssignmentNode(objectAssignmentNode, context),
|
|
202
202
|
string = stringFromVariableAndNamesParameters(variable, namedParameters, context),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import elements from "../../elements";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { define } from "../../elements";
|
|
6
6
|
|
|
7
|
-
export default
|
|
7
|
+
export default define(class VariableAssignment {
|
|
8
8
|
constructor(string, variable, expression) {
|
|
9
9
|
this.string = string;
|
|
10
10
|
this.variable = variable;
|
|
@@ -49,7 +49,7 @@ export default domAssigned(class VariableAssignment {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
function variableAssignmentFromTypeAndVariableAssignmentNode(type, variableAssignmentNode, context) {
|
|
52
|
-
const { Variable, Expression, VariableAssignment } =
|
|
52
|
+
const { Variable, Expression, VariableAssignment } = elements,
|
|
53
53
|
expression = Expression.fromVariableAssignmentNode(variableAssignmentNode, context),
|
|
54
54
|
variable = Variable.fromTypeAndVariableAssignmentNode(type, variableAssignmentNode, context),
|
|
55
55
|
string = stringFromExpressionAndVariable(expression, variable, context),
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import elements from "../../elements";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { define } from "../../elements";
|
|
6
6
|
import { nodeQuery, nodesQuery } from "../../utilities/query";
|
|
7
7
|
|
|
8
8
|
const typeTerminalNodeQuery = nodeQuery("/variableAssignments/@type"),
|
|
9
9
|
variableAssignmentNodesQuery = nodesQuery("/variableAssignments/variableAssignment"),
|
|
10
10
|
stepVariableAssignmentsNodeQuery = nodeQuery("/step/variableAssignments");
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default define(class VariableAssignments {
|
|
13
13
|
constructor(string, array) {
|
|
14
14
|
this.string = string;
|
|
15
15
|
this.array = array;
|
|
@@ -53,7 +53,7 @@ export default domAssigned(class VariableAssignments {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
function variableAssignmentsFromVariableAssignmentsNode(variableAssignmentsNode, context) {
|
|
56
|
-
const { VariableAssignments } =
|
|
56
|
+
const { VariableAssignments } = elements,
|
|
57
57
|
type = typeFromVariableAssignmentsNode(variableAssignmentsNode, context),
|
|
58
58
|
array = arrayFromTypeAndVariableAssignmentsNode(type, variableAssignmentsNode, context),
|
|
59
59
|
string = stringFromArray(array, context),
|
|
@@ -88,7 +88,7 @@ function typeFromVariableAssignmentsNode(variableAssignmentsNode, context) {
|
|
|
88
88
|
function arrayFromTypeAndVariableAssignmentsNode(type, variableAssignmentsNode, context) {
|
|
89
89
|
const variableAssignmentNodes = variableAssignmentNodesQuery(variableAssignmentsNode),
|
|
90
90
|
array = variableAssignmentNodes.map((variableAssignmentNode) => {
|
|
91
|
-
const { VariableAssignment } =
|
|
91
|
+
const { VariableAssignment } = elements,
|
|
92
92
|
variableAssignment = VariableAssignment.fromTypeAndVariableAssignmentNode(type, variableAssignmentNode, context);
|
|
93
93
|
|
|
94
94
|
return variableAssignment;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import elements from "../../elements";
|
|
4
4
|
import Exception from "../../exception";
|
|
5
5
|
import BlockContext from "../../context/block";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { define } from "../../elements";
|
|
8
8
|
import { nodeQuery, nodesQuery } from "../../utilities/query";
|
|
9
9
|
|
|
10
10
|
const stepNodesQuery = nodesQuery("/returnBlock/step"),
|
|
@@ -13,7 +13,7 @@ const stepNodesQuery = nodesQuery("/returnBlock/step"),
|
|
|
13
13
|
anonymousProcedureReturnBlockNodeQuery = nodeQuery("/anonymousProcedure/returnBlock"),
|
|
14
14
|
procedureDeclarationReturnBlockNodeQuery = nodeQuery("/procedureDeclaration/returnBlock");
|
|
15
15
|
|
|
16
|
-
export default
|
|
16
|
+
export default define(class ReturnBlock {
|
|
17
17
|
constructor(string, steps, nonsensical, returnStatement) {
|
|
18
18
|
this.string = string;
|
|
19
19
|
this.steps = steps;
|
|
@@ -105,7 +105,7 @@ function stringFromReturnStatement(returnStatement, context) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
function stepsFromReturnBlockNode(returnBlockNode, context) {
|
|
108
|
-
const { Step } =
|
|
108
|
+
const { Step } = elements,
|
|
109
109
|
stepNodes = stepNodesQuery(returnBlockNode),
|
|
110
110
|
steps = stepNodes.map((stepNode) => {
|
|
111
111
|
const step = Step.fromStepNode(stepNode, context);
|
|
@@ -117,7 +117,7 @@ function stepsFromReturnBlockNode(returnBlockNode, context) {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
function returnBlockFromReturnBlockNode(returnBlockNode, context) {
|
|
120
|
-
const { ReturnBlock, ReturnStatement } =
|
|
120
|
+
const { ReturnBlock, ReturnStatement } = elements,
|
|
121
121
|
returnStatement = ReturnStatement.fromReturnBlockNode(returnBlockNode, context),
|
|
122
122
|
nonsensical = nonsensicalFromReturnBlockNode(returnBlockNode, context),
|
|
123
123
|
steps = stepsFromReturnBlockNode(returnBlockNode, context),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import elements from "../elements";
|
|
4
4
|
import Exception from "../exception";
|
|
5
5
|
|
|
6
|
+
import { define } from "../elements";
|
|
6
7
|
import { nodeQuery } from "../utilities/query";
|
|
7
|
-
import { domAssigned } from "../dom";
|
|
8
8
|
import { EQUAL_TO, NOT_EQUAL_TO } from "../constants";
|
|
9
9
|
|
|
10
10
|
const terminalNodeQuery = nodeQuery("/comparison/@*"),
|
|
@@ -12,7 +12,7 @@ const terminalNodeQuery = nodeQuery("/comparison/@*"),
|
|
|
12
12
|
rightExpressionNodeQuery = nodeQuery("/comparison/expression[1]"),
|
|
13
13
|
expressionComparisonNodeQuery = nodeQuery("/expression/comparison");
|
|
14
14
|
|
|
15
|
-
export default
|
|
15
|
+
export default define(class Comparison {
|
|
16
16
|
constructor(string, negated, leftExpression, rightExpression) {
|
|
17
17
|
this.string = string;
|
|
18
18
|
this.negated = negated;
|
|
@@ -65,7 +65,7 @@ export default domAssigned(class Comparison {
|
|
|
65
65
|
boolean = !boolean; ///
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const { Expression } =
|
|
68
|
+
const { Expression } = elements;
|
|
69
69
|
|
|
70
70
|
expression = Expression.fromBoolean(boolean, context);
|
|
71
71
|
|
|
@@ -100,7 +100,7 @@ function negatedFromComparisonNode(comparisonNode) {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
function comparisonFromComparisonNode(comparisonNode, context) {
|
|
103
|
-
const { Expression, Comparison } =
|
|
103
|
+
const { Expression, Comparison } = elements,
|
|
104
104
|
leftExpressionNode = leftExpressionNodeQuery(comparisonNode),
|
|
105
105
|
rightExpressionNode = rightExpressionNodeQuery(comparisonNode),
|
|
106
106
|
rightExpression = Expression.fromExpressionNode(rightExpressionNode, context),
|