occam-furtle 2.0.69 → 2.0.73

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.
Files changed (41) hide show
  1. package/lib/dom/assignment/object.js +36 -38
  2. package/lib/dom/assignment.js +1 -10
  3. package/lib/dom/block/return.js +31 -4
  4. package/lib/dom/block.js +1 -1
  5. package/lib/dom/parameter/named.js +143 -0
  6. package/lib/dom/parameter.js +10 -36
  7. package/lib/dom/parameters/named.js +208 -0
  8. package/lib/dom/parameters.js +8 -52
  9. package/lib/dom/procedure/anonymous.js +28 -24
  10. package/lib/dom/procedure.js +7 -22
  11. package/lib/dom/returnStatement.js +5 -10
  12. package/lib/dom/some.js +15 -6
  13. package/lib/dom/step.js +3 -12
  14. package/lib/dom/value.js +2 -2
  15. package/lib/dom/variable.js +5 -5
  16. package/lib/index.js +3 -2
  17. package/lib/nodeProperties.js +118 -0
  18. package/lib/nodeProperty.js +100 -0
  19. package/package.json +4 -4
  20. package/src/dom/assignment/object.js +34 -36
  21. package/src/dom/assignment.js +0 -10
  22. package/src/dom/block/return.js +51 -10
  23. package/src/dom/block.js +1 -1
  24. package/src/dom/parameter/named.js +119 -0
  25. package/src/dom/parameter.js +7 -43
  26. package/src/dom/parameters/named.js +129 -0
  27. package/src/dom/parameters.js +12 -63
  28. package/src/dom/procedure/anonymous.js +51 -37
  29. package/src/dom/procedure.js +3 -25
  30. package/src/dom/returnStatement.js +8 -14
  31. package/src/dom/some.js +25 -9
  32. package/src/dom/step.js +3 -12
  33. package/src/dom/value.js +1 -1
  34. package/src/dom/variable.js +8 -11
  35. package/src/index.js +2 -1
  36. package/src/nodeProperties.js +84 -0
  37. package/src/nodeProperty.js +56 -0
  38. package/lib/dom/assignment/variable.js +0 -133
  39. package/lib/parameters/node.js +0 -76
  40. package/src/dom/assignment/variable.js +0 -52
  41. package/src/parameters/node.js +0 -32
@@ -7,9 +7,8 @@ import { domAssigned } from "../dom";
7
7
  import { nodeQuery, nodesQuery } from "../utilities/query";
8
8
 
9
9
  const parameterNodesQuery = nodesQuery("/parameters/parameter"),
10
- someParametersNodeQuery = nodeQuery("/some/parameters"),
11
10
  arrayAssignmentParametersNodeQuery = nodeQuery("/arrayAssignment/parameters"),
12
- objectAssignmentParametersNodeQuery = nodeQuery("/objectAssignment/parameters"),
11
+ anonymousProcedureParametersNodeQuery = nodeQuery("/anonymousProcedure/parameters"),
13
12
  procedureDeclarationParametersNodeQuery = nodeQuery("/procedureDeclaration/parameters");
14
13
 
