occam-furtle 2.0.120 → 2.0.122

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 (67) hide show
  1. package/lib/dom/assignment/array.js +12 -12
  2. package/lib/dom/assignment/object.js +30 -30
  3. package/lib/dom/assignment/variable.js +13 -13
  4. package/lib/dom/block/return.js +9 -9
  5. package/lib/dom/comparison.js +28 -28
  6. package/lib/dom/every.js +25 -25
  7. package/lib/dom/expression/bitwise.js +186 -0
  8. package/lib/dom/expression/bracketed.js +149 -0
  9. package/lib/dom/expression/negated.js +166 -0
  10. package/lib/dom/expression.js +578 -0
  11. package/lib/dom/expressions.js +210 -0
  12. package/lib/dom/parameter/named.js +9 -9
  13. package/lib/dom/parameter.js +9 -9
  14. package/lib/dom/parameters/named.js +11 -11
  15. package/lib/dom/parameters.js +11 -11
  16. package/lib/dom/procedure/anonymous.js +7 -7
  17. package/lib/dom/procedure.js +12 -12
  18. package/lib/dom/procedureCall.js +17 -17
  19. package/lib/dom/query/node.js +19 -19
  20. package/lib/dom/query/nodes.js +19 -19
  21. package/lib/dom/reduce.js +32 -32
  22. package/lib/dom/some.js +25 -25
  23. package/lib/dom/statement/return.js +12 -12
  24. package/lib/dom/ternary.js +27 -27
  25. package/lib/dom/variable.js +30 -30
  26. package/lib/example/utilities/expressions.js +29 -0
  27. package/lib/example.js +4 -4
  28. package/lib/index.js +9 -9
  29. package/package.json +1 -1
  30. package/src/dom/assignment/array.js +14 -14
  31. package/src/dom/assignment/object.js +33 -33
  32. package/src/dom/assignment/variable.js +15 -15
  33. package/src/dom/block/return.js +7 -7
  34. package/src/dom/comparison.js +39 -39
  35. package/src/dom/every.js +25 -25
  36. package/src/dom/expression/bitwise.js +135 -0
  37. package/src/dom/expression/bracketed.js +73 -0
  38. package/src/dom/expression/negated.js +97 -0
  39. package/src/dom/{value.js → expression.js} +128 -128
  40. package/src/dom/expressions.js +138 -0
  41. package/src/dom/parameter/named.js +7 -7
  42. package/src/dom/parameter.js +7 -7
  43. package/src/dom/parameters/named.js +9 -9
  44. package/src/dom/parameters.js +9 -9
  45. package/src/dom/procedure/anonymous.js +10 -10
  46. package/src/dom/procedure.js +12 -12
  47. package/src/dom/procedureCall.js +19 -19
  48. package/src/dom/query/node.js +19 -19
  49. package/src/dom/query/nodes.js +19 -19
  50. package/src/dom/reduce.js +36 -36
  51. package/src/dom/some.js +25 -25
  52. package/src/dom/statement/return.js +14 -14
  53. package/src/dom/ternary.js +39 -39
  54. package/src/dom/variable.js +31 -31
  55. package/src/example/utilities/{values.js → expressions.js} +4 -4
  56. package/src/example.js +4 -4
  57. package/src/index.js +6 -6
  58. package/lib/dom/value/bitwise.js +0 -186
  59. package/lib/dom/value/bracketed.js +0 -149
  60. package/lib/dom/value/negated.js +0 -166
  61. package/lib/dom/value.js +0 -578
  62. package/lib/dom/values.js +0 -210
  63. package/lib/example/utilities/values.js +0 -29
  64. package/src/dom/value/bitwise.js +0 -135
  65. package/src/dom/value/bracketed.js +0 -73
  66. package/src/dom/value/negated.js +0 -97
  67. package/src/dom/values.js +0 -138
@@ -5,10 +5,10 @@ import dom from "../../dom";
5
5
  import { domAssigned } from "../../dom";
6
6
 
