occam-furtle 2.0.63 → 2.0.64

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/src/dom/step.js CHANGED
@@ -44,27 +44,20 @@ export default domAssigned(class Step {
44
44
  }
45
45
 
46
46
  evaluate(context) {
47
- if (this.forEachLoop !== null) {
48
- this.forEachLoop.evaluate(context);
49
- }
50
47
 
51
- if (this.arrayAssignment !== null) {
48
+ if (false) {
49
+ ///
50
+ } else if (this.forEachLoop !== null) {
51
+ this.forEachLoop.evaluate(context);
52
+ } else if (this.arrayAssignment !== null) {
52
53
  this.arrayAssignment.evaluate(context);
53
- }
54
-
55
- if (this.objectAssigment !== null) {
54
+ } else if (this.objectAssigment !== null) {
56
55
  this.objectAssigment.evaluate(context);
57
- }
58
-
59
- if (this.conditionalBlocks !== null) {
56
+ } else if (this.conditionalBlocks !== null) {
60
57
  this.conditionalBlocks.evaluate(context);
61
- }
62
-
63
- if (this.variableAssignment !== null) {
58
+ } else if (this.variableAssignment !== null) {
64
59
  this.variableAssignment.evaluate(context);
65
- }
66
-
67
- if (this.variablesDeclaration !== null) {
60
+ } else if (this.variablesDeclaration !== null) {
68
61
  this.variablesDeclaration.evaluate(context);
69
62
  }
70
63
  }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ import dom from "../dom";
4
+
5
+ import { nodeQuery } from "../utilities/query";
6
+ import { domAssigned } from "../dom";
7
+
8
+ const ifValueNodeQuery = nodeQuery("/ternary/value[0]"),
9
+ ternaryNodeQuery = nodeQuery("/value/ternary"),
10
+ conditionNodeQuery = nodeQuery("/ternary/condition"),
11
+ elseValueNodeQuery = nodeQuery("/ternary/value[1]");
12
+
13
+ export default domAssigned(class Ternary {
14
+ constructor(string, condition, ifValue, elseValue) {
15
+ this.string = string;
16
+ this.condition = condition;
17
+ this.ifValue = ifValue;
18
+ this.elseValue = elseValue;
19
+ }
20
+
21
+ getString() {
22
+ return this.string;
23
+ }
24
+
25
+ getCondition() {
26
+ return this.condition;
27
+ }
28
+
29
+ getConditionBlock() {
30
+ return this.ifValue;
31
+ }
32
+
33
+ getElseBlock() {
34
+ return this.elseValue;
35
+ }
36
+
37
+ evaluate(context) {
38
+ let value;
39
+
40
+ const ternaryString = this.string; ///
41
+
42
+ context.trace(`Evaluating the '${ternaryString}' ternary...`);
43
+
44
+ value = this.condition.evaluate(context);
45
+
46
+ const boolean = value.getBoolean();
47
+
48
+ value = boolean ?
49
+ this.ifValue.evaluate(context) :
50
+ this.elseValue.evaluate(context);
51
+
52
+ context.debug(`...evaluated the '${ternaryString}' ternary.`);
53
+
54
+ return value;
55
+ }
56
+
57
+ static name = "Ternary";
58
+
59
+ static fromValueNode(valueNode, context) {
60
+ let ternary = null;
61
+
62
+ const ternaryNode = ternaryNodeQuery(valueNode);
63
+
64
+ if (ternaryNode !== null) {
65
+ const { Value, Condition } = dom,
66
+ string = stringFromTernaryNode(ternaryNode, context),
67
+ ifValueNode = ifValueNodeQuery(ternaryNode),
68
+ elseValueNode = elseValueNodeQuery(ternaryNode),
69
+ condition = Condition.fromTernaryNode(ternaryNode, context),
70
+ ifValue = Value.fromValueNode(ifValueNode, context),
71
+ elseValue = Value.fromValueNode(elseValueNode, context);
72
+
73
+ ternary = new Ternary(string, condition, ifValue, elseValue);
74
+ }
75
+
76
+ return ternary;
77
+ }
78
+ });
79
+
80
+ function stringFromTernaryNode(ternaryNode, context) {
81
+ let string;
82
+
83
+ const ifValueNode = ifValueNodeQuery(ternaryNode),
84
+ elseValueNode = elseValueNodeQuery(ternaryNode),
85
+ conditionNode = conditionNodeQuery(ternaryNode),
86
+ ifValueString = context.nodeAsString(ifValueNode),
87
+ elseValueString = context.nodeAsString(elseValueNode),
88
+ conditionString = context.nodeAsString(conditionNode);
89
+
90
+ string = `If (${conditionString}) ${ifValueString} ${elseValueString}`;
91
+
92
+ return string;
93
+ }
package/src/dom/value.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { arrayUtilities } from "necessary";
4
4
 
5
5
  import dom from "../dom";
6
+ import nullNode from "../nullNode";
6
7
 
7
8
  import { nodeQuery } from "../utilities/query";
8
9
  import { domAssigned } from "../dom";
@@ -19,12 +20,13 @@ const numberTerminalNodeQuery = nodeQuery("/value/@number"),
19
20
  stringLiteralTerminalNodeQuery = nodeQuery("/value/@string-literal");
20
21
 
21
22
  export default domAssigned(class Value {
22
- constructor(node, nodes, number, string, boolean, variable, nodeQuery, nodesQuery, procedureCall) {
23
+ constructor(node, nodes, number, string, boolean, ternary, variable, nodeQuery, nodesQuery, procedureCall) {
23
24
  this.node = node;
24
25
  this.nodes = nodes;
25
26
  this.number = number;
26
27
  this.string = string;
27
28
  this.boolean = boolean;
29
+ this.ternary = ternary;
28
30
  this.variable = variable;
29
31
  this.nodeQuery = nodeQuery;
30
32
  this.nodesQuery = nodesQuery;
@@ -51,6 +53,10 @@ export default domAssigned(class Value {
51
53
  return this.boolean;
52
54
  }
53
55
 
56
+ getTernary() {
57
+ return this.ternay;
58
+ }
59
+
54
60
  getVariable() {
55
61
  return this.variable;
56
62
  }
@@ -82,6 +88,8 @@ export default domAssigned(class Value {
82
88
  type = STRING_TYPE;
83
89
  } else if (this.boolean !== null) {
84
90
  type = BOOLEAN_TYPE;
91
+ } else if (this.ternary !== null) {
92
+ type = this.ternary.getType();
85
93
  } else if (this.variable !== null) {
86
94
  type = this.variable.getType();
87
95
  } else if (this.nodeQuery !== null) {
@@ -110,6 +118,8 @@ export default domAssigned(class Value {
110
118
  string = stringAsString(this.string, context)
111
119
  } else if (this.boolean !== null) {
112
120
  string = booleanAsString(this.boolean, context)
121
+ } else if (this.ternary !== null) {
122
+ string = this.ternary.asString(context);
113
123
  } else if (this.variable !== null) {
114
124
  string = this.variable.asString(context);
115
125
  } else if (this.nodeQuery !== null) {
@@ -134,6 +144,8 @@ export default domAssigned(class Value {
134
144
  (this.string !== null) ||
135
145
  (this.boolean !== null)) {
136
146
  value = this;
147
+ } else if (this.ternary !== null) {
148
+ value = this.ternary.evaluate(context);
137
149
  } else if (this.variable !== null) {
138
150
  value = this.variable.evaluate(context);
139
151
  } else if (this.nodeQuery !== null) {
@@ -153,15 +165,29 @@ export default domAssigned(class Value {
153
165
  if (false) {
154
166
  ///
155
167
  } else if (this.node !== null) {
156
- const node = value.getNode(),
157
- nodeMatches = matchNode(this.node, node);
168
+ const node = value.getNode();
158
169
 
159
- equalTo = nodeMatches; ///
170
+ if (node === null) {
171
+ equalTo = false;
172
+ } else {
173
+ const nodeA = this.node, ///
174
+ nodeB = node, ///
175
+ nodeMatches = matchNode(nodeA, nodeB);
176
+
177
+ equalTo = nodeMatches; ///
178
+ }
160
179
  } else if (this.nodes !== null) {
161
- const nodes = value.getNode(),
162
- nodesMatch = matchNodes(this.nodes, nodes);
180
+ const nodes = value.getNode();
163
181
 
164
- equalTo = nodesMatch; ///
182
+ if (nodes === null) {
183
+ equalTo = false;
184
+ } else {
185
+ const nodesA = this.nodes, ///
186
+ nodesB = nodes, ///
187
+ nodesMatch = matchNodes(nodesA, nodesB);
188
+
189
+ equalTo = nodesMatch; ///
190
+ }
165
191
  } else if (this.number !== null) {
166
192
  const number = value.getNumber();
167
193
 
@@ -185,18 +211,19 @@ export default domAssigned(class Value {
185
211
 
186
212
  static fromNode(node, context) {
187
213
  if (node === null) {
188
- node = nullValue;
214
+ node = nullNode;
189
215
  }
190
216
 
191
217
  const nodes = null,
192
218
  number = null,
193
219
  string = null,
194
220
  boolean = null,
221
+ ternary = null,
195
222
  variable = null,
196
223
  nodeQuery = null,
197
224
  nodesQuery = null,
198
225
  procedureCall = null,
199
- value = new Value(node, nodes, number, string, boolean, variable, nodeQuery, nodesQuery, procedureCall);
226
+ value = new Value(node, nodes, number, string, boolean, ternary, variable, nodeQuery, nodesQuery, procedureCall);
200
227
 
201
228
  return value;
202
229
  }
@@ -206,11 +233,12 @@ export default domAssigned(class Value {
206
233
  number = null,
207
234
  string = null,
208
235
  boolean = null,
236
+ ternary = null,
209
237
  variable = null,
210
238
  nodeQuery = null,
211
239
  nodesQuery = null,
212
240
  procedureCall = null,
213
- value = new Value(node, nodes, number, string, boolean, variable, nodeQuery, nodesQuery, procedureCall);
241
+ value = new Value(node, nodes, number, string, boolean, ternary, variable, nodeQuery, nodesQuery, procedureCall);
214
242
 
215
243
  return value;
216
244
  }
@@ -220,11 +248,12 @@ export default domAssigned(class Value {
220
248
  nodes = null,
221
249
  number = null,
222
250
  boolean = null,
251
+ ternary = null,
223
252
  variable = null,
224
253
  nodeQuery = null,
225
254
  nodesQuery = null,
226
255
  procedureCall = null,
227
- value = new Value(node, nodes, number, string, boolean, variable, nodeQuery, nodesQuery, procedureCall);
256
+ value = new Value(node, nodes, number, string, boolean, ternary, variable, nodeQuery, nodesQuery, procedureCall);
228
257
 
229
258
  return value;
230
259
  }
@@ -234,11 +263,12 @@ export default domAssigned(class Value {
234
263
  nodes = null,
235
264
  number = null,
236
265
  string = null,
266
+ ternary = null,
237
267
  variable = null,
238
268
  nodeQuery = null,
239
269
  nodesQuery = null,
240
270
  procedureCall = null,
241
- value = new Value(node, nodes, number, string, boolean, variable, nodeQuery, nodesQuery, procedureCall);
271
+ value = new Value(node, nodes, number, string, boolean, ternary, variable, nodeQuery, nodesQuery, procedureCall);
242
272
 
243
273
  return value;
244
274
  }
@@ -295,7 +325,7 @@ export default domAssigned(class Value {
295
325
  function matchNode(nodeA, nodeB) {
296
326
  let nodeMatches;
297
327
 
298
- if ((nodeA === null) || (nodeB === null)) {
328
+ if ((nodeA === nullNode) || (nodeB === nullNode)) {
299
329
  nodeMatches = (nodeA === nodeB);
300
330
  } else {
301
331
  const nodeAEqualToNodeA = nodeA.isEqualTo(nodeB);
@@ -309,17 +339,13 @@ function matchNode(nodeA, nodeB) {
309
339
  function matchNodes(nodesA, nodesB) {
310
340
  let nodesMatch;
311
341
 
312
- if ((nodesA === null) || (nodesB === null)) {
313
- nodesMatch = (nodesA === nodesB);
314
- } else {
315
- nodesMatch = match(nodesA, nodesB, (nodeA, nodeB) => {
316
- const nodeMatches = matchNode(nodeA, nodeB);
342
+ nodesMatch = match(nodesA, nodesB, (nodeA, nodeB) => {
343
+ const nodeMatches = matchNode(nodeA, nodeB);
317
344
 
318
- if (nodeMatches) {
319
- return true;
320
- }
321
- });
322
- }
345
+ if (nodeMatches) {
346
+ return true;
347
+ }
348
+ });
323
349
 
324
350
  return nodesMatch;
325
351
  }
@@ -327,7 +353,7 @@ function matchNodes(nodesA, nodesB) {
327
353
  function nodeAsString(node, context) {
328
354
  let string;
329
355
 
330
- const nodeString = (node === nullValue) ?
356
+ const nodeString = (node === nullNode) ?
331
357
  NULL :
332
358
  context.nodeAsString(node);
333
359
 
@@ -369,23 +395,38 @@ function booleanAsString(boolean, context) {
369
395
  }
370
396
 
371
397
  function valueFromValueNode(valueNode, context) {
372
- const { Value, Variable, NodeQuery, NodesQuery, ProcedureCall } = dom,
398
+ const { Value, Ternary, Variable, NodeQuery, NodesQuery, ProcedureCall } = dom,
373
399
  node = nodeFromValueNode(valueNode, context),
374
400
  nodes = nodesFromValueNode(valueNode, context),
375
401
  number = numberFromValueNode(valueNode, context),
376
402
  string = stringFromValueNode(valueNode, context),
377
403
  boolean = booleanFromValueNode(valueNode, context),
404
+ ternary = Ternary.fromValueNode(valueNode, context),
378
405
  variable = Variable.fromValueNode(valueNode, context),
379
406
  nodeQuery = NodeQuery.fromValueNode(valueNode, context),
380
407
  nodesQuery = NodesQuery.fromValueNode(valueNode, context),
381
408
  procedureCall = ProcedureCall.fromValueNode(valueNode, context),
382
- value = new Value(node, nodes, number, string, boolean, variable, nodeQuery, nodesQuery, procedureCall);
409
+ value = new Value(node, nodes, number, string, boolean, ternary, variable, nodeQuery, nodesQuery, procedureCall);
383
410
 
384
411
  return value;
385
412
  }
386
413
 
387
414
  function nodeFromValueNode(valueNode, context) {
388
- const node = null; ///
415
+ let node = null;
416
+
417
+ const primitiveTerminalNode = primitiveTerminalNodeQuery(valueNode);
418
+
419
+ if (primitiveTerminalNode !== null) {
420
+ const primitiveTerminalNodeContent = primitiveTerminalNode.getContent();
421
+
422
+ switch (primitiveTerminalNodeContent) {
423
+ case NULL: {
424
+ node = nullNode;
425
+
426
+ break;
427
+ }
428
+ }
429
+ }
389
430
 
390
431
  return node;
391
432
  }
@@ -456,13 +497,3 @@ function stringFromStringLiteral(stringLiteral, context) {
456
497
 
457
498
  return string;
458
499
  }
459
-
460
- class NullValue {
461
- static fromNothing() {
462
- const nullValue = new NullValue();
463
-
464
- return nullValue;
465
- }
466
- }
467
-
468
- export const nullValue = NullValue.fromNothing();
package/src/index.js CHANGED
@@ -6,6 +6,7 @@ import Block from "./dom/block";
6
6
  import Error from "./dom/error";
7
7
  import Value from "./dom/value";
8
8
  import Values from "./dom/values";
9
+ import Ternary from "./dom/ternary";
9
10
  import Variable from "./dom/variable";
10
11
  import Condition from "./dom/condition";
11
12
  import Reference from "./dom/reference";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ class NullNode {
4
+ static fromNothing() {
5
+ const nullNode = new NullNode();
6
+
7
+ return nullNode;
8
+ }
9
+ }
10
+
11
+ const nullNode = NullNode.fromNothing();
12
+
13
+ export default nullNode;
14
+