occam-furtle 2.0.120 → 2.0.121
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/dom/assignment/array.js +12 -12
- package/lib/dom/assignment/object.js +30 -30
- package/lib/dom/assignment/variable.js +13 -13
- package/lib/dom/block/return.js +9 -9
- package/lib/dom/comparison.js +28 -28
- package/lib/dom/every.js +25 -25
- package/lib/dom/expression/bitwise.js +186 -0
- package/lib/dom/expression/bracketed.js +149 -0
- package/lib/dom/expression/negated.js +166 -0
- package/lib/dom/expression.js +578 -0
- package/lib/dom/expressions.js +210 -0
- package/lib/dom/parameter/named.js +9 -9
- package/lib/dom/parameter.js +9 -9
- package/lib/dom/parameters/named.js +11 -11
- package/lib/dom/parameters.js +11 -11
- package/lib/dom/procedure/anonymous.js +7 -7
- package/lib/dom/procedure.js +12 -12
- package/lib/dom/procedureCall.js +17 -17
- package/lib/dom/query/node.js +19 -19
- package/lib/dom/query/nodes.js +19 -19
- package/lib/dom/reduce.js +32 -32
- package/lib/dom/some.js +25 -25
- package/lib/dom/statement/return.js +12 -12
- package/lib/dom/ternary.js +27 -27
- package/lib/dom/variable.js +30 -30
- package/lib/example/utilities/expressions.js +29 -0
- package/lib/example.js +4 -4
- package/lib/index.js +9 -9
- package/package.json +1 -1
- package/src/dom/assignment/array.js +14 -14
- package/src/dom/assignment/object.js +33 -33
- package/src/dom/assignment/variable.js +15 -15
- package/src/dom/block/return.js +7 -7
- package/src/dom/comparison.js +39 -39
- package/src/dom/every.js +25 -25
- package/src/dom/expression/bitwise.js +135 -0
- package/src/dom/expression/bracketed.js +73 -0
- package/src/dom/expression/negated.js +97 -0
- package/src/dom/{value.js → expression.js} +128 -128
- package/src/dom/expressions.js +138 -0
- package/src/dom/parameter/named.js +7 -7
- package/src/dom/parameter.js +7 -7
- package/src/dom/parameters/named.js +9 -9
- package/src/dom/parameters.js +9 -9
- package/src/dom/procedure/anonymous.js +10 -10
- package/src/dom/procedure.js +12 -12
- package/src/dom/procedureCall.js +19 -19
- package/src/dom/query/node.js +19 -19
- package/src/dom/query/nodes.js +19 -19
- package/src/dom/reduce.js +36 -36
- package/src/dom/some.js +25 -25
- package/src/dom/statement/return.js +14 -14
- package/src/dom/ternary.js +39 -39
- package/src/dom/variable.js +31 -31
- package/src/example/utilities/{values.js → expressions.js} +4 -4
- package/src/example.js +4 -4
- package/src/index.js +6 -6
- package/lib/dom/value/bitwise.js +0 -186
- package/lib/dom/value/bracketed.js +0 -149
- package/lib/dom/value/negated.js +0 -166
- package/lib/dom/value.js +0 -578
- package/lib/dom/values.js +0 -210
- package/lib/example/utilities/values.js +0 -29
- package/src/dom/value/bitwise.js +0 -135
- package/src/dom/value/bracketed.js +0 -73
- package/src/dom/value/negated.js +0 -97
- package/src/dom/values.js +0 -138
|
@@ -39,17 +39,17 @@ export default domAssigned(class NamedParameters {
|
|
|
39
39
|
|
|
40
40
|
forEachNamedParameter(callback) { this.array.forEach(callback); }
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
const
|
|
42
|
+
matchExpressions(expressions, context) {
|
|
43
|
+
const expressionsString = expressions.getString(),
|
|
44
44
|
namedParametersString = this.string; ///
|
|
45
45
|
|
|
46
|
-
context.trace(`Matching the ${
|
|
46
|
+
context.trace(`Matching the ${expressionsString} expressions against the '${namedParametersString}' named parameters...`);
|
|
47
47
|
|
|
48
|
-
const
|
|
48
|
+
const expressionsLength = expressions.getLength(),
|
|
49
49
|
namedParametersLength = this.getLength();
|
|
50
50
|
|
|
51
|
-
if (
|
|
52
|
-
const message = `The ${
|
|
51
|
+
if (expressionsLength !== namedParametersLength) {
|
|
52
|
+
const message = `The ${expressionsString} expressions and '${namedParametersString}' named parameters are not of the same length.`,
|
|
53
53
|
exception = Exception.fromMessage(message);
|
|
54
54
|
|
|
55
55
|
throw exception;
|
|
@@ -57,13 +57,13 @@ export default domAssigned(class NamedParameters {
|
|
|
57
57
|
|
|
58
58
|
this.forEachNamedParameter((namedParameter, index) => {
|
|
59
59
|
if (namedParameter !== null) {
|
|
60
|
-
const
|
|
60
|
+
const expression = expressions.getExpression(index);
|
|
61
61
|
|
|
62
|
-
namedParameter.
|
|
62
|
+
namedParameter.matchExpression(expression, context);
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
context.debug(`...matched the ${
|
|
66
|
+
context.debug(`...matched the ${expressionsString} expressions against the '${namedParametersString}' named parameters.`);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
matchNamedParameter(namedParameter, context) {
|
package/src/dom/parameters.js
CHANGED
|
@@ -40,17 +40,17 @@ export default domAssigned(class Parameters {
|
|
|
40
40
|
|
|
41
41
|
forEachParameter(callback) { this.array.forEach(callback); }
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
const
|
|
43
|
+
matchExpressions(expressions, context) {
|
|
44
|
+
const expressionsString = expressions.getString(),
|
|
45
45
|
parametersString = this.string; ///
|
|
46
46
|
|
|
47
|
-
context.trace(`Matching the ${
|
|
47
|
+
context.trace(`Matching the ${expressionsString} expressions against the '${parametersString}' parameters...`);
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
const expressionsLength = expressions.getLength(),
|
|
50
50
|
parametersLength = this.getLength();
|
|
51
51
|
|
|
52
|
-
if (
|
|
53
|
-
const message = `The ${
|
|
52
|
+
if (expressionsLength !== parametersLength) {
|
|
53
|
+
const message = `The ${expressionsString} expressions and '${parametersString}' parameters are not of the same length.`,
|
|
54
54
|
exception = Exception.fromMessage(message);
|
|
55
55
|
|
|
56
56
|
throw exception;
|
|
@@ -58,13 +58,13 @@ export default domAssigned(class Parameters {
|
|
|
58
58
|
|
|
59
59
|
this.forEachParameter((parameter, index) => {
|
|
60
60
|
if (parameter !== null) {
|
|
61
|
-
const
|
|
61
|
+
const expression = expressions.getExpression(index);
|
|
62
62
|
|
|
63
|
-
parameter.
|
|
63
|
+
parameter.matchExpression(expression, context);
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
context.debug(`...matched the ${
|
|
67
|
+
context.debug(`...matched the ${expressionsString} expressions against the '${parametersString}' parameters.`);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
static name = "Parameters";
|
|
@@ -5,7 +5,7 @@ import Exception from "../../exception";
|
|
|
5
5
|
|
|
6
6
|
import { nodeQuery } from "../../utilities/query";
|
|
7
7
|
import { domAssigned } from "../../dom";
|
|
8
|
-
import {
|
|
8
|
+
import { variablesFromExpressionsAndParameters } from "../procedure";
|
|
9
9
|
|
|
10
10
|
const typeTerminalNodeQuery = nodeQuery("/anonymousProcedure/@type"),
|
|
11
11
|
someAnonymousProcedureNodeQuery = nodeQuery("/some/anonymousProcedure"),
|
|
@@ -36,20 +36,20 @@ export default domAssigned(class AnonymousProcedure {
|
|
|
36
36
|
return this.returnBlock;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
call(
|
|
39
|
+
call(expressions, context) {
|
|
40
40
|
const anonymousProcedureString = this.string; ///
|
|
41
41
|
|
|
42
42
|
context.trace(`Calling the '${anonymousProcedureString}' anonymous procedure...`);
|
|
43
43
|
|
|
44
|
-
this.parameters.
|
|
44
|
+
this.parameters.matchExpressions(expressions, context);
|
|
45
45
|
|
|
46
|
-
const variables =
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const variables = variablesFromExpressionsAndParameters(expressions, this.parameters, context),
|
|
47
|
+
expression = this.returnBlock.evaluate(variables, context),
|
|
48
|
+
expressionType = expression.getType();
|
|
49
49
|
|
|
50
|
-
if (this.type !==
|
|
51
|
-
const
|
|
52
|
-
message = `The ${
|
|
50
|
+
if (this.type !== expressionType) {
|
|
51
|
+
const expressionString = expression.asString(context),
|
|
52
|
+
message = `The ${expressionString} expression's '${expressionType}' type and the '${anonymousProcedureString}' anonymous procedure's '${this.type}' type do not match.`,
|
|
53
53
|
exception = Exception.fromMessage(message);
|
|
54
54
|
|
|
55
55
|
throw exception;
|
|
@@ -57,7 +57,7 @@ export default domAssigned(class AnonymousProcedure {
|
|
|
57
57
|
|
|
58
58
|
context.debug(`...called the '${anonymousProcedureString}' anonymous procedure.`);
|
|
59
59
|
|
|
60
|
-
return
|
|
60
|
+
return expression;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
static name = "AnonymousProcedure";
|
package/src/dom/procedure.js
CHANGED
|
@@ -47,7 +47,7 @@ export default domAssigned(class Procedure {
|
|
|
47
47
|
|
|
48
48
|
matchName(name) { return this.label.matchName(name); }
|
|
49
49
|
|
|
50
|
-
call(
|
|
50
|
+
call(expressions, fileContext) {
|
|
51
51
|
let context;
|
|
52
52
|
|
|
53
53
|
context = fileContext; ///
|
|
@@ -56,15 +56,15 @@ export default domAssigned(class Procedure {
|
|
|
56
56
|
|
|
57
57
|
context.trace(`Calling the '${procedureString}' procedure...`);
|
|
58
58
|
|
|
59
|
-
this.parameters.
|
|
59
|
+
this.parameters.matchExpressions(expressions, context);
|
|
60
60
|
|
|
61
|
-
const variables =
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const variables = variablesFromExpressionsAndParameters(expressions, this.parameters, context),
|
|
62
|
+
expression = this.returnBlock.evaluate(variables, context),
|
|
63
|
+
expressionType = expression.getType();
|
|
64
64
|
|
|
65
|
-
if (this.type !==
|
|
66
|
-
const
|
|
67
|
-
message = `The ${
|
|
65
|
+
if (this.type !== expressionType) {
|
|
66
|
+
const expressionString = expression.asString(context),
|
|
67
|
+
message = `The ${expressionString} expression's '${expressionType}' type and the '${procedureString}' procedure's '${this.type}' type do not match.`,
|
|
68
68
|
exception = Exception.fromMessage(message);
|
|
69
69
|
|
|
70
70
|
throw exception;
|
|
@@ -74,7 +74,7 @@ export default domAssigned(class Procedure {
|
|
|
74
74
|
|
|
75
75
|
context.debug(`...called the '${procedureString}' procedure.`);
|
|
76
76
|
|
|
77
|
-
return
|
|
77
|
+
return expression;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
static name = "Procedure";
|
|
@@ -86,15 +86,15 @@ export default domAssigned(class Procedure {
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
export function
|
|
89
|
+
export function variablesFromExpressionsAndParameters(expressions, parameters, context) {
|
|
90
90
|
const variables = [];
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
expressions.forEachExpression((expression, index) => {
|
|
93
93
|
const { Variable } = dom,
|
|
94
94
|
parameter = parameters.getParameter(index);
|
|
95
95
|
|
|
96
96
|
if (parameter !== null) {
|
|
97
|
-
const variable = Variable.
|
|
97
|
+
const variable = Variable.fromExpressionAndParameter(expression, parameter, context);
|
|
98
98
|
|
|
99
99
|
variables.push(variable);
|
|
100
100
|
}
|
package/src/dom/procedureCall.js
CHANGED
|
@@ -6,13 +6,13 @@ import Exception from "../exception";
|
|
|
6
6
|
import { nodeQuery } from "../utilities/query";
|
|
7
7
|
import { domAssigned } from "../dom";
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const expressionProcedureCallNodeQuery = nodeQuery("/expression/procedureCall");
|
|
10
10
|
|
|
11
11
|
export default domAssigned(class ProcedureCall {
|
|
12
|
-
constructor(string, reference,
|
|
12
|
+
constructor(string, reference, expressions) {
|
|
13
13
|
this.string = string;
|
|
14
14
|
this.reference = reference;
|
|
15
|
-
this.
|
|
15
|
+
this.expressions = expressions;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
getString() {
|
|
@@ -23,8 +23,8 @@ export default domAssigned(class ProcedureCall {
|
|
|
23
23
|
return this.reference;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
return this.
|
|
26
|
+
getExpressions() {
|
|
27
|
+
return this.expressions;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
evaluate(context) {
|
|
@@ -43,23 +43,23 @@ export default domAssigned(class ProcedureCall {
|
|
|
43
43
|
|
|
44
44
|
const fileContext = context.getFileContext(),
|
|
45
45
|
procedure = context.findProcedureByReference(this.reference),
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
expressions = this.expressions.evaluate(context),
|
|
47
|
+
expression = procedure.call(expressions, fileContext);
|
|
48
48
|
|
|
49
49
|
context.debug(`...evaluated the '${procedureCallString}' procedure call.`);
|
|
50
50
|
|
|
51
|
-
return
|
|
51
|
+
return expression;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
static name = "ProcedureCall";
|
|
55
55
|
|
|
56
|
-
static
|
|
56
|
+
static fromExpressionNode(expressionNode, context) {
|
|
57
57
|
let procedureCall = null;
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const expressionProcedureCallNode = expressionProcedureCallNodeQuery(expressionNode);
|
|
60
60
|
|
|
61
|
-
if (
|
|
62
|
-
const procedureCallNode =
|
|
61
|
+
if (expressionProcedureCallNode !== null) {
|
|
62
|
+
const procedureCallNode = expressionProcedureCallNode; ///
|
|
63
63
|
|
|
64
64
|
procedureCall = procedureCallFromProcedureCallNode(procedureCallNode, context);
|
|
65
65
|
}
|
|
@@ -69,19 +69,19 @@ export default domAssigned(class ProcedureCall {
|
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
function procedureCallFromProcedureCallNode(procedureCallNode, context) {
|
|
72
|
-
const {
|
|
72
|
+
const { Reference, Expressions, ProcedureCall } = dom,
|
|
73
73
|
reference = Reference.fromProcedureCallNode(procedureCallNode, context),
|
|
74
|
-
|
|
75
|
-
string =
|
|
76
|
-
procedureCall = new ProcedureCall(string, reference,
|
|
74
|
+
expressions = Expressions.fromProcedureCallNode(procedureCallNode, context),
|
|
75
|
+
string = stringFromExpressionsAndReference(expressions, reference, context),
|
|
76
|
+
procedureCall = new ProcedureCall(string, reference, expressions);
|
|
77
77
|
|
|
78
78
|
return procedureCall;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
function
|
|
82
|
-
const
|
|
81
|
+
function stringFromExpressionsAndReference(expressions, reference, context) {
|
|
82
|
+
const expressionsString = expressions.getString(),
|
|
83
83
|
referenceString = reference.getString(),
|
|
84
|
-
string = `${referenceString}(${
|
|
84
|
+
string = `${referenceString}(${expressionsString})`;
|
|
85
85
|
|
|
86
86
|
return string;
|
|
87
87
|
}
|
package/src/dom/query/node.js
CHANGED
|
@@ -14,7 +14,7 @@ import { domAssigned } from "../../dom";
|
|
|
14
14
|
const { first } = arrayUtilities,
|
|
15
15
|
{ trimDoubleQuotes } = contentUtilities;
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const expressionNodeQueryNodeQuery = nodeQuery("/expression/nodeQuery"),
|
|
18
18
|
stringLiteralTerminalNodeQuery = nodeQuery("/nodeQuery/@string-literal");
|
|
19
19
|
|
|
20
20
|
export default domAssigned(class NodeQuery {
|
|
@@ -37,7 +37,7 @@ export default domAssigned(class NodeQuery {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
evaluate(context) {
|
|
40
|
-
let
|
|
40
|
+
let expression;
|
|
41
41
|
|
|
42
42
|
const nodeQueryString = this.string; ///
|
|
43
43
|
|
|
@@ -50,23 +50,23 @@ export default domAssigned(class NodeQuery {
|
|
|
50
50
|
throw exception;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
expression = this.variable.evaluate(context);
|
|
54
54
|
|
|
55
|
-
const
|
|
55
|
+
const expressionType = expression.getType();
|
|
56
56
|
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
59
|
-
message = `The ${
|
|
57
|
+
if (expressionType !== NODE_TYPE) {
|
|
58
|
+
const expressionString = expression.asString(context),
|
|
59
|
+
message = `The ${expressionString} expression's '${expressionType}' type should be '${NODE_TYPE}'.`,
|
|
60
60
|
exception = Exception.fromMessage(message);
|
|
61
61
|
|
|
62
62
|
throw exception;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
const
|
|
65
|
+
const expressionNode = expression.getNode();
|
|
66
66
|
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
69
|
-
message = `The ${
|
|
67
|
+
if (expressionNode === null) {
|
|
68
|
+
const expressionString = expression.asString(context),
|
|
69
|
+
message = `The ${expressionString} expression's node is null.`,
|
|
70
70
|
exception = Exception.fromMessage(message);
|
|
71
71
|
|
|
72
72
|
throw exception;
|
|
@@ -74,7 +74,7 @@ export default domAssigned(class NodeQuery {
|
|
|
74
74
|
|
|
75
75
|
let node;
|
|
76
76
|
|
|
77
|
-
node =
|
|
77
|
+
node = expressionNode; ///
|
|
78
78
|
|
|
79
79
|
const nodes = this.query.execute(node),
|
|
80
80
|
nodesLength = nodes.length;
|
|
@@ -90,24 +90,24 @@ export default domAssigned(class NodeQuery {
|
|
|
90
90
|
|
|
91
91
|
node = firstNode; ///
|
|
92
92
|
|
|
93
|
-
const {
|
|
93
|
+
const { Expression } = dom;
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
expression = Expression.fromNode(node, context);
|
|
96
96
|
|
|
97
97
|
context.debug(`...evaluated the '${nodeQueryString}' node query.`);
|
|
98
98
|
|
|
99
|
-
return
|
|
99
|
+
return expression;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
static name = "NodeQuery";
|
|
103
103
|
|
|
104
|
-
static
|
|
104
|
+
static fromExpressionNode(expressionNode, context) {
|
|
105
105
|
let nodeQuery = null;
|
|
106
106
|
|
|
107
|
-
const
|
|
107
|
+
const expressionNodeQueryNode = expressionNodeQueryNodeQuery(expressionNode);
|
|
108
108
|
|
|
109
|
-
if (
|
|
110
|
-
const nodeQueryNode =
|
|
109
|
+
if (expressionNodeQueryNode !== null) {
|
|
110
|
+
const nodeQueryNode = expressionNodeQueryNode; ///
|
|
111
111
|
|
|
112
112
|
nodeQuery = nodeQueryFromNodeQueryNode(nodeQueryNode, context);
|
|
113
113
|
}
|
package/src/dom/query/nodes.js
CHANGED
|
@@ -12,7 +12,7 @@ import { domAssigned } from "../../dom";
|
|
|
12
12
|
|
|
13
13
|
const { trimDoubleQuotes } = contentUtilities;
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const expressionNodesQueryNodeQuery = nodeQuery("/expression/nodesQuery"),
|
|
16
16
|
stringLiteralTerminalNodesQuery = nodeQuery("/nodesQuery/@string-literal");
|
|
17
17
|
|
|
18
18
|
export default domAssigned(class NodesQuery {
|
|
@@ -35,7 +35,7 @@ export default domAssigned(class NodesQuery {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
evaluate(context) {
|
|
38
|
-
let
|
|
38
|
+
let expression;
|
|
39
39
|
|
|
40
40
|
const nodesQueryString = this.string; ///
|
|
41
41
|
|
|
@@ -48,23 +48,23 @@ export default domAssigned(class NodesQuery {
|
|
|
48
48
|
throw exception;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
expression = this.variable.evaluate(context);
|
|
52
52
|
|
|
53
|
-
const
|
|
53
|
+
const expressionType = expression.getType();
|
|
54
54
|
|
|
55
|
-
if (
|
|
56
|
-
const
|
|
57
|
-
message = `The ${
|
|
55
|
+
if (expressionType !== NODE_TYPE) {
|
|
56
|
+
const expressionString = expression.asString(context),
|
|
57
|
+
message = `The ${expressionString} expression's '${expressionType}' type should be '${NODE_TYPE}'.`,
|
|
58
58
|
exception = Exception.fromMessage(message);
|
|
59
59
|
|
|
60
60
|
throw exception;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const
|
|
63
|
+
const expressionNode = expression.getNode();
|
|
64
64
|
|
|
65
|
-
if (
|
|
66
|
-
const
|
|
67
|
-
message = `The ${
|
|
65
|
+
if (expressionNode === null) {
|
|
66
|
+
const expressionString = expression.asString(context),
|
|
67
|
+
message = `The ${expressionString} expression's node is null.`,
|
|
68
68
|
exception = Exception.fromMessage(message);
|
|
69
69
|
|
|
70
70
|
throw exception;
|
|
@@ -72,28 +72,28 @@ export default domAssigned(class NodesQuery {
|
|
|
72
72
|
|
|
73
73
|
let node;
|
|
74
74
|
|
|
75
|
-
node =
|
|
75
|
+
node = expressionNode; ///
|
|
76
76
|
|
|
77
77
|
const nodes = this.query.execute(node);
|
|
78
78
|
|
|
79
|
-
const {
|
|
79
|
+
const { Expression } = dom;
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
expression = Expression.fromNodes(nodes, context);
|
|
82
82
|
|
|
83
83
|
context.debug(`...evaluated the '${nodesQueryString}' nodes query.`);
|
|
84
84
|
|
|
85
|
-
return
|
|
85
|
+
return expression;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
static name = "NodesQuery";
|
|
89
89
|
|
|
90
|
-
static
|
|
90
|
+
static fromExpressionNode(expressionNode, context) {
|
|
91
91
|
let nodesQuery = null;
|
|
92
92
|
|
|
93
|
-
const
|
|
93
|
+
const expressionNodesQueryNode = expressionNodesQueryNodeQuery(expressionNode);
|
|
94
94
|
|
|
95
|
-
if (
|
|
96
|
-
const nodesQueryNode =
|
|
95
|
+
if (expressionNodesQueryNode !== null) {
|
|
96
|
+
const nodesQueryNode = expressionNodesQueryNode; ///
|
|
97
97
|
|
|
98
98
|
nodesQuery = nodesQueryFromNodesQueryNode(nodesQueryNode, context);
|
|
99
99
|
}
|
package/src/dom/reduce.js
CHANGED
|
@@ -7,13 +7,13 @@ import { nodeQuery } from "../utilities/query";
|
|
|
7
7
|
import { NODES_TYPE } from "../types";
|
|
8
8
|
import { domAssigned } from "../dom";
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const expressionReduceNodeQuery = nodeQuery("/expression/reduce");
|
|
11
11
|
|
|
12
12
|
export default domAssigned(class Reduce {
|
|
13
|
-
constructor(string, variable,
|
|
13
|
+
constructor(string, variable, initialExpression, anonymousProcedure) {
|
|
14
14
|
this.string = string;
|
|
15
15
|
this.variable = variable;
|
|
16
|
-
this.
|
|
16
|
+
this.initialExpression = initialExpression;
|
|
17
17
|
this.anonymousProcedure = anonymousProcedure;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -25,8 +25,8 @@ export default domAssigned(class Reduce {
|
|
|
25
25
|
return this.variable;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
return this.
|
|
28
|
+
getInitialExpression() {
|
|
29
|
+
return this.initialExpression;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
getAnonymousProcedure() {
|
|
@@ -34,59 +34,59 @@ export default domAssigned(class Reduce {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
evaluate(context) {
|
|
37
|
-
let
|
|
37
|
+
let expression;
|
|
38
38
|
|
|
39
39
|
const reduceString = this.getString();
|
|
40
40
|
|
|
41
41
|
context.trace(`Evaluating the '${reduceString}' reduce...`);
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
expression = this.variable.evaluate(context);
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const expressionType = expression.getType();
|
|
46
46
|
|
|
47
|
-
if (
|
|
48
|
-
const
|
|
49
|
-
message = `The ${
|
|
47
|
+
if (expressionType !== NODES_TYPE) {
|
|
48
|
+
const expressionString = expression.asString(context),
|
|
49
|
+
message = `The ${expressionString} expression's '${expressionType}' type should be '${NODES_TYPE}'.`,
|
|
50
50
|
exception = Exception.fromMessage(message);
|
|
51
51
|
|
|
52
52
|
throw exception;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const nodes =
|
|
56
|
-
|
|
55
|
+
const nodes = expression.getNodes(),
|
|
56
|
+
initialExpression = this.initialExpression.evaluate(context);
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
let
|
|
58
|
+
expression = nodes.reduce((currentExpression, node) => {
|
|
59
|
+
let expression;
|
|
60
60
|
|
|
61
|
-
const {
|
|
61
|
+
const { Expression, Expressions } = dom;
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
expression = currentExpression; ///
|
|
64
64
|
|
|
65
|
-
const
|
|
65
|
+
const expressions = Expressions.fromExpression(expression, context);
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
expression = Expression.fromNode(node, context);
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
expressions.addExpression(expression);
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
expression = this.anonymousProcedure.call(expressions, context);
|
|
72
72
|
|
|
73
|
-
return
|
|
74
|
-
},
|
|
73
|
+
return expression;
|
|
74
|
+
}, initialExpression);
|
|
75
75
|
|
|
76
76
|
context.trace(`...evaluated the '${reduceString}' reduce.`);
|
|
77
77
|
|
|
78
|
-
return
|
|
78
|
+
return expression;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
static name = "Reduce";
|
|
82
82
|
|
|
83
|
-
static
|
|
83
|
+
static fromExpressionNode(expressionNode, context) {
|
|
84
84
|
let reduce = null;
|
|
85
85
|
|
|
86
|
-
const
|
|
86
|
+
const expressionReduceNode = expressionReduceNodeQuery(expressionNode);
|
|
87
87
|
|
|
88
|
-
if (
|
|
89
|
-
const reduceNode =
|
|
88
|
+
if (expressionReduceNode !== null) {
|
|
89
|
+
const reduceNode = expressionReduceNode; ///
|
|
90
90
|
|
|
91
91
|
reduce = reduceFromReduceNode(reduceNode, context);
|
|
92
92
|
}
|
|
@@ -96,22 +96,22 @@ export default domAssigned(class Reduce {
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
function reduceFromReduceNode(reduceNode, context) {
|
|
99
|
-
const {
|
|
100
|
-
|
|
99
|
+
const { Reduce, Variable, Expression, AnonymousProcedure } = dom,
|
|
100
|
+
expression = Expression.fromReduceNode(reduceNode, context),
|
|
101
101
|
variable = Variable.fromReduceNode(reduceNode, context),
|
|
102
|
-
|
|
102
|
+
initialExpression = expression, ///
|
|
103
103
|
anonymousProcedure = AnonymousProcedure.fromReduceNode(reduceNode, context),
|
|
104
|
-
string =
|
|
105
|
-
reduce = new Reduce(string, variable,
|
|
104
|
+
string = stringFromVariableInitialExpressionAndAnonymousProcedure(variable, initialExpression, anonymousProcedure),
|
|
105
|
+
reduce = new Reduce(string, variable, initialExpression, anonymousProcedure);
|
|
106
106
|
|
|
107
107
|
return reduce;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
function
|
|
110
|
+
function stringFromVariableInitialExpressionAndAnonymousProcedure(variable, initialExpression, anonymousProcedure) {
|
|
111
111
|
const variableString = variable.getString(),
|
|
112
|
-
|
|
112
|
+
initialExpressionString = initialExpression.getString(),
|
|
113
113
|
anonymousProcedureString = anonymousProcedure.getString(),
|
|
114
|
-
string = `Reduce(${variableString}, ${anonymousProcedureString}, ${
|
|
114
|
+
string = `Reduce(${variableString}, ${anonymousProcedureString}, ${initialExpressionString})`;
|
|
115
115
|
|
|
116
116
|
return string;
|
|
117
117
|
}
|