7
7
  export default domAssigned(class VariableAssignment {
8
- constructor(string, variable, value) {
8
+ constructor(string, variable, expression) {
9
9
  this.string = string;
10
10
  this.variable = variable;
11
- this.value = value;
11
+ this.expression = expression;
12
12
  }
13
13
 
14
14
  getString() {
@@ -19,24 +19,24 @@ export default domAssigned(class VariableAssignment {
19
19
  return this.variable;
20
20
  }
21
21
 
22
- getValue() {
23
- return this.value;
22
+ getExpression() {
23
+ return this.expression;
24
24
  }
25
25
 
26
26
  evaluate(context) {
27
- let value;
27
+ let expression;
28
28
 
29
29
  const variableAssignmentString = this.string; ///
30
30
 
31
31
  context.trace(`Evaluating the '${variableAssignmentString}' variable assignment...`);
32
32
 
33
- value = this.value.evaluate(context);
33
+ expression = this.expression.evaluate(context);
34
34
 
35
- this.variable.assign(value, context);
35
+ this.variable.assign(expression, context);
36
36
 
37
37
  context.debug(`...evaluated the '${variableAssignmentString}' variable assignment.`);
38
38
 
39
- return value;
39
+ return expression;
40
40
  }
41
41
 
42
42
  static name = "VariableAssignment";
@@ -49,19 +49,19 @@ export default domAssigned(class VariableAssignment {
49
49
  });
50
50
 
51
51
  function variableAssignmentFromTypeAndVariableAssignmentNode(type, variableAssignmentNode, context) {
52
- const { Variable, Value, VariableAssignment } = dom,
53
- value = Value.fromVariableAssignmentNode(variableAssignmentNode, context),
52
+ const { Variable, Expression, VariableAssignment } = dom,
53
+ expression = Expression.fromVariableAssignmentNode(variableAssignmentNode, context),
54
54
  variable = Variable.fromTypeAndVariableAssignmentNode(type, variableAssignmentNode, context),
55
- string = stringFromValueAndVariable(value, variable, context),
56
- assignment = new VariableAssignment(string, variable, value);
55
+ string = stringFromExpressionAndVariable(expression, variable, context),
56
+ assignment = new VariableAssignment(string, variable, expression);
57
57
 
58
58
  return assignment;
59
59
  }
60
60
 
61
- function stringFromValueAndVariable(value, variable, context) {
61
+ function stringFromExpressionAndVariable(expression, variable, context) {
62
62
  const variableString = variable.getString(),
63
- valueString = value.asString(context),
64
- string = `${variableString} = ${valueString};`;
63
+ expressionString = expression.asString(context),
64
+ string = `${variableString} = ${expressionString};`;
65
65
 
66
66
  return string;
67
67
  }
@@ -9,7 +9,7 @@ import { nodeQuery, nodesQuery } from "../../utilities/query";
9
9
 
10
10
  const stepNodesQuery = nodesQuery("/returnBlock/step"),
11
11
  nonsenseNodesQuery = nodesQuery("/returnBlock/nonsense"),
12
- valueReturnBlockNodeQuery = nodeQuery("/value/returnBlock"),
12
+ expressionReturnBlockNodeQuery = nodeQuery("/expression/returnBlock"),
13
13
  anonymousProcedureReturnBlockNodeQuery = nodeQuery("/anonymousProcedure/returnBlock"),
14
14
  procedureDeclarationReturnBlockNodeQuery = nodeQuery("/procedureDeclaration/returnBlock");
15
15
 
@@ -59,20 +59,20 @@ export default domAssigned(class ReturnBlock {
59
59
  step.evaluate(context);
60
60
  });
61
61
 
62
- const value = this.returnStatement.evaluate(context);
62
+ const expression = this.returnStatement.evaluate(context);
63
63
 
64
- return value;
64
+ return expression;
65
65
  }
66
66
 
67
67
  static name = "ReturnBlock";
68
68
 
69
- static fromValueNode(valueNode, context) {
69
+ static fromExpressionNode(expressionNode, context) {
70
70
  let returnBlock = null;
71
71
 
72
- const valueReturnBlockNode = valueReturnBlockNodeQuery(valueNode);
72
+ const expressionReturnBlockNode = expressionReturnBlockNodeQuery(expressionNode);
73
73
 
74
- if (valueReturnBlockNode !== null) {
75
- const returnBlockNode = valueReturnBlockNode; ///
74
+ if (expressionReturnBlockNode !== null) {
75
+ const returnBlockNode = expressionReturnBlockNode; ///
76
76
 
77
77
  returnBlock = returnBlockFromReturnBlockNode(returnBlockNode, context);
78
78
  }
@@ -8,16 +8,16 @@ import { domAssigned } from "../dom";
8
8
  import { EQUAL_TO, NOT_EQUAL_TO } from "../constants";
9
9
 
10
10
  const terminalNodeQuery = nodeQuery("/comparison/@*"),
11
- leftValueNodeQuery = nodeQuery("/comparison/value[0]"),
12
- rightValueNodeQuery = nodeQuery("/comparison/value[1]"),
13
- valueComparisonNodeQuery = nodeQuery("/value/comparison");
11
+ leftExpressionNodeQuery = nodeQuery("/comparison/expression[0]"),
12
+ rightExpressionNodeQuery = nodeQuery("/comparison/expression[1]"),
13
+ expressionComparisonNodeQuery = nodeQuery("/expression/comparison");
14
14
 
15
15
  export default domAssigned(class Comparison {
16
- constructor(string, negated, leftValue, rightValue) {
16
+ constructor(string, negated, leftExpression, rightExpression) {
17
17
  this.string = string;
18
18
  this.negated = negated;
19
- this.leftValue = leftValue;
20
- this.rightValue = rightValue;
19
+ this.leftExpression = leftExpression;
20
+ this.rightExpression = rightExpression;
21
21
  }
22
22
 
23
23
  getString() {
@@ -28,61 +28,61 @@ export default domAssigned(class Comparison {
28
28
  return this.negated;
29
29
  }
30
30
 
31
- getLeftValue() {
32
- return this.leftValue;
31
+ getLeftExpression() {
32
+ return this.leftExpression;
33
33
  }
34
34
 
35
- getRightValue() {
36
- return this.rightValue;
35
+ getRightExpression() {
36
+ return this.rightExpression;
37
37
  }
38
38
 
39
39
  evaluate(context) {
40
- let value;
40
+ let expression;
41
41
 
42
42
  const comparisonString = this.string; ///
43
43
 
44
44
  context.trace(`Evaluating the '${comparisonString}' comparison...`);
45
45
 
46
- const leftValue = this.leftValue.evaluate(context),
47
- rightValue = this.rightValue.evaluate(context),
48
- leftValueType = leftValue.getType(),
49
- rightValueType = rightValue.getType();
46
+ const leftExpression = this.leftExpression.evaluate(context),
47
+ rightExpression = this.rightExpression.evaluate(context),
48
+ leftExpressionType = leftExpression.getType(),
49
+ rightExpressionType = rightExpression.getType();
50
50
 
51
- if (leftValueType !== rightValueType) {
52
- const leftValueString = leftValue.asString(context),
53
- rightValueString = rightValue.asString(context),
54
- message = `The ${leftValueString} left value's type is '${leftValueType}' whereas the ${rightValueString} right value's type is '${rightValueType}'.`,
51
+ if (leftExpressionType !== rightExpressionType) {
52
+ const leftExpressionString = leftExpression.asString(context),
53
+ rightExpressionString = rightExpression.asString(context),
54
+ message = `The ${leftExpressionString} left expression's type is '${leftExpressionType}' whereas the ${rightExpressionString} right expression's type is '${rightExpressionType}'.`,
55
55
  exception = Exception.fromMessage(message);
56
56
 
57
57
  throw exception;
58
58
  }
59
59
 
60
- const leftValueEqualToRightValue = leftValue.isEqualTo(rightValue);
60
+ const leftExpressionEqualToRightExpression = leftExpression.isEqualTo(rightExpression);
61
61
 
62
- let boolean = leftValueEqualToRightValue; ///
62
+ let boolean = leftExpressionEqualToRightExpression; ///
63
63
 
64
64
  if (this.negated) {
65
65
  boolean = !boolean; ///
66
66
  }
67
67
 
68
- const { Value } = dom;
68
+ const { Expression } = dom;
69
69
 
70
- value = Value.fromBoolean(boolean, context);
70
+ expression = Expression.fromBoolean(boolean, context);
71
71
 
72
72
  context.debug(`...evaluated the '${comparisonString}' comparison.`);
73
73
 
74
- return value;
74
+ return expression;
75
75
  }
76
76
 
77
77
  static name = "Comparison";
78
78
 
79
- static fromValueNode(valudNode, context) {
79
+ static fromExpressionNode(valudNode, context) {
80
80
  let comparison = null;
81
81
 
82
- const valueComparisonNode = valueComparisonNodeQuery(valudNode);
82
+ const expressionComparisonNode = expressionComparisonNodeQuery(valudNode);
83
83
 
84
- if (valueComparisonNode !== null) {
85
- const comparisonNode = valueComparisonNode; ///
84
+ if (expressionComparisonNode !== null) {
85
+ const comparisonNode = expressionComparisonNode; ///
86
86
 
87
87
  comparison = comparisonFromComparisonNode(comparisonNode, context);
88
88
  }
@@ -100,25 +100,25 @@ function negatedFromComparisonNode(comparisonNode) {
100
100
  }
101
101
 
102
102
  function comparisonFromComparisonNode(comparisonNode, context) {
103
- const { Value, Comparison } = dom,
104
- leftValueNode = leftValueNodeQuery(comparisonNode),
105
- rightValueNode = rightValueNodeQuery(comparisonNode),
106
- rightValue = Value.fromValueNode(rightValueNode, context),
107
- leftValue = Value.fromValueNode(leftValueNode, context),
103
+ const { Expression, Comparison } = dom,
104
+ leftExpressionNode = leftExpressionNodeQuery(comparisonNode),
105
+ rightExpressionNode = rightExpressionNodeQuery(comparisonNode),
106
+ rightExpression = Expression.fromExpressionNode(rightExpressionNode, context),
107
+ leftExpression = Expression.fromExpressionNode(leftExpressionNode, context),
108
108
  negated = negatedFromComparisonNode(comparisonNode, context),
109
- string = stringFromNegatedLeftValueAndRightValue(negated, leftValue, rightValue, context),
110
- comparison = new Comparison(string, negated, leftValue, rightValue);
109
+ string = stringFromNegatedLeftExpressionAndRightExpression(negated, leftExpression, rightExpression, context),
110
+ comparison = new Comparison(string, negated, leftExpression, rightExpression);
111
111
 
112
112
  return comparison;
113
113
  }
114
114
 
115
- function stringFromNegatedLeftValueAndRightValue(negated, leftValue, rightValue, context) {
115
+ function stringFromNegatedLeftExpressionAndRightExpression(negated, leftExpression, rightExpression, context) {
116
116
  const operatorString = negated ?
117
117
  EQUAL_TO :
118
118
  NOT_EQUAL_TO,
119
- leftValueString = leftValue.asString(context),
120
- rightValueString = rightValue.asString(context),
121
- string = `${leftValueString} ${operatorString} ${rightValueString}`;
119
+ leftExpressionString = leftExpression.asString(context),
120
+ rightExpressionString = rightExpression.asString(context),
121
+ string = `${leftExpressionString} ${operatorString} ${rightExpressionString}`;
122
122
 
123
123
  return string;
124
124
  }
package/src/dom/every.js CHANGED
@@ -7,7 +7,7 @@ import { nodeQuery } from "../utilities/query";
7
7
  import { domAssigned } from "../dom";
8
8
  import { NODES_TYPE, BOOLEAN_TYPE } from "../types";
9
9
 
10
- const valueEveryNodeQuery = nodeQuery("/value/every");
10
+ const expressionEveryNodeQuery = nodeQuery("/expression/every");
11
11
 
12
12
  export default domAssigned(class Every {
13
13
  constructor(string, variable, anonymousProcedure) {
@@ -29,69 +29,69 @@ export default domAssigned(class Every {
29
29
  }
30
30
 
31
31
  evaluate(context) {
32
- let value;
32
+ let expression;
33
33
 
34
34
  const everyString = this.getString();
35
35
 
36
36
  context.trace(`Evaluating the '${everyString}' every...`);
37
37
 
38
- value = this.variable.evaluate(context);
38
+ expression = this.variable.evaluate(context);
39
39
 
40
- const valueType = value.getType();
40
+ const expressionType = expression.getType();
41
41
 
42
- if (valueType !== NODES_TYPE) {
43
- const valueString = value.asString(context),
44
- message = `The ${valueString} value's '${valueType}' type should be '${NODES_TYPE}'.`,
42
+ if (expressionType !== NODES_TYPE) {
43
+ const expressionString = expression.asString(context),
44
+ message = `The ${expressionString} expression's '${expressionType}' type should be '${NODES_TYPE}'.`,
45
45
  exception = Exception.fromMessage(message);
46
46
 
47
47
  throw exception;
48
48
  }
49
49
 
50
- const nodes = value.getNodes(),
50
+ const nodes = expression.getNodes(),
51
51
  boolean = nodes.every((node) => {
52
- let value;
52
+ let expression;
53
53
 
54
- const { Value, Values } = dom;
54
+ const { Expression, Expressions } = dom;
55
55
 
56
- value = Value.fromNode(node, context);
56
+ expression = Expression.fromNode(node, context);
57
57
 
58
- const values = Values.fromValue(value, context);
58
+ const expressions = Expressions.fromExpression(expression, context);
59
59
 
60
- value = this.anonymousProcedure.call(values, context);
60
+ expression = this.anonymousProcedure.call(expressions, context);
61
61
 
62
- const valueType = value.getType();
62
+ const expressionType = expression.getType();
63
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}'.`,
64
+ if (expressionType !== BOOLEAN_TYPE) {
65
+ const expressionString = expression.asString(context),
66
+ message = `The ${expressionString} expression's type is '${expressionType}' when it should be of type '${BOOLEAN_TYPE}'.`,
67
67
  exception = Exception.fromMessage(message);
68
68
 
69
69
  throw exception;
70
70
  }
71
71
 
72
- const boolean = value.getBoolean();
72
+ const boolean = expression.getBoolean();
73
73
 
74
74
  return boolean;
75
75
  });
76
76
 
77
- const { Value } = dom;
77
+ const { Expression } = dom;
78
78
 
79
- value = Value.fromBoolean(boolean, context);
79
+ expression = Expression.fromBoolean(boolean, context);
80
80
 
81
81
  context.trace(`...evaluated the '${everyString}' every.`);
82
82
 
83
- return value;
83
+ return expression;
84
84
  }
85
85
 
86
86
  static name = "Every";
87
87
 
88
- static fromValueNode(valueNode, context) {
88
+ static fromExpressionNode(expressionNode, context) {
89
89
  let every = null;
90
90
 
91
- const valueEveryNode = valueEveryNodeQuery(valueNode);
91
+ const expressionEveryNode = expressionEveryNodeQuery(expressionNode);
92
92
 
93
- if (valueEveryNode !== null) {
94
- const everyNode = valueEveryNode; ///
93
+ if (expressionEveryNode !== null) {
94
+ const everyNode = expressionEveryNode; ///
95
95
 
96
96
  every = everyFromEveryNode(everyNode, context);
97
97
  }
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ import dom from "../../dom";
4
+ import Exception from "../../exception";
5
+
6
+ import { nodeQuery } from "../../utilities/query";
7
+ import { domAssigned } from "../../dom";
8
+ import { BOOLEAN_TYPE } from "../../types";
9
+ import { CONJUNCTION, DISJUNCTION } from "../../constants";
10
+
11
+ const terminalNodeQuery = nodeQuery("/bitwiseExpression/@*"),
12
+ leftExpressionNodeQuery = nodeQuery("/bitwiseExpression/expression[0]"),
13
+ rightExpressionNodeQuery = nodeQuery("/bitwiseExpression/expression[1]"),
14
+ expressionBitwiseExpressionNodeQuery = nodeQuery("/expression/bitwiseExpression");
15
+
16
+ export default domAssigned(class BitwiseExpression {
17
+ constructor(string, type, disjoint, leftExpression, rightExpression) {
18
+ this.string = string;
19
+ this.type = type;
20
+ this.disjoint = disjoint;
21
+ this.leftExpression = leftExpression;
22
+ this.rightExpression = rightExpression;
23
+ }
24
+
25
+ getString() {
26
+ return this.string;
27
+ }
28
+
29
+ getType() {
30
+ return this.type;
31
+ }
32
+
33
+ isDisjoint() {
34
+ return this.disjoint;
35
+ }
36
+
37
+ getLeftExpression() {
38
+ return this.leftExpression;
39
+ }
40
+
41
+ getRightExpression() {
42
+ return this.rightExpression;
43
+ }
44
+
45
+ evaluate(context) {
46
+ let expression;
47
+
48
+ const bitwiseExpressionString = this.string; ///
49
+
50
+ context.trace(`Evaluating the '${bitwiseExpressionString}' bitwise expression...`);
51
+
52
+ const { Expression } = dom,
53
+ leftExpression = this.leftExpression.evaluate(context),
54
+ rightExpression = this.rightExpression.evaluate(context),
55
+ leftExpressionType = leftExpression.getType(),
56
+ rightExpressionType = rightExpression.getType();
57
+
58
+ if (leftExpressionType !== BOOLEAN_TYPE) {
59
+ const leftExpressionString = leftExpression.asString(context),
60
+ message = `The ${leftExpressionString} left expression's type is '${leftExpressionType}' when it should be of type '${BOOLEAN_TYPE}'.`,
61
+ exception = Exception.fromMessage(message);
62
+
63
+ throw exception;
64
+ }
65
+
66
+ if (rightExpressionType !== BOOLEAN_TYPE) {
67
+ const rightExpressionString = rightExpression.asString(context),
68
+ message = `The ${rightExpressionString} right expression's type is '${rightExpressionType}' when it should be of type '${BOOLEAN_TYPE}'.`,
69
+ exception = Exception.fromMessage(message);
70
+
71
+ throw exception;
72
+ }
73
+
74
+ const leftExpressionBoolean = leftExpression.getBoolean(),
75
+ rightExpressionBoolean = rightExpression.getBoolean(),
76
+ boolean = this.disjoint ?
77
+ (leftExpressionBoolean || rightExpressionBoolean) :
78
+ (leftExpressionBoolean && rightExpressionBoolean);
79
+
80
+ expression = Expression.fromBoolean(boolean, context); ///
81
+
82
+ context.debug(`...evaluated the '${bitwiseExpressionString}' bitwise expression.`);
83
+
84
+ return expression;
85
+ }
86
+
87
+ static name = "BitwiseExpression";
88
+
89
+ static fromExpressionNode(expressionNode, context) {
90
+ let bitwiseExpression = null;
91
+
92
+ const expressionBitwiseExpressionNode = expressionBitwiseExpressionNodeQuery(expressionNode);
93
+
94
+ if (expressionBitwiseExpressionNode !== null) {
95
+ const bitwiseExpressionNode = expressionBitwiseExpressionNode; ///
96
+
97
+ bitwiseExpression = bitwiseExpressionFromBitwiseExpressionNode(bitwiseExpressionNode, context);
98
+ }
99
+
100
+ return bitwiseExpression;
101
+ }
102
+ });
103
+
104
+ function bitwiseExpressionFromBitwiseExpressionNode(bitwiseExpressionNode, context) {
105
+ const { Expression, BitwiseExpression } = dom,
106
+ leftExpressionNode = leftExpressionNodeQuery(bitwiseExpressionNode),
107
+ rightExpressionNode = rightExpressionNodeQuery(bitwiseExpressionNode),
108
+ type = BOOLEAN_TYPE,
109
+ disjoint = disjointFromBitwiseExpressionNode(bitwiseExpressionNode, context),
110
+ leftExpression = Expression.fromExpressionNode(leftExpressionNode, context),
111
+ rightExpression = Expression.fromExpressionNode(rightExpressionNode, context),
112
+ string = stringFromTypeDisjointLeftExpressionAndRightExpression(disjoint, leftExpression, rightExpression, context),
113
+ bitwiseExpression = new BitwiseExpression(string, type, disjoint, leftExpression, rightExpression);
114
+
115
+ return bitwiseExpression;
116
+ }
117
+
118
+ function disjointFromBitwiseExpressionNode(bitwiseExpressionNode, context) {
119
+ const terminalNode = terminalNodeQuery(bitwiseExpressionNode),
120
+ terminalNodeContent = terminalNode.getContent(),
121
+ disjoint = (terminalNodeContent === DISJUNCTION);
122
+
123
+ return disjoint;
124
+ }
125
+
126
+ function stringFromTypeDisjointLeftExpressionAndRightExpression(disjoint, leftExpression, rightExpression, context) {
127
+ const operatorString = disjoint ?
128
+ DISJUNCTION :
129
+ CONJUNCTION,
130
+ leftExpressionString = leftExpression.asString(context),
131
+ rightExpressionString = rightExpression.asString(context),
132
+ string = `${leftExpressionString} ${operatorString} ${rightExpressionString}`;
133
+
134
+ return string;
135
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ import dom from "../../dom";
4
+
5
+ import { nodeQuery } from "../../utilities/query";
6
+ import { domAssigned } from "../../dom";
7
+
8
+ const expressionNodeQuery = nodeQuery("/bracketedExpression/expression"),
9
+ expressionBracketedExpressionNodeQuery = nodeQuery("/expression/bracketedExpression");
10
+
11
+ export default domAssigned(class BracketedExpression {
12
+ constructor(string, expression) {
13
+ this.string = string;
14
+ this.expression = expression;
15
+ }
16
+
17
+ getString() {
18
+ return this.string;
19
+ }
20
+
21
+ getExpression() {
22
+ return this.expression;
23
+ }
24
+
25
+ getType() { return this.expression.getType(); }
26
+
27
+ evaluate(context) {
28
+ let expression;
29
+
30
+ const bracketedExpressionString = this.string; ///
31
+
32
+ context.trace(`Evaluating the '${bracketedExpressionString}' bracketed expression...`);
33
+
34
+ expression = this.expression.evaluate(context);
35
+
36
+ context.debug(`...evaluated the '${bracketedExpressionString}' bracketed expression.`);
37
+
38
+ return expression;
39
+ }
40
+
41
+ static name = "BracketedExpression";
42
+
43
+ static fromExpressionNode(expressionNode, context) {
44
+ let bracketedExpression = null;
45
+
46
+ const expressionBracketedExpressionNode = expressionBracketedExpressionNodeQuery(expressionNode);
47
+
48
+ if (expressionBracketedExpressionNode !== null) {
49
+ const bracketedExpressionNode = expressionBracketedExpressionNode; ///
50
+
51
+ bracketedExpression = bracketedExpressionFromBracketedExpressionNode(bracketedExpressionNode, context);
52
+ }
53
+
54
+ return bracketedExpression;
55
+ }
56
+ });
57
+
58
+ function bracketedExpressionFromBracketedExpressionNode(bracketedExpressionNode, context) {
59
+ const { Expression, BracketedExpression } = dom,
60
+ expressionNode = expressionNodeQuery(bracketedExpressionNode),
61
+ expression = Expression.fromExpressionNode(expressionNode, context),
62
+ string = stringFromExpression(expression, context),
63
+ bracketedExpression = new BracketedExpression(string, expression);
64
+
65
+ return bracketedExpression;
66
+ }
67
+
68
+ function stringFromExpression(expression, context) {
69
+ const expressionString = expression.asString(context),
70
+ string = `(${expressionString})`;
71
+
72
+ return string;
73
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ import dom from "../../dom";
4
+ import Exception from "../../exception";
5
+
6
+ import { nodeQuery } from "../../utilities/query";
7
+ import { domAssigned } from "../../dom";
8
+ import { BOOLEAN_TYPE } from "../../types";
9
+
10
+ const expressionNodeQuery = nodeQuery("/negatedExpression/expression"),
11
+ expressionNegatedExpressionNodeQuery = nodeQuery("/expression/negatedExpression");
12
+
13
+ export default domAssigned(class NegatedExpression {
14
+ constructor(string, type, expression) {
15
+ this.string = string;
16
+ this.type = type;
17
+ this.expression = expression;
18
+ }
19
+
20
+ getString() {
21
+ return this.string;
22
+ }
23
+
24
+ getType() {
25
+ return this.type;
26
+ }
27
+
28
+ getExpression() {
29
+ return this.expression;
30
+ }
31
+
32
+ evaluate(context) {
33
+ let expression;
34
+
35
+ const negatedExpressionString = this.string; ///
36
+
37
+ context.trace(`Evaluating the '${negatedExpressionString}' negated expression...`);
38
+
39
+ expression = this.expression.evaluate(context);
40
+
41
+ const expressionType = expression.getType();
42
+
43
+ if (expressionType !== BOOLEAN_TYPE) {
44
+ const expressionString = expression.asString(context),
45
+ message = `The ${expressionString} left expression's type is '${expressionType}' when it should be of type '${BOOLEAN_TYPE}'.`,
46
+ exception = Exception.fromMessage(message);
47
+
48
+ throw exception;
49
+ }
50
+
51
+ let boolean = expression.getBoolean();
52
+
53
+ boolean = !boolean;
54
+
55
+ const { Expression } = dom;
56
+
57
+ expression = Expression.fromBoolean(boolean, context); ///
58
+
59
+ context.debug(`...evaluated the '${negatedExpressionString}' negated expression.`);
60
+
61
+ return expression;
62
+ }
63
+
64
+ static name = "NegatedExpression";
65
+
66
+ static fromExpressionNode(expressionNode, context) {
67
+ let negatedExpression = null;
68
+
69
+ const expressionNegatedExpressionNode = expressionNegatedExpressionNodeQuery(expressionNode);
70
+
71
+ if (expressionNegatedExpressionNode !== null) {
72
+ const negatedExpressionNode = expressionNegatedExpressionNode; ///
73
+
74
+ negatedExpression = negatedExpressionFromNegatedExpressionNode(negatedExpressionNode, context);
75
+ }
76
+
77
+ return negatedExpression;
78
+ }
79
+ });
80
+
81
+ function negatedExpressionFromNegatedExpressionNode(negatedExpressionNode, context) {
82
+ const { Expression, NegatedExpression } = dom,
83
+ expressionNode = expressionNodeQuery(negatedExpressionNode),
84
+ expression = Expression.fromExpressionNode(expressionNode, context),
85
+ type = BOOLEAN_TYPE,
86
+ string = stringFromExpression(expression, context),
87
+ negatedExpression = new NegatedExpression(string, type, expression);
88
+
89
+ return negatedExpression;
90
+ }
91
+
92
+ function stringFromExpression(expression, context) {
93
+ const expressionString = expression.asString(context),
94
+ string = `!${expressionString}`;
95
+
96
+ return string;
97
+ }