occam-furtle 2.0.80 → 2.0.86
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/constants.js +9 -1
- package/lib/dom/assignment/array.js +6 -2
- package/lib/dom/assignment/object.js +6 -2
- package/lib/dom/assignment/variable.js +6 -2
- package/lib/dom/assignments/variable.js +10 -2
- package/lib/dom/block/return.js +8 -4
- package/lib/dom/comparison.js +7 -3
- package/lib/dom/declaration/procedure.js +6 -2
- package/lib/dom/every.js +5 -5
- package/lib/dom/label.js +6 -2
- package/lib/dom/parameter/named.js +12 -2
- package/lib/dom/parameter.js +6 -2
- package/lib/dom/parameters/named.js +10 -2
- package/lib/dom/parameters.js +4 -12
- package/lib/dom/procedure/anonymous.js +11 -12
- package/lib/dom/procedure.js +4 -4
- package/lib/dom/procedureCall.js +6 -2
- package/lib/dom/reduce.js +34 -32
- package/lib/dom/reference.js +6 -2
- package/lib/dom/some.js +4 -4
- package/lib/dom/statement/return.js +6 -2
- package/lib/dom/step.js +8 -12
- package/lib/dom/ternary.js +5 -7
- package/lib/dom/value/bitwise.js +7 -3
- package/lib/dom/value/bracketed.js +6 -2
- package/lib/dom/value/negated.js +6 -2
- package/lib/dom/value.js +34 -47
- package/lib/dom/values.js +8 -9
- package/lib/dom/variable.js +18 -14
- package/lib/index.js +1 -4
- package/lib/nodeProperties.js +10 -3
- package/lib/nodeProperty.js +3 -3
- package/package.json +5 -5
- package/src/constants.js +2 -0
- package/src/dom/assignment/array.js +10 -3
- package/src/dom/assignment/object.js +10 -3
- package/src/dom/assignment/variable.js +9 -2
- package/src/dom/assignments/variable.js +18 -4
- package/src/dom/block/return.js +12 -6
- package/src/dom/comparison.js +15 -5
- package/src/dom/declaration/procedure.js +8 -2
- package/src/dom/every.js +8 -12
- package/src/dom/label.js +9 -3
- package/src/dom/parameter/named.js +19 -2
- package/src/dom/parameter.js +9 -2
- package/src/dom/parameters/named.js +16 -2
- package/src/dom/parameters.js +1 -1
- package/src/dom/procedure/anonymous.js +19 -23
- package/src/dom/procedure.js +7 -10
- package/src/dom/procedureCall.js +10 -2
- package/src/dom/reduce.js +44 -47
- package/src/dom/reference.js +8 -2
- package/src/dom/some.js +7 -9
- package/src/dom/statement/return.js +8 -2
- package/src/dom/step.js +11 -13
- package/src/dom/ternary.js +8 -15
- package/src/dom/value/bitwise.js +14 -4
- package/src/dom/value/bracketed.js +9 -3
- package/src/dom/value/negated.js +9 -3
- package/src/dom/value.js +36 -52
- package/src/dom/values.js +5 -10
- package/src/dom/variable.js +21 -17
- package/src/index.js +0 -3
- package/src/nodeProperties.js +15 -1
- package/src/nodeProperty.js +4 -2
- package/lib/dom/block.js +0 -150
- package/lib/dom/conditionalBlocks.js +0 -176
- package/lib/dom/procedureCall/anonymous.js +0 -141
- package/src/dom/block.js +0 -68
- package/src/dom/conditionalBlocks.js +0 -106
- package/src/dom/procedureCall/anonymous.js +0 -61
|
@@ -80,14 +80,31 @@ export default domAssigned(class NamedParameter {
|
|
|
80
80
|
const type = typeFromNamedParameterNode(namedParameterNode, context),
|
|
81
81
|
name = nameFromNamedParameterNode(namedParameterNode, context),
|
|
82
82
|
asName = asNameFromNamedParameterNode(namedParameterNode, context),
|
|
83
|
-
|
|
84
|
-
string = context.nodeAsString(node),
|
|
83
|
+
string = stringFromTypeNameAndAsName(type, name, asName, context),
|
|
85
84
|
namedParameter = new NamedParameter(string, type, name, asName);
|
|
86
85
|
|
|
87
86
|
return namedParameter;
|
|
88
87
|
}
|
|
89
88
|
});
|
|
90
89
|
|
|
90
|
+
function stringFromTypeNameAndAsName(type, name, asName, context) {
|
|
91
|
+
let string;
|
|
92
|
+
|
|
93
|
+
const typeString = type, ///
|
|
94
|
+
nameString = name; ///
|
|
95
|
+
|
|
96
|
+
string = `${typeString} ${nameString}`;
|
|
97
|
+
|
|
98
|
+
if (asName !== null) {
|
|
99
|
+
const asNameString = asName; ///
|
|
100
|
+
|
|
101
|
+
string = `${string} As ${asNameString}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
91
108
|
function typeFromNamedParameterNode(namedParameterNode, context) {
|
|
92
109
|
const typeTerminalNode = typeTerminalNodeQuery(namedParameterNode),
|
|
93
110
|
typeTerminalNodeContent = typeTerminalNode.getContent(),
|
package/src/dom/parameter.js
CHANGED
|
@@ -57,8 +57,7 @@ export default domAssigned(class Parameter {
|
|
|
57
57
|
if (terminalNodesLength === 2) {
|
|
58
58
|
const name = nameFromParameterNode(parameterNode, context),
|
|
59
59
|
type = typeFromParameterNode(parameterNode, context),
|
|
60
|
-
|
|
61
|
-
string = context.nodeAsString(node);
|
|
60
|
+
string = stringFromNameAndType(name, type, context);
|
|
62
61
|
|
|
63
62
|
parameter = new Parameter(string, type, name);
|
|
64
63
|
}
|
|
@@ -67,6 +66,14 @@ export default domAssigned(class Parameter {
|
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
68
|
|
|
69
|
+
function stringFromNameAndType(name, type, context) {
|
|
70
|
+
const nameString = name, ///
|
|
71
|
+
typeString = type, ///
|
|
72
|
+
string = `${typeString} ${nameString}`;
|
|
73
|
+
|
|
74
|
+
return string;
|
|
75
|
+
}
|
|
76
|
+
|
|
70
77
|
function nameFromParameterNode(parameterNode, context) {
|
|
71
78
|
const nameTerminalNode = nameTerminalNodeQuery(parameterNode),
|
|
72
79
|
nameTerminalNodeContent = nameTerminalNode.getContent(),
|
|
@@ -107,16 +107,30 @@ export default domAssigned(class NamedParameters {
|
|
|
107
107
|
static fromObjectAssignmentNode(objectAssignmentNode, context) {
|
|
108
108
|
const objectAssignmentNamedParametersNode = objectAssignmentNamedParametersNodeQuery(objectAssignmentNode),
|
|
109
109
|
parametersNode = objectAssignmentNamedParametersNode, ///
|
|
110
|
-
node = parametersNode, ///
|
|
111
|
-
string = context.nodeAsString(node),
|
|
112
110
|
namedParameterNodes = namedParameterNodesQuery(parametersNode),
|
|
113
111
|
array = arrayFromNamedParameterNodes(namedParameterNodes, context),
|
|
112
|
+
string = stringFromArray(array, context),
|
|
114
113
|
namedParameters = new NamedParameters(string, array);
|
|
115
114
|
|
|
116
115
|
return namedParameters;
|
|
117
116
|
}
|
|
118
117
|
});
|
|
119
118
|
|
|
119
|
+
function stringFromArray(array, context) {
|
|
120
|
+
const namedParametersSString = array.reduce((namedParametersSString, namedParameter) => {
|
|
121
|
+
const namedParameterString = namedParameter.getString();
|
|
122
|
+
|
|
123
|
+
namedParametersSString = (namedParametersSString === null) ?
|
|
124
|
+
namedParameterString :
|
|
125
|
+
`${namedParametersSString}, ${namedParameterString}`;
|
|
126
|
+
|
|
127
|
+
return namedParametersSString;
|
|
128
|
+
}, null),
|
|
129
|
+
string = namedParametersSString; ///
|
|
130
|
+
|
|
131
|
+
return string;
|
|
132
|
+
}
|
|
133
|
+
|
|
120
134
|
function arrayFromNamedParameterNodes(namedParameterNodes, context) {
|
|
121
135
|
const { NamedParameter } = dom,
|
|
122
136
|
array = namedParameterNodes.map((namedParameterNode) => { ///
|
package/src/dom/parameters.js
CHANGED
|
@@ -121,7 +121,7 @@ export default domAssigned(class Parameters {
|
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
function stringFromArray(array, context) {
|
|
125
125
|
const parametersString = array.reduce((parametersString, parameter) => {
|
|
126
126
|
const parameterString = parameter.getString();
|
|
127
127
|
|
|
@@ -7,11 +7,10 @@ import { nodeQuery } from "../../utilities/query";
|
|
|
7
7
|
import { domAssigned } from "../../dom";
|
|
8
8
|
import { variablesFromValuesAndParameters } from "../procedure";
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
typeTerminalNodeQuery = nodeQuery("/anonymousProcedure/@type"),
|
|
10
|
+
const typeTerminalNodeQuery = nodeQuery("/anonymousProcedure/@type"),
|
|
12
11
|
someAnonymousProcedureNodeQuery = nodeQuery("/some/anonymousProcedure"),
|
|
13
12
|
everyAnonymousProcedureNodeQuery = nodeQuery("/every/anonymousProcedure"),
|
|
14
|
-
|
|
13
|
+
reduceAnonymousProcedureNodeQuery = nodeQuery("/reduce/anonymousProcedure");
|
|
15
14
|
|
|
16
15
|
export default domAssigned(class AnonymousProcedure {
|
|
17
16
|
constructor(string, type, parameters, returnBlock) {
|
|
@@ -44,9 +43,8 @@ export default domAssigned(class AnonymousProcedure {
|
|
|
44
43
|
|
|
45
44
|
this.parameters.matchValues(values, context);
|
|
46
45
|
|
|
47
|
-
const variables = variablesFromValuesAndParameters(values, this.parameters, context)
|
|
48
|
-
|
|
49
|
-
const value = this.returnBlock.evaluate(variables, context),
|
|
46
|
+
const variables = variablesFromValuesAndParameters(values, this.parameters, context),
|
|
47
|
+
value = this.returnBlock.evaluate(variables, context),
|
|
50
48
|
valueType = value.getType();
|
|
51
49
|
|
|
52
50
|
if (this.type !== valueType) {
|
|
@@ -80,9 +78,9 @@ export default domAssigned(class AnonymousProcedure {
|
|
|
80
78
|
return anonymousProcedure;
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
static
|
|
84
|
-
const
|
|
85
|
-
anonymousProcedureNode =
|
|
81
|
+
static fromReduceNode(reduceNode, context) {
|
|
82
|
+
const reduceAnonymousProcedureNode = reduceAnonymousProcedureNodeQuery(reduceNode),
|
|
83
|
+
anonymousProcedureNode = reduceAnonymousProcedureNode, ///
|
|
86
84
|
anonymousProcedure = anonymousProcedureFromAnonymousProcedureNode(anonymousProcedureNode, context);
|
|
87
85
|
|
|
88
86
|
return anonymousProcedure;
|
|
@@ -91,15 +89,24 @@ export default domAssigned(class AnonymousProcedure {
|
|
|
91
89
|
|
|
92
90
|
function anonymousProcedureFromAnonymousProcedureNode(anonymousProcedureNode, context) {
|
|
93
91
|
const { Parameters, ReturnBlock, AnonymousProcedure } = dom,
|
|
94
|
-
string = stringFromAnonymousProcedureNode(anonymousProcedureNode, context),
|
|
95
|
-
type = typeFromProcedureAnonymousProcedureNode(anonymousProcedureNode, context),
|
|
96
|
-
parameters = Parameters.fromAnonymousProcedureNode(anonymousProcedureNode, context),
|
|
97
92
|
returnBlock = ReturnBlock.fromAnonymousProcedureNode(anonymousProcedureNode, context),
|
|
93
|
+
parameters = Parameters.fromAnonymousProcedureNode(anonymousProcedureNode, context),
|
|
94
|
+
type = typeFromProcedureAnonymousProcedureNode(anonymousProcedureNode, context),
|
|
95
|
+
string = stringFromTypeParametersAndReturnBlock(type, parameters, returnBlock, context),
|
|
98
96
|
anonymousProcedure = new AnonymousProcedure(string, type, parameters, returnBlock);
|
|
99
97
|
|
|
100
98
|
return anonymousProcedure;
|
|
101
99
|
}
|
|
102
100
|
|
|
101
|
+
function stringFromTypeParametersAndReturnBlock(type, parameters, returnBlock, context) {
|
|
102
|
+
const typeString = type, ///
|
|
103
|
+
parametersString = parameters.getString(),
|
|
104
|
+
returnBlockString = returnBlock.getString(),
|
|
105
|
+
string = `${typeString} (${parametersString}) ${returnBlockString}`;
|
|
106
|
+
|
|
107
|
+
return string;
|
|
108
|
+
}
|
|
109
|
+
|
|
103
110
|
function typeFromProcedureAnonymousProcedureNode(anonymousProcedureNode, context) {
|
|
104
111
|
const typeTerminalNode = typeTerminalNodeQuery(anonymousProcedureNode),
|
|
105
112
|
typeTerminalNodeContent = typeTerminalNode.getContent(),
|
|
@@ -107,14 +114,3 @@ function typeFromProcedureAnonymousProcedureNode(anonymousProcedureNode, context
|
|
|
107
114
|
|
|
108
115
|
return type;
|
|
109
116
|
}
|
|
110
|
-
|
|
111
|
-
function stringFromAnonymousProcedureNode(anonymousProcedureNode, context) {
|
|
112
|
-
const parametersNode = parametersNodeQuery(anonymousProcedureNode),
|
|
113
|
-
typeTerminalNode = typeTerminalNodeQuery(anonymousProcedureNode),
|
|
114
|
-
parametersString = context.nodeAsString(parametersNode),
|
|
115
|
-
typeNode = typeTerminalNode, ///
|
|
116
|
-
typeString = context.nodeAsString(typeNode),
|
|
117
|
-
string = `${typeString} (${parametersString}) { ... }`;
|
|
118
|
-
|
|
119
|
-
return string;
|
|
120
|
-
}
|
package/src/dom/procedure.js
CHANGED
|
@@ -83,11 +83,11 @@ export default domAssigned(class Procedure {
|
|
|
83
83
|
|
|
84
84
|
static fromProcedureDeclarationNode(procedureDeclarationNode, context) {
|
|
85
85
|
const { Label, ReturnBlock, Parameters } = dom,
|
|
86
|
-
string = stringFromProcedureDeclarationNode(procedureDeclarationNode, context),
|
|
87
86
|
type = typeFromProcedureDeclarationNode(procedureDeclarationNode, context),
|
|
88
87
|
label = Label.fromProcedureDeclarationNode(procedureDeclarationNode, context),
|
|
89
88
|
parameters = Parameters.fromProcedureDeclarationNode(procedureDeclarationNode, context),
|
|
90
89
|
returnBlock = ReturnBlock.fromProcedureDeclarationNode(procedureDeclarationNode, context),
|
|
90
|
+
string = stringFromTypeLabelParametersAndReturnBlock(type, label, parameters, returnBlock),
|
|
91
91
|
procedureDeclaration = new Procedure(string, type, label, parameters, returnBlock);
|
|
92
92
|
|
|
93
93
|
return procedureDeclaration;
|
|
@@ -119,15 +119,12 @@ function typeFromProcedureDeclarationNode(procedureDeclarationNode, context) {
|
|
|
119
119
|
return type;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
labelString = context.nodeAsString(labelNode),
|
|
129
|
-
parametersString = context.nodeAsString(parametersNode),
|
|
130
|
-
string = `${typeString} ${labelString}(${parametersString}) { ... }`;
|
|
122
|
+
function stringFromTypeLabelParametersAndReturnBlock(type, label, parameters, returnBlock) {
|
|
123
|
+
const typeString = type, ///
|
|
124
|
+
labelString = label.getString(),
|
|
125
|
+
parametersString = parameters.getString(),
|
|
126
|
+
returnBlockString = returnBlock.getString(),
|
|
127
|
+
string = `${typeString} ${labelString}(${parametersString}) ${returnBlockString}`;
|
|
131
128
|
|
|
132
129
|
return string;
|
|
133
130
|
}
|
package/src/dom/procedureCall.js
CHANGED
|
@@ -61,9 +61,9 @@ export default domAssigned(class ProcedureCall {
|
|
|
61
61
|
if (procedureCallNode !== null) {
|
|
62
62
|
const { Values, Reference } = dom,
|
|
63
63
|
node = procedureCallNode, ///
|
|
64
|
-
string = context.nodeAsString(node),
|
|
65
64
|
reference = Reference.fromValueNode(valueNode, context),
|
|
66
|
-
values = Values.fromValueNode(valueNode, context)
|
|
65
|
+
values = Values.fromValueNode(valueNode, context),
|
|
66
|
+
string = stringFromValuesAndReference(values, reference, context);
|
|
67
67
|
|
|
68
68
|
procedureCall = new ProcedureCall(string, reference, values);
|
|
69
69
|
}
|
|
@@ -71,3 +71,11 @@ export default domAssigned(class ProcedureCall {
|
|
|
71
71
|
return procedureCall;
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
|
+
|
|
75
|
+
function stringFromValuesAndReference(values, reference, context) {
|
|
76
|
+
const valuesString = values.getString(),
|
|
77
|
+
referenceString = reference.getString(),
|
|
78
|
+
string = `${referenceString}(${valuesString})`;
|
|
79
|
+
|
|
80
|
+
return string;
|
|
81
|
+
}
|
package/src/dom/reduce.js
CHANGED
|
@@ -7,14 +7,16 @@ import { nodeQuery } from "../utilities/query";
|
|
|
7
7
|
import { domAssigned } from "../dom";
|
|
8
8
|
import { NODES_TYPE, BOOLEAN_TYPE } from "../types";
|
|
9
9
|
|
|
10
|
-
const variableNodeQuery = nodeQuery("/
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const variableNodeQuery = nodeQuery("/reduce/variable"),
|
|
11
|
+
parametersNodeQuery = nodeQuery("/reduce/anonymousProcedure/parameters"),
|
|
12
|
+
valueReduceNodeQuery = nodeQuery("/value/reduce"),
|
|
13
|
+
initialValueNodeQuery = nodeQuery("/reduce/value"); ///
|
|
13
14
|
|
|
14
|
-
export default domAssigned(class
|
|
15
|
-
constructor(string, variable, anonymousProcedure) {
|
|
15
|
+
export default domAssigned(class Reduce {
|
|
16
|
+
constructor(string, variable, initialValue, anonymousProcedure) {
|
|
16
17
|
this.string = string;
|
|
17
18
|
this.variable = variable;
|
|
19
|
+
this.initialValue = initialValue;
|
|
18
20
|
this.anonymousProcedure = anonymousProcedure;
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -26,6 +28,10 @@ export default domAssigned(class Some {
|
|
|
26
28
|
return this.variable;
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
getInitialValue() {
|
|
32
|
+
return this.initialValue;
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
getAnonymousProcedure() {
|
|
30
36
|
return this.anonymousProcedure;
|
|
31
37
|
}
|
|
@@ -33,9 +39,9 @@ export default domAssigned(class Some {
|
|
|
33
39
|
evaluate(context) {
|
|
34
40
|
let value;
|
|
35
41
|
|
|
36
|
-
const
|
|
42
|
+
const reduceString = this.getString();
|
|
37
43
|
|
|
38
|
-
context.trace(`Evaluating the '${
|
|
44
|
+
context.trace(`Evaluating the '${reduceString}' reduce...`);
|
|
39
45
|
|
|
40
46
|
value = this.variable.evaluate(context);
|
|
41
47
|
|
|
@@ -50,68 +56,59 @@ export default domAssigned(class Some {
|
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
const nodes = value.getNodes(),
|
|
53
|
-
|
|
54
|
-
let value;
|
|
55
|
-
|
|
56
|
-
const { Value, Values } = dom;
|
|
57
|
-
|
|
58
|
-
value = Value.fromNode(node, context);
|
|
59
|
-
|
|
60
|
-
const values = Values.fromValue(value, context);
|
|
59
|
+
initialValue = this.initialValue.evaluate(context);
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
value = nodes.reduce((currentValue, node) => {
|
|
62
|
+
let value;
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
const { Value, Values } = dom;
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
const valueString = value.asString(context),
|
|
68
|
-
message = `The ${valueString} value's type is '${valueType}' when it should be of type '${BOOLEAN_TYPE}'.`,
|
|
69
|
-
exception = Exception.fromMessage(message);
|
|
66
|
+
value = currentValue; ///
|
|
70
67
|
|
|
71
|
-
|
|
72
|
-
}
|
|
68
|
+
const values = Values.fromValue(value, context);
|
|
73
69
|
|
|
74
|
-
|
|
70
|
+
value = Value.fromNode(node, context);
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
});
|
|
72
|
+
values.addValue(value);
|
|
78
73
|
|
|
79
|
-
|
|
74
|
+
value = this.anonymousProcedure.call(values, context);
|
|
80
75
|
|
|
81
|
-
|
|
76
|
+
return value;
|
|
77
|
+
}, initialValue);
|
|
82
78
|
|
|
83
|
-
context.trace(`...evaluated the '${
|
|
79
|
+
context.trace(`...evaluated the '${reduceString}' reduce.`);
|
|
84
80
|
|
|
85
81
|
return value;
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
static name = "
|
|
84
|
+
static name = "Reduce";
|
|
89
85
|
|
|
90
86
|
static fromValueNode(valueNode, context) {
|
|
91
|
-
let
|
|
87
|
+
let reduce = null;
|
|
92
88
|
|
|
93
|
-
const
|
|
89
|
+
const valueReduceNode = valueReduceNodeQuery(valueNode);
|
|
94
90
|
|
|
95
|
-
if (
|
|
96
|
-
const { Variable, AnonymousProcedure } = dom,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
variable = Variable.
|
|
100
|
-
|
|
91
|
+
if (valueReduceNode !== null) {
|
|
92
|
+
const { Value, Variable, AnonymousProcedure } = dom,
|
|
93
|
+
reduceNode = valueReduceNode, ///
|
|
94
|
+
value = Value.fromReduceNode(reduceNode, context),
|
|
95
|
+
variable = Variable.fromReduceNode(reduceNode, context),
|
|
96
|
+
initialValue = value, ///
|
|
97
|
+
anonymousProcedure = AnonymousProcedure.fromReduceNode(reduceNode, context),
|
|
98
|
+
string = stringFromVariableInitialValueAndAnonymousProcedure(variable, initialValue, anonymousProcedure);
|
|
101
99
|
|
|
102
|
-
|
|
100
|
+
reduce = new Reduce(string, variable, initialValue, anonymousProcedure);
|
|
103
101
|
}
|
|
104
102
|
|
|
105
|
-
return
|
|
103
|
+
return reduce;
|
|
106
104
|
}
|
|
107
105
|
});
|
|
108
106
|
|
|
109
|
-
function
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
string = `Some(${variableString}, (${parametersString}) { ... })`;
|
|
107
|
+
function stringFromVariableInitialValueAndAnonymousProcedure(variable, initialValue, anonymousProcedure) {
|
|
108
|
+
const variableString = variable.getString(),
|
|
109
|
+
initialValueString = initialValue.getString(),
|
|
110
|
+
anonymousProcedureString = anonymousProcedure.getString(),
|
|
111
|
+
string = `Reduce(${variableString}, ${anonymousProcedureString}, ${initialValueString})`;
|
|
115
112
|
|
|
116
113
|
return string;
|
|
117
|
-
}
|
|
114
|
+
}
|
package/src/dom/reference.js
CHANGED
|
@@ -34,15 +34,21 @@ export default domAssigned(class Reference {
|
|
|
34
34
|
static fromValueNode(valueNode, context) {
|
|
35
35
|
const valueProcedureCallReferenceNod = valueProcedureCallReferenceNodeQuery(valueNode),
|
|
36
36
|
referenceNode = valueProcedureCallReferenceNod,
|
|
37
|
-
node = referenceNode, ///
|
|
38
|
-
string = context.nodeAsString(node),
|
|
39
37
|
name = nameFromReferenceNode(referenceNode, context),
|
|
38
|
+
string = stringFromName(name, context),
|
|
40
39
|
reference = new Reference(string, name);
|
|
41
40
|
|
|
42
41
|
return reference;
|
|
43
42
|
}
|
|
44
43
|
});
|
|
45
44
|
|
|
45
|
+
function stringFromName(name, context) {
|
|
46
|
+
const nameString = name, ///
|
|
47
|
+
string = nameString; ///
|
|
48
|
+
|
|
49
|
+
return string;
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
function nameFromReferenceNode(referenceNode, context) {
|
|
47
53
|
const referenceNameTerminalNode = referenceNameTerminalNodeQuery(referenceNode),
|
|
48
54
|
referenceNameTerminalNodeContent = referenceNameTerminalNode.getContent(),
|
package/src/dom/some.js
CHANGED
|
@@ -95,9 +95,9 @@ export default domAssigned(class Some {
|
|
|
95
95
|
if (valueSomeNode !== null) {
|
|
96
96
|
const { Variable, AnonymousProcedure } = dom,
|
|
97
97
|
someNode = valueSomeNode, ///
|
|
98
|
-
|
|
98
|
+
anonymousProcedure = AnonymousProcedure.fromSomeNode(someNode, context),
|
|
99
99
|
variable = Variable.fromSomeNode(someNode, context),
|
|
100
|
-
|
|
100
|
+
string = stringFromVariableAndAnonymousProcedure(variable, anonymousProcedure, context);
|
|
101
101
|
|
|
102
102
|
some = new Some(string, variable, anonymousProcedure);
|
|
103
103
|
}
|
|
@@ -106,12 +106,10 @@ export default domAssigned(class Some {
|
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
-
function
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
parametersString = context.nodeAsString(parametersNode),
|
|
114
|
-
string = `Some(${variableString}, (${parametersString}) { ... })`;
|
|
109
|
+
function stringFromVariableAndAnonymousProcedure(variable, anonymousProcedure, context) {
|
|
110
|
+
const variableString = variable.getString(),
|
|
111
|
+
anonymousProcedureString = anonymousProcedure.getString(),
|
|
112
|
+
string = `Some(${variableString}, ${anonymousProcedureString}) `;
|
|
115
113
|
|
|
116
114
|
return string;
|
|
117
|
-
}
|
|
115
|
+
}
|
|
@@ -40,11 +40,17 @@ export default domAssigned(class ReturnStatement {
|
|
|
40
40
|
static fromReturnBlockNode(returnBlockNode, context) {
|
|
41
41
|
const { Value } = dom,
|
|
42
42
|
returnStatementNode = returnStatementNodeQuery(returnBlockNode),
|
|
43
|
-
node = returnStatementNode, ///
|
|
44
|
-
string = context.nodeAsString(node),
|
|
45
43
|
value = Value.fromReturnStatementNode(returnStatementNode, context),
|
|
44
|
+
string = stringFromValue(value, context),
|
|
46
45
|
returnStatement = new ReturnStatement(string, value);
|
|
47
46
|
|
|
48
47
|
return returnStatement;
|
|
49
48
|
}
|
|
50
49
|
});
|
|
50
|
+
|
|
51
|
+
function stringFromValue(value, context) {
|
|
52
|
+
const valueString = value.asString(context),
|
|
53
|
+
string = `Return ${valueString};`;
|
|
54
|
+
|
|
55
|
+
return string;
|
|
56
|
+
}
|
package/src/dom/step.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
import dom from "../dom";
|
|
4
4
|
|
|
5
5
|
import { domAssigned } from "../dom";
|
|
6
|
+
import { EMPTY_STRING } from "../constants";
|
|
6
7
|
|
|
7
8
|
export default domAssigned(class Step {
|
|
8
|
-
constructor(string, arrayAssignment, objectAssigment,
|
|
9
|
+
constructor(string, arrayAssignment, objectAssigment, variablesDeclaration) {
|
|
9
10
|
this.string = string;
|
|
10
11
|
this.arrayAssignment = arrayAssignment;
|
|
11
12
|
this.objectAssigment = objectAssigment;
|
|
12
|
-
this.conditionalBlocks = conditionalBlocks;
|
|
13
13
|
this.variablesDeclaration = variablesDeclaration;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -25,10 +25,6 @@ export default domAssigned(class Step {
|
|
|
25
25
|
return this.objectAssigment;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
getConditionalBlocks() {
|
|
29
|
-
return this.conditionalBlocks;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
28
|
getVariablesDeclaration() {
|
|
33
29
|
return this.variablesDeclaration;
|
|
34
30
|
}
|
|
@@ -40,8 +36,6 @@ export default domAssigned(class Step {
|
|
|
40
36
|
this.arrayAssignment.evaluate(context);
|
|
41
37
|
} else if (this.objectAssigment !== null) {
|
|
42
38
|
this.objectAssigment.evaluate(context);
|
|
43
|
-
} else if (this.conditionalBlocks !== null) {
|
|
44
|
-
this.conditionalBlocks.evaluate(context);
|
|
45
39
|
} else if (this.variablesDeclaration !== null) {
|
|
46
40
|
this.variablesDeclaration.evaluate(context);
|
|
47
41
|
}
|
|
@@ -50,15 +44,19 @@ export default domAssigned(class Step {
|
|
|
50
44
|
static name = "Step";
|
|
51
45
|
|
|
52
46
|
static fromStepNode(stepNode, context) {
|
|
53
|
-
const { ArrayAssignment, ObjectAssigment,
|
|
54
|
-
|
|
55
|
-
string = context.nodeAsString(node),
|
|
47
|
+
const { ArrayAssignment, ObjectAssigment, VariableAssignments } = dom,
|
|
48
|
+
string = stringFromNothing(context),
|
|
56
49
|
arrayAssignment = ArrayAssignment.fromStepNode(stepNode, context),
|
|
57
50
|
objectAssigment = ObjectAssigment.fromStepNode(stepNode, context),
|
|
58
|
-
conditionalBlocks = ConditionalBlocks.fromStepNode(stepNode, context),
|
|
59
51
|
variablesDeclaration = VariableAssignments.fromStepNode(stepNode, context),
|
|
60
|
-
step = new Step(string, arrayAssignment, objectAssigment,
|
|
52
|
+
step = new Step(string, arrayAssignment, objectAssigment, variablesDeclaration);
|
|
61
53
|
|
|
62
54
|
return step;
|
|
63
55
|
}
|
|
64
56
|
});
|
|
57
|
+
|
|
58
|
+
function stringFromNothing(context) {
|
|
59
|
+
const string = EMPTY_STRING;
|
|
60
|
+
|
|
61
|
+
return string;
|
|
62
|
+
}
|
package/src/dom/ternary.js
CHANGED
|
@@ -7,8 +7,7 @@ import { nodeQuery } from "../utilities/query";
|
|
|
7
7
|
import { domAssigned } from "../dom";
|
|
8
8
|
import { BOOLEAN_TYPE } from "../types";
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
ifValueNodeQuery = nodeQuery("/ternary/value[1]"),
|
|
10
|
+
const ifValueNodeQuery = nodeQuery("/ternary/value[1]"),
|
|
12
11
|
ternaryNodeQuery = nodeQuery("/value/ternary"),
|
|
13
12
|
elseValueNodeQuery = nodeQuery("/ternary/value[2]");
|
|
14
13
|
|
|
@@ -75,12 +74,12 @@ export default domAssigned(class Ternary {
|
|
|
75
74
|
|
|
76
75
|
if (ternaryNode !== null) {
|
|
77
76
|
const { Value } = dom,
|
|
78
|
-
string = stringFromTernaryNode(ternaryNode, context),
|
|
79
77
|
ifValueNode = ifValueNodeQuery(ternaryNode),
|
|
80
78
|
elseValueNode = elseValueNodeQuery(ternaryNode),
|
|
81
79
|
value = Value.fromTernaryNode(ternaryNode, context),
|
|
82
80
|
ifValue = Value.fromValueNode(ifValueNode, context),
|
|
83
|
-
elseValue = Value.fromValueNode(elseValueNode, context)
|
|
81
|
+
elseValue = Value.fromValueNode(elseValueNode, context),
|
|
82
|
+
string = stringFromValueIfValueAndElseValue(value, ifValue, elseValue, context);
|
|
84
83
|
|
|
85
84
|
ternary = new Ternary(string, value, ifValue, elseValue);
|
|
86
85
|
}
|
|
@@ -89,17 +88,11 @@ export default domAssigned(class Ternary {
|
|
|
89
88
|
}
|
|
90
89
|
});
|
|
91
90
|
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
elseValueNode = elseValueNodeQuery(ternaryNode),
|
|
98
|
-
ifValueString = context.nodeAsString(ifValueNode),
|
|
99
|
-
elseValueString = context.nodeAsString(elseValueNode),
|
|
100
|
-
valueString = context.nodeAsString(valueNode);
|
|
101
|
-
|
|
102
|
-
string = `If (${valueString}) ${ifValueString} ${elseValueString}`;
|
|
91
|
+
function stringFromValueIfValueAndElseValue(value, ifValue, elseValue, context) {
|
|
92
|
+
const valueString = value.asString(context),
|
|
93
|
+
ifValueString = ifValue.asString(context),
|
|
94
|
+
elseValueString = elseValue.asString(context),
|
|
95
|
+
string = `If (${valueString}) ${ifValueString} Else ${elseValueString};`;
|
|
103
96
|
|
|
104
97
|
return string;
|
|
105
98
|
}
|
package/src/dom/value/bitwise.js
CHANGED
|
@@ -5,8 +5,8 @@ import Exception from "../../exception";
|
|
|
5
5
|
|
|
6
6
|
import { nodeQuery } from "../../utilities/query";
|
|
7
7
|
import { domAssigned } from "../../dom";
|
|
8
|
-
import { DISJUNCTION } from "../../constants";
|
|
9
8
|
import { BOOLEAN_TYPE } from "../../types";
|
|
9
|
+
import { CONJUNCTION, DISJUNCTION } from "../../constants";
|
|
10
10
|
|
|
11
11
|
const terminalNodeQuery = nodeQuery("/bitwiseValue/@*"),
|
|
12
12
|
leftValueNodeQuery = nodeQuery("/bitwiseValue/value[0]"),
|
|
@@ -93,14 +93,13 @@ export default domAssigned(class BitwiseValue {
|
|
|
93
93
|
|
|
94
94
|
if (bitwiseValueNode !== null) {
|
|
95
95
|
const { Value } = dom,
|
|
96
|
-
node = bitwiseValueNode, //
|
|
97
|
-
string = context.nodeAsString(node),
|
|
98
96
|
type = BOOLEAN_TYPE,
|
|
99
97
|
leftValueNode = leftValueNodeQuery(bitwiseValueNode),
|
|
100
98
|
rightValueNode = rightValueNodeQuery(bitwiseValueNode),
|
|
101
99
|
disjoint = disjointFromBitwiseValueNode(bitwiseValueNode, context),
|
|
102
100
|
leftValue = Value.fromValueNode(leftValueNode, context),
|
|
103
|
-
rightValue = Value.fromValueNode(rightValueNode, context)
|
|
101
|
+
rightValue = Value.fromValueNode(rightValueNode, context),
|
|
102
|
+
string = stringFromTypeDisjointLeftValueAndRightValue(disjoint, leftValue, rightValue, context);
|
|
104
103
|
|
|
105
104
|
bitwiseValue = new BitwiseValue(string, type, disjoint, leftValue, rightValue);
|
|
106
105
|
}
|
|
@@ -116,3 +115,14 @@ function disjointFromBitwiseValueNode(bitwiseValueNode, context) {
|
|
|
116
115
|
|
|
117
116
|
return disjoint;
|
|
118
117
|
}
|
|
118
|
+
|
|
119
|
+
function stringFromTypeDisjointLeftValueAndRightValue(disjoint, leftValue, rightValue, context) {
|
|
120
|
+
const operatorString = disjoint ?
|
|
121
|
+
DISJUNCTION :
|
|
122
|
+
CONJUNCTION,
|
|
123
|
+
leftValueString = leftValue.asString(context),
|
|
124
|
+
rightValueString = rightValue.asString(context),
|
|
125
|
+
string = `${leftValueString} ${operatorString} ${rightValueString}`;
|
|
126
|
+
|
|
127
|
+
return string;
|
|
128
|
+
}
|
|
@@ -48,10 +48,9 @@ export default domAssigned(class BracketedValue {
|
|
|
48
48
|
if (valueBracketedValueNode !== null) {
|
|
49
49
|
const { Value } = dom,
|
|
50
50
|
bracketedValueNode = valueBracketedValueNode, ///
|
|
51
|
-
node = bracketedValueNode, ///
|
|
52
|
-
string = context.nodeAsString(node),
|
|
53
51
|
valueNode = valueNodeQuery(bracketedValueNode),
|
|
54
|
-
value = Value.fromValueNode(valueNode, context)
|
|
52
|
+
value = Value.fromValueNode(valueNode, context),
|
|
53
|
+
string = stringFromValue(value, context);
|
|
55
54
|
|
|
56
55
|
bracketedValue = new BracketedValue(string, value);
|
|
57
56
|
}
|
|
@@ -59,3 +58,10 @@ export default domAssigned(class BracketedValue {
|
|
|
59
58
|
return bracketedValue;
|
|
60
59
|
}
|
|
61
60
|
});
|
|
61
|
+
|
|
62
|
+
function stringFromValue(value, context) {
|
|
63
|
+
const valueString = value.asString(context),
|
|
64
|
+
string = `(${valueString})`;
|
|
65
|
+
|
|
66
|
+
return string;
|
|
67
|
+
}
|