15
14
  export default domAssigned(class Parameters {
@@ -38,8 +37,6 @@ export default domAssigned(class Parameters {
38
37
  return parameter;
39
38
  }
40
39
 
41
- someParameter(callback) { return this.array.some(callback); }
42
-
43
40
  forEachParameter(callback) { this.array.forEach(callback); }
44
41
 
45
42
  matchValues(values, context) {
@@ -69,60 +66,8 @@ export default domAssigned(class Parameters {
69
66
  context.debug(`...matched the ${valuesString} values against the '${parametersString}' parameters.`);
70
67
  }
71
68
 
72
- matchParameter(parameter, context) {
73
- const parameterString = parameter.getString(),
74
- parametersString = this.string; ///
75
-
76
- context.trace(`Matching the '${parameterString}' parameter against the '${parametersString}' parameters...`);
77
-
78
- const parameterA = parameter, ///
79
- parameterMatches = this.someParameter((parameter) => {
80
- if (parameter !== null) {
81
- const parameterB = parameter, ///
82
- parameterBMatchesParameterA = parameterA.matchParameter(parameterB, context);
83
-
84
- if (parameterBMatchesParameterA) {
85
- return true;
86
- }
87
- }
88
- });
89
-
90
- if (!parameterMatches) {
91
- const message = `The '${parameterString}' parameter does not match any of the '${parametersString}' parameters.`,
92
- exception = Exception.fromMessage(message);
93
-
94
- throw exception;
95
- }
96
-
97
- context.debug(`...matched the '${parameterString}' parameter against the '${parametersString}' parameters.`);
98
- }
99
-
100
- matchParameters(parameters, context) {
101
- parameters.forEachParameter((parameter) => {
102
- if (parameter !== null) {
103
- this.matchParameter(parameter, context);
104
- }
105
- });
106
- }
107
-
108
69
  static name = "Parameters";
109
70
 
110
- static fromSomeNode(someNode, context) {
111
- const { Parameter } = dom,
112
- someParametersNode = someParametersNodeQuery(someNode),
113
- parameterNode = someParametersNode, ///
114
- parameterNodes = parameterNodesQuery(parameterNode),
115
- array = parameterNodes.map((parameterNode) => {
116
- const parameter = Parameter.fromParameterNode(parameterNode, context);
117
-
118
- return parameter;
119
- }),
120
- string = stringFromArray(array, context),
121
- parameters = new Parameters(string, array);
122
-
123
- return parameters;
124
- }
125
-
126
71
  static fromStringAndArray(string, array) {
127
72
  const parameters = new Parameters(string, array);
128
73
 
@@ -141,13 +86,17 @@ export default domAssigned(class Parameters {
141
86
  return parameters;
142
87
  }
143
88
 
144
- static fromObjectAssignmentNode(objectAssignmentNode, context) {
145
- const objectAssignmentParametersNode = objectAssignmentParametersNodeQuery(objectAssignmentNode),
146
- parametersNode = objectAssignmentParametersNode, ///
147
- node = parametersNode, ///
148
- string = context.nodeAsString(node),
149
- parameterNodes = parameterNodesQuery(parametersNode),
150
- array = arrayFromParameterNodes(parameterNodes, context),
89
+ static fromAnonymousProcedureNode(anonymousProcedureNode, context) {
90
+ const { Parameter } = dom,
91
+ anonymousProcedureParametersNode = anonymousProcedureParametersNodeQuery(anonymousProcedureNode),
92
+ parameterNode = anonymousProcedureParametersNode, ///
93
+ parameterNodes = parameterNodesQuery(parameterNode),
94
+ array = parameterNodes.map((parameterNode) => {
95
+ const parameter = Parameter.fromParameterNode(parameterNode, context);
96
+
97
+ return parameter;
98
+ }),
99
+ string = stringFromArray(array, context),
151
100
  parameters = new Parameters(string, array);
152
101
 
153
102
  return parameters;
@@ -3,18 +3,19 @@
3
3
  import dom from "../../dom";
4
4
  import Exception from "../../exception";
5
5
 
6
+ import { nodeQuery } from "../../utilities/query";
6
7
  import { domAssigned } from "../../dom";
7
- import { nodeQuery, nodesQuery } from "../../utilities/query";
8
8
  import { variablesFromValuesAndParameters } from "../procedure";
9
9
 
10
- const nonsenseNodesQuery = nodesQuery("/some/anonymousProcedure/returnBlock/nonsense"),
11
- parametersNodeQuery = nodeQuery("/some/anonymousProcedure/parameters");
10
+ const parametersNodeQuery = nodeQuery("/anonymousProcedure/parameters"),
11
+ typeTerminalNodeQuery = nodeQuery("/anonymousProcedure/@type"),
12
+ somAnonymousProcedureNodeQuery = nodeQuery("/some/anonymousProcedure");
12
13
 
13
14
  export default domAssigned(class AnonymousProcedure {
14
- constructor(string, parameters, nonsensical, returnBlock) {
15
+ constructor(string, type, parameters, returnBlock) {
15
16
  this.string = string;
17
+ this.type - type;
16
18
  this.parameters = parameters;
17
- this.nonsensical = nonsensical;
18
19
  this.returnBlock = returnBlock;
19
20
  }
20
21
 
@@ -22,12 +23,12 @@ export default domAssigned(class AnonymousProcedure {
22
23
  return this.string;
23
24
  }
24
25
 
25
- getParameters() {
26
- return this.paramters;
26
+ getType() {
27
+ return this.type;
27
28
  }
28
29
 
29
- isNonsensical() {
30
- return this.nonsensical;
30
+ getParameters() {
31
+ return this.paramters;
31
32
  }
32
33
 
33
34
  getReturnBlock() {
@@ -35,54 +36,67 @@ export default domAssigned(class AnonymousProcedure {
35
36
  }
36
37
 
37
38
  call(values, context) {
38
- debugger
39
-
40
39
  const anonymousProcedureString = this.string; ///
41
40
 
42
41
  context.trace(`Calling the '${anonymousProcedureString}' anonymous procedure...`);
43
42
 
44
- if (this.nonsensical) {
45
- const message = `The '${anonymousProcedureString}' anonymous procedure is nonsensical.`,
46
- exception = Exception.fromMessage(message);
47
-
48
- throw exception;
49
- }
50
-
51
43
  this.parameters.matchValues(values, context);
52
44
 
53
45
  const variables = variablesFromValuesAndParameters(values, this.parameters, context);
54
46
 
55
- this.returnBlock.evaluate(variables, context);
47
+ const value = this.returnBlock.evaluate(variables, context),
48
+ valueType = value.getType();
49
+
50
+ if (this.type !== valueType) {
51
+ const valueString = value.asString(context),
52
+ message = `The ${valueString} value's '${valueType}' type and the '${anonymousProcedureString}' anonymous procedure's '${this.type}' type do not match.`,
53
+ exception = Exception.fromMessage(message);
54
+
55
+ throw exception;
56
+ }
56
57
 
57
58
  context.debug(`...called the '${anonymousProcedureString}' anonymous procedure.`);
59
+
60
+ return value;
58
61
  }
59
62
 
60
63
  static name = "AnonymousProcedure";
61
64
 
62
65
  static fromSomeNode(someNode, context) {
63
- const { ReturnBlock, Parameters } = dom,
64
- string = stringFromSomeNode(someNode, context),
65
- parameters = Parameters.fromSomeNode(someNode, context),
66
- nonsensical = nonsensicalFromSomeNode(someNode, context),
67
- returnBlock = ReturnBlock.fromSomeNode(someNode, context),
68
- anonymousProcedureDeclaration = new AnonymousProcedure(string, parameters, nonsensical, returnBlock);
69
-
70
- return anonymousProcedureDeclaration;
66
+ const someAnonymousProcedureNode = somAnonymousProcedureNodeQuery(someNode),
67
+ anonymousProcedureNode = someAnonymousProcedureNode, ///
68
+ anonymousProcedure = anonymousProcedureFromAnonymousProcedureNode(anonymousProcedureNode, context);
69
+
70
+ return anonymousProcedure;
71
71
  }
72
72
  });
73
73
 
74
- function stringFromSomeNode(someNode, context) {
75
- const parametersNode = parametersNodeQuery(someNode),
76
- parametersString = context.nodeAsString(parametersNode),
77
- string = `(${parametersString}) { ... }`;
74
+ function anonymousProcedureFromAnonymousProcedureNode(anonymousProcedureNode, context) {
75
+ const { Parameters, ReturnBlock, AnonymousProcedure } = dom,
76
+ string = stringFromAnonymousProcedureNode(anonymousProcedureNode, context),
77
+ type = typeFromProcedureAnonymousProcedureNode(anonymousProcedureNode, context),
78
+ parameters = Parameters.fromAnonymousProcedureNode(anonymousProcedureNode, context),
79
+ returnBlock = ReturnBlock.fromAnonymousProcedureNode(anonymousProcedureNode, context),
80
+ anonymousProcedure = new AnonymousProcedure(string, type, parameters, returnBlock);
78
81
 
79
- return string;
82
+ return anonymousProcedure;
83
+ }
84
+
85
+ function typeFromProcedureAnonymousProcedureNode(anonymousProcedureNode, context) {
86
+ const typeTerminalNode = typeTerminalNodeQuery(anonymousProcedureNode),
87
+ typeTerminalNodeContent = typeTerminalNode.getContent(),
88
+ type = typeTerminalNodeContent; ///
89
+
90
+ return type;
80
91
  }
81
92
 
82
- function nonsensicalFromSomeNode(someNode, context) {
83
- const nonsenseNodes = nonsenseNodesQuery(someNode),
84
- nonsenseNodesLength = nonsenseNodes.length,
85
- nonsensical = (nonsenseNodesLength > 0);
93
+ function stringFromAnonymousProcedureNode(anonymousProcedureNode, context) {
94
+ const parametersNode = parametersNodeQuery(anonymousProcedureNode),
95
+ typeTerminalNode = typeTerminalNodeQuery(anonymousProcedureNode),
96
+ parametersString = context.nodeAsString(parametersNode),
97
+ typeNode = typeTerminalNode, ///
98
+ typeString = context.nodeAsString(typeNode),
99
+ string = `${typeString} (${parametersString}) { ... }`;
86
100
 
87
- return nonsensical;
101
+ return string;
88
102
  }
@@ -3,22 +3,20 @@
3
3
  import dom from "../dom";
4
4
  import Exception from "../exception";
5
5
 
6
+ import { nodeQuery } from "../utilities/query";
6
7
  import { domAssigned } from "../dom";
7
8
  import { BOOLEAN_TYPE } from "../types";
8
- import { nodeQuery, nodesQuery } from "../utilities/query";
9
9
 
10
10
  const labelNodeQuery = nodeQuery("/procedureDeclaration/label"),
11
- nonsenseNodesQuery = nodesQuery("/procedureDeclaration/returnBlock/nonsense"),
12
11
  parametersNodeQuery = nodeQuery("/procedureDeclaration/parameters"),
13
12
  typeTerminalNodeQuery = nodeQuery("/procedureDeclaration/@type");
14
13
 
15
14
  export default domAssigned(class Procedure {
16
- constructor(string, type, label, parameters, nonsensical, returnBlock) {
15
+ constructor(string, type, label, parameters, returnBlock) {
17
16
  this.string = string;
18
17
  this.type = type;
19
18
  this.label = label;
20
19
  this.parameters = parameters;
21
- this.nonsensical = nonsensical;
22
20
  this.returnBlock = returnBlock;
23
21
  }
24
22
 
@@ -38,10 +36,6 @@ export default domAssigned(class Procedure {
38
36
  return this.parameters;
39
37
  }
40
38
 
41
- isNonsensical() {
42
- return this.nonsensical;
43
- }
44
-
45
39
  getReturnBlock() {
46
40
  return this.returnBlock;
47
41
  }
@@ -64,13 +58,6 @@ export default domAssigned(class Procedure {
64
58
 
65
59
  context.trace(`Calling the '${procedureString}' procedure...`);
66
60
 
67
- if (this.nonsensical) {
68
- const message = `The '${procedureString}' procedure is nonsensical.`,
69
- exception = Exception.fromMessage(message);
70
-
71
- throw exception;
72
- }
73
-
74
61
  this.parameters.matchValues(values, context);
75
62
 
76
63
  const variables = variablesFromValuesAndParameters(values, this.parameters, context),
@@ -100,9 +87,8 @@ export default domAssigned(class Procedure {
100
87
  type = typeFromProcedureDeclarationNode(procedureDeclarationNode, context),
101
88
  label = Label.fromProcedureDeclarationNode(procedureDeclarationNode, context),
102
89
  parameters = Parameters.fromProcedureDeclarationNode(procedureDeclarationNode, context),
103
- nonsensical = nonsensicalFromProcedureDeclarationNode(procedureDeclarationNode, context),
104
90
  returnBlock = ReturnBlock.fromProcedureDeclarationNode(procedureDeclarationNode, context),
105
- procedureDeclaration = new Procedure(string, type, label, parameters, nonsensical, returnBlock);
91
+ procedureDeclaration = new Procedure(string, type, label, parameters, returnBlock);
106
92
 
107
93
  return procedureDeclaration;
108
94
  }
@@ -145,11 +131,3 @@ function stringFromProcedureDeclarationNode(procedureDeclarationNode, context) {
145
131
 
146
132
  return string;
147
133
  }
148
-
149
- function nonsensicalFromProcedureDeclarationNode(procedureDeclarationNode, context) {
150
- const nonsenseNodes = nonsenseNodesQuery(procedureDeclarationNode),
151
- nonsenseNodesLength = nonsenseNodes.length,
152
- nonsensical = (nonsenseNodesLength > 0);
153
-
154
- return nonsensical;
155
- }
@@ -5,7 +5,7 @@ import dom from "../dom";
5
5
  import { nodeQuery } from "../utilities/query";
6
6
  import { domAssigned } from "../dom";
7
7
 
8
- const returnStatementNodeQuery = nodeQuery("/procedureDeclaration/returnBlock/returnStatement");
8
+ const returnStatementNodeQuery = nodeQuery("/returnBlock/returnStatement");
9
9
 
10
10
  export default domAssigned(class ReturnStatement {
11
11
  constructor(string, value) {
@@ -37,19 +37,13 @@ export default domAssigned(class ReturnStatement {
37
37
 
38
38
  static name = "ReturnStatement";
39
39
 
40
- static fromProcedureDeclarationNode(procedureDeclarationNode, context) {
41
- let returnStatement = null;
42
-
43
- const returnStatementNode = returnStatementNodeQuery(procedureDeclarationNode);
44
-
45
- if (returnStatementNode !== null) {
46
- const { Value } = dom,
47
- node = returnStatementNode, ///
48
- string = context.nodeAsString(node),
49
- value = Value.fromReturnStatementNode(returnStatementNode, context);
50
-
51
- returnStatement = new ReturnStatement(string, value);
52
- }
40
+ static fromReturnBlockNode(returnBlockNode, context) {
41
+ const { Value } = dom,
42
+ returnStatementNode = returnStatementNodeQuery(returnBlockNode),
43
+ node = returnStatementNode, ///
44
+ string = context.nodeAsString(node),
45
+ value = Value.fromReturnStatementNode(returnStatementNode, context),
46
+ returnStatement = new ReturnStatement(string, value);
53
47
 
54
48
  return returnStatement;
55
49
  }
package/src/dom/some.js CHANGED
@@ -4,8 +4,8 @@ import dom from "../dom";
4
4
  import Exception from "../exception";
5
5
 
6
6
  import { nodeQuery } from "../utilities/query";
7
- import { NODES_TYPE } from "../types";
8
7
  import { domAssigned } from "../dom";
8
+ import { NODES_TYPE, BOOLEAN_TYPE } from "../types";
9
9
 
10
10
  const variableNodeQuery = nodeQuery("/some/variable"),
11
11
  valueSomeNodeQuery = nodeQuery("/value/some"),
@@ -31,11 +31,9 @@ export default domAssigned(class Some {
31
31
  }
32
32
 
33
33
  evaluate(context) {
34
- debugger
35
-
36
34
  const someString = this.getString();
37
35
 
38
- context.trace(`Evaluating the '${someString}' some loop...`);
36
+ context.trace(`Evaluating the '${someString}' some...`);
39
37
 
40
38
  const value = this.variable.evaluate(context),
41
39
  valueType = value.getType();
@@ -51,14 +49,32 @@ export default domAssigned(class Some {
51
49
  const nodes = value.getNodes();
52
50
 
53
51
  nodes.some((node) => {
54
- const { Value, Values } = dom,
55
- value = Value.fromNode(node, context),
56
- values = Values.fromValue(value, context);
52
+ let value;
53
+
54
+ const { Value, Values } = dom;
55
+
56
+ value = Value.fromNode(node, context);
57
+
58
+ const values = Values.fromValue(value, context);
59
+
60
+ value = this.anonymousProcedure.call(values, context);
61
+
62
+ const valueType = value.getType();
63
+
64
+ if (valueType !== BOOLEAN_TYPE) {
65
+ const valueString = value.asString(context),
66
+ message = `The ${valueString} value's type is '${valueType}' when it should be of type '${BOOLEAN_TYPE}'.`,
67
+ exception = Exception.fromMessage(message);
68
+
69
+ throw exception;
70
+ }
71
+
72
+ const boolean = value.getBoolean();
57
73
 
58
- this.anonymousProcedure.call(values, context);
74
+ return boolean;
59
75
  });
60
76
 
61
- context.trace(`...evaluated the '${someString}' some loop.`);
77
+ context.trace(`...evaluated the '${someString}' some.`);
62
78
  }
63
79
 
64
80
  static name = "Some";
package/src/dom/step.js CHANGED
@@ -5,12 +5,11 @@ import dom from "../dom";
5
5
  import { domAssigned } from "../dom";
6
6
 
7
7
  export default domAssigned(class Step {
8
- constructor(string, arrayAssignment, objectAssigment, conditionalBlocks, variableAssignment, variablesDeclaration) {
8
+ constructor(string, arrayAssignment, objectAssigment, conditionalBlocks, variablesDeclaration) {
9
9
  this.string = string;
10
10
  this.arrayAssignment = arrayAssignment;
11
11
  this.objectAssigment = objectAssigment;
12
12
  this.conditionalBlocks = conditionalBlocks;
13
- this.variableAssignment = variableAssignment;
14
13
  this.variablesDeclaration = variablesDeclaration;
15
14
  }
16
15
 
@@ -30,16 +29,11 @@ export default domAssigned(class Step {
30
29
  return this.conditionalBlocks;
31
30
  }
32
31
 
33
- getVariableAssignment() {
34
- return this.variableAssignment;
35
- }
36
-
37
32
  getVariablesDeclaration() {
38
33
  return this.variablesDeclaration;
39
34
  }
40
35
 
41
36
  evaluate(context) {
42
-
43
37
  if (false) {
44
38
  ///
45
39
  } else if (this.arrayAssignment !== null) {
@@ -48,8 +42,6 @@ export default domAssigned(class Step {
48
42
  this.objectAssigment.evaluate(context);
49
43
  } else if (this.conditionalBlocks !== null) {
50
44
  this.conditionalBlocks.evaluate(context);
51
- } else if (this.variableAssignment !== null) {
52
- this.variableAssignment.evaluate(context);
53
45
  } else if (this.variablesDeclaration !== null) {
54
46
  this.variablesDeclaration.evaluate(context);
55
47
  }
@@ -58,15 +50,14 @@ export default domAssigned(class Step {
58
50
  static name = "Step";
59
51
 
60
52
  static fromStepNode(stepNode, context) {
61
- const { ArrayAssignment, ObjectAssigment, ConditionalBlocks, VariableAssignment, VariablesDeclaration } = dom,
53
+ const { ArrayAssignment, ObjectAssigment, ConditionalBlocks, VariablesDeclaration } = dom,
62
54
  node = stepNode, ///
63
55
  string = context.nodeAsString(node),
64
56
  arrayAssignment = ArrayAssignment.fromStepNode(stepNode, context),
65
57
  objectAssigment = ObjectAssigment.fromStepNode(stepNode, context),
66
58
  conditionalBlocks = ConditionalBlocks.fromStepNode(stepNode, context),
67
- variableAssignment = VariableAssignment.fromStepNode(stepNode, context),
68
59
  variablesDeclaration = VariablesDeclaration.fromStepNode(stepNode, context),
69
- step = new Step(string, arrayAssignment, objectAssigment, conditionalBlocks, variableAssignment, variablesDeclaration);
60
+ step = new Step(string, arrayAssignment, objectAssigment, conditionalBlocks, variablesDeclaration);
70
61
 
71
62
  return step;
72
63
  }
package/src/dom/value.js CHANGED
@@ -19,7 +19,7 @@ const ternaryValueNodeQuery = nodeQuery("/ternary/value"),
19
19
  primitiveTerminalNodeQuery = nodeQuery("/value/@primitive"),
20
20
  returnStatementValueNodeQuery = nodeQuery("/returnStatement/value"),
21
21
  stringLiteralTerminalNodeQuery = nodeQuery("/value/@string-literal"),
22
- conditionalBlocksCValueNodeQuery = nodeQuery("/conditionalBlocks/vvalue");
22
+ conditionalBlocksCValueNodeQuery = nodeQuery("/conditionalBlocks/value");
23
23
 
24
24
  export default domAssigned(class Value {
25
25
  constructor(node, nodes, number, string, boolean, some, ternary, variable, nodeQuery, nodesQuery, comparison, negatedValue, bitwiseValue, bracketedValue, procedureCall) {
@@ -12,8 +12,7 @@ const someVariableNodeQuery = nodeQuery("/some/variable"),
12
12
  nodesQueryVariableNodeQuery = nodeQuery("/nodesQuery/variable"),
13
13
  variableNameTerminalNodeQuery = nodeQuery("/variable/@name"),
14
14
  arrayAssignmentVariableNodeQuery = nodeQuery("/arrayAssignment/variable"),
15
- objectAssignmentVariableNodeQuery = nodeQuery("/objectAssignment/variable"),
16
- variableAssignmentVariableNodeQuery = nodeQuery("/variableAssignment/variable");
15
+ objectAssignmentVariableNodeQuery = nodeQuery("/objectAssignment/variable");
17
16
 
18
17
  export default domAssigned(class Variable {
19
18
  constructor(string, type, name, value, assignment) {
@@ -218,16 +217,14 @@ export default domAssigned(class Variable {
218
217
  return variable;
219
218
  }
220
219
 
221
- static fromVariableAssignmentNode(variableAssignmentNode, context) {
222
- const { Assignment } = dom,
223
- variableAssignmentVariableNode = variableAssignmentVariableNodeQuery(variableAssignmentNode),
224
- variableNode = variableAssignmentVariableNode, ///
225
- node = variableNode, ///
226
- string = context.nodeAsString(node),
227
- type = null,
228
- name = nameFromVariableNode(variableNode),
220
+ static fromNamedParameterAndAssignment(namedParameter, assignment, context) {
221
+ const asName = namedParameter.getAsName(),
222
+ name = (asName !== null) ?
223
+ asName : ///
224
+ namedParameter.getName(),
225
+ type = namedParameter.getType(),
229
226
  value = null,
230
- assignment = Assignment.fromVariableAssignmentNode(variableAssignmentNode, context),
227
+ string = name, ///
231
228
  variable = new Variable(string, type, name, value, assignment);
232
229
 
233
230
  return variable;
package/src/index.js CHANGED
@@ -21,13 +21,14 @@ import ReturnBlock from "./dom/block/return";
21
21
  import NegatedValue from "./dom/value/negated";
22
22
  import BitwiseValue from "./dom/value/bitwise";
23
23
  import ProcedureCall from "./dom/procedureCall";
24
+ import NamedParameter from "./dom/parameter/named";
24
25
  import BracketedValue from "./dom/value/bracketed";
25
26
  import ArrayAssigment from "./dom/assignment/array";
26
27
  import ReturnStatement from "./dom/returnStatement";
28
+ import NamedParameters from "./dom/parameters/named";
27
29
  import ObjectAssignment from "./dom/assignment/object";
28
30
  import ConditionalBlocks from "./dom/conditionalBlocks";
29
31
  import AnonymousProcedure from "./dom/procedure/anonymous";
30
- import VariableAssignment from "./dom/assignment/variable";
31
32
  import ProcedureDeclaration from "./dom/declaration/procedure";
32
33
  import VariablesDeclaration from "./dom/declaration/variables";
33
34
 
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ import Exception from "./exception";
4
+ import NodeProperty from "./nodeProperty";
5
+
6
+ import { stringFromArray } from "./dom/parameters";
7
+ import { NODES_TYPE, STRING_TYPE, BOOLEAN_TYPE } from "./types";
8
+ import { CONTENT_PARAMETER_NAME, TERMINAL_PARAMETER_NAME, CHILD_NODES_PARAMETER_NAME } from "./parameterNames";
9
+
10
+ const types = [
11
+ STRING_TYPE,
12
+ BOOLEAN_TYPE,
13
+ NODES_TYPE,
14
+ ],
15
+ names = [
16
+ CONTENT_PARAMETER_NAME,
17
+ TERMINAL_PARAMETER_NAME,
18
+ CHILD_NODES_PARAMETER_NAME
19
+ ];
20
+
21
+ class NodeProperties {
22
+ constructor(string, array) {
23
+ this.string = string;
24
+ this.array = array;
25
+ }
26
+
27
+ getString() {
28
+ return this.string;
29
+ }
30
+
31
+ getArray() {
32
+ return this.array;
33
+ }
34
+
35
+ someNodeProperty(callback) { return this.array.some(callback); }
36
+
37
+ matchNamedParameter(namedParameter, context) {
38
+ const nodePropertiesString = this.string, ///
39
+ namedParameterString = namedParameter.getString();
40
+
41
+ context.trace(`Matching the '${namedParameterString}' named parameter against the '${nodePropertiesString}' node properties...`);
42
+
43
+ const namedParameterMatches = this.someNodeProperty((nodeProperty) => {
44
+ const namedParameterMatchesNodeProperty = nodeProperty.matchNamedParameter(namedParameter, context);
45
+
46
+ if (namedParameterMatchesNodeProperty) {
47
+ return true;
48
+ }
49
+ });
50
+
51
+ if (!namedParameterMatches) {
52
+ const message = `The '${namedParameterString}' named parameter does not match any of the '${nodePropertiesString}' node properties.`,
53
+ exception = Exception.fromMessage(message);
54
+
55
+ throw exception;
56
+ }
57
+
58
+ context.debug(`...matched the '${namedParameterString}' named parameter against the '${nodePropertiesString}' node properties.`);
59
+ }
60
+
61
+ matchNamedParameters(namedParameters, context) {
62
+ namedParameters.forEachNamedParameter((namedParameter) => {
63
+ this.matchNamedParameter(namedParameter, context);
64
+ });
65
+ }
66
+
67
+ static fromNothing() {
68
+ const context = null,
69
+ array = names.map((name, index) => {
70
+ const type = types[index],
71
+ nodeProperty = NodeProperty.fromNameAndType(name, type, context);
72
+
73
+ return nodeProperty;
74
+ }),
75
+ string = stringFromArray(array, context),
76
+ nodeProperties = new NodeProperties(string, array);
77
+
78
+ return nodeProperties;
79
+ }
80
+ }
81
+
82
+ const nodeProperties = NodeProperties.fromNothing();
83
+
84
+ export default nodeProperties;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ export default class NodeProperty {
4
+ constructor(string, type, name) {
5
+ this.string = string;
6
+ this.type = type;
7
+ this.name = name;
8
+ }
9
+
10
+ getString() {
11
+ return this.string;
12
+ }
13
+
14
+ getType() {
15
+ return this.type;
16
+ }
17
+
18
+ getName() {
19
+ return this.name;
20
+ }
21
+
22
+ matchNamedParameter(namedParameter, context) {
23
+ let namedParameterMatches;
24
+
25
+ const nodePropertyString = this.string, ///
26
+ namedParameterString = namedParameter.getString();
27
+
28
+ context.trace(`Matching the '${nodePropertyString}' node property against the '${namedParameterString}' named parameter...`);
29
+
30
+ const name = namedParameter.getName(),
31
+ type = namedParameter.getType();
32
+
33
+ namedParameterMatches = ((this.name === name) && (this.type === type));
34
+
35
+ if (namedParameterMatches) {
36
+ context.debug(`...matched the '${nodePropertyString}' node property against the '${namedParameterString}' named parameter.`);
37
+ }
38
+
39
+ return namedParameterMatches;
40
+ }
41
+
42
+ static name = "Parameter";
43
+
44
+ static fromNameAndType(name, type, context) {
45
+ const string = stringFromNameAndType(name, type, context),
46
+ nodeProperty = new NodeProperty(string, type, name);
47
+
48
+ return nodeProperty;
49
+ }
50
+ };
51
+
52
+ function stringFromNameAndType(name, type) {
53
+ const string = `${type} ${name}`;
54
+
55
+ return string;
56
+ }