occam-furtle 2.0.330 → 2.0.331

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 (43) hide show
  1. package/lib/element/expression/comparison.js +110 -0
  2. package/lib/element/expression.js +13 -13
  3. package/lib/element/term/bracketed.js +85 -0
  4. package/lib/element/term/comparison.js +110 -0
  5. package/lib/element/term/logical.js +118 -0
  6. package/lib/element/term/negated.js +102 -0
  7. package/lib/element/term.js +54 -3
  8. package/lib/element/ternary.js +7 -7
  9. package/lib/node/expression/comparison.js +163 -0
  10. package/lib/node/expression.js +8 -8
  11. package/lib/node/term/bracketed.js +116 -0
  12. package/lib/node/term/comparison.js +163 -0
  13. package/lib/node/term/logical.js +175 -0
  14. package/lib/node/term/negated.js +116 -0
  15. package/lib/node/term.js +39 -3
  16. package/lib/node/ternary.js +11 -18
  17. package/lib/nonTerminalNodeMap.js +10 -6
  18. package/lib/preamble.js +9 -5
  19. package/lib/ruleNames.js +21 -5
  20. package/lib/utilities/element.js +30 -30
  21. package/package.json +1 -1
  22. package/src/element/{comparison.js → expression/comparison.js} +8 -8
  23. package/src/element/expression.js +10 -10
  24. package/src/element/term/bracketed.js +36 -0
  25. package/src/element/term/comparison.js +69 -0
  26. package/src/element/term/logical.js +80 -0
  27. package/src/element/term/negated.js +59 -0
  28. package/src/element/term.js +46 -3
  29. package/src/element/ternary.js +5 -5
  30. package/src/node/{comparison.js → expression/comparison.js} +7 -7
  31. package/src/node/expression.js +9 -9
  32. package/src/node/term/bracketed.js +16 -0
  33. package/src/node/term/comparison.js +68 -0
  34. package/src/node/term/logical.js +80 -0
  35. package/src/node/term/negated.js +16 -0
  36. package/src/node/term.js +51 -2
  37. package/src/node/ternary.js +13 -20
  38. package/src/nonTerminalNodeMap.js +17 -5
  39. package/src/preamble.js +6 -2
  40. package/src/ruleNames.js +7 -2
  41. package/src/utilities/element.js +42 -42
  42. package/lib/element/comparison.js +0 -110
  43. package/lib/node/comparison.js +0 -163
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
 
3
- import Exception from "../exception";
3
+ import Exception from "../../exception";
4
4
 
5
- import { define } from "../elements";
6
- import { termFromBoolean } from "../utilities/term";
5
+ import { define } from "../../elements";
6
+ import { termFromBoolean } from "../../utilities/term";
7
7
 
8
- export default define(class Comparison {
8
+ export default define(class ComparisonExpression {
9
9
  constructor(string, negated, leftExpression, rightExpression) {
10
10
  this.string = string;
11
11
  this.negated = negated;
@@ -32,9 +32,9 @@ export default define(class Comparison {
32
32
  evaluate(context) {
33
33
  let term;
34
34
 
35
- const comparisonString = this.string; ///
35
+ const comparisonExpressionString = this.string; ///
36
36
 
37
- context.trace(`Evaluating the '${comparisonString}' comparison...`);
37
+ context.trace(`Evaluating the '${comparisonExpressionString}' comparison expression...`);
38
38
 
39
39
  const leftTerm = this.leftExpression.evaluate(context),
40
40
  rightTerm = this.rightExpression.evaluate(context),
@@ -60,10 +60,10 @@ export default define(class Comparison {
60
60
 
61
61
  term = termFromBoolean(boolean, context);
62
62
 
63
- context.debug(`...evaluated the '${comparisonString}' comparison.`);
63
+ context.debug(`...evaluated the '${comparisonExpressionString}' comparison expression.`);
64
64
 
65
65
  return term;
66
66
  }
67
67
 
68
- static name = "Comparison";
68
+ static name = "ComparisonExpression";
69
69
  });
@@ -3,7 +3,7 @@
3
3
  import { define } from "../elements";
4
4
 
5
5
  export default define(class Expression {
6
- constructor(string, variable, primitive, some, every, reduce, ternary, nodeQuery, nodesQuery, comparison, returnBlock, procedureCall, negatedExpression, logicalExpression, bracketedExpression) {
6
+ constructor(string, variable, primitive, some, every, reduce, ternary, nodeQuery, nodesQuery, returnBlock, procedureCall, negatedExpression, logicalExpression, bracketedExpression, comparisonExpression) {
7
7
  this.string = string;
8
8
  this.variable = variable;
9
9
  this.primitive = primitive;
@@ -13,12 +13,12 @@ export default define(class Expression {
13
13
  this.ternary = ternary;
14
14
  this.nodeQuery = nodeQuery;
15
15
  this.nodesQuery = nodesQuery;
16
- this.comparison = comparison;
17
16
  this.returnBlock = returnBlock;
18
17
  this.procedureCall = procedureCall;
19
18
  this.negatedExpression = negatedExpression;
20
19
  this.logicalExpression = logicalExpression;
21
20
  this.bracketedExpression = bracketedExpression;
21
+ this.comparisonExpression = comparisonExpression;
22
22
  }
23
23
 
24
24
  getString() {
@@ -57,10 +57,6 @@ export default define(class Expression {
57
57
  return this.nodesQuery;
58
58
  }
59
59
 
60
- getComparison() {
61
- return this.comparison;
62
- }
63
-
64
60
  getReturnBlock() {
65
61
  return this.returnBlock;
66
62
  }
@@ -81,6 +77,10 @@ export default define(class Expression {
81
77
  return this.bracketedExpression;
82
78
  }
83
79
 
80
+ getComparisonExpression() {
81
+ return this.comparisonExpression;
82
+ }
83
+
84
84
  getNode() { return this.primitive.getNode(); }
85
85
 
86
86
  getNodes() { return this.primitive.getNodes(); }
@@ -112,8 +112,6 @@ export default define(class Expression {
112
112
  type = this.nodeQuery.getType();
113
113
  } else if (this.nodesQuery !== null) {
114
114
  type = this.nodesQuery.getType();
115
- } else if (this.comparison !== null) {
116
- type = this.comparison.getType();
117
115
  } else if (this.returnBlock !== null) {
118
116
  type = this.returnBlock.getType();
119
117
  } else if (this.procedureCall !== null) {
@@ -124,6 +122,8 @@ export default define(class Expression {
124
122
  type = this.logicalExpression.getType();
125
123
  } else if (this.bracketedExpression !== null) {
126
124
  type = this.bracketedExpression.getType();
125
+ } else if (this.comparisonExpression !== null) {
126
+ type = this.comparisonExpression.getType();
127
127
  }
128
128
 
129
129
  return type;
@@ -150,8 +150,6 @@ export default define(class Expression {
150
150
  term = this.nodeQuery.evaluate(context);
151
151
  } else if (this.nodesQuery !== null) {
152
152
  term = this.nodesQuery.evaluate(context);
153
- } else if (this.comparison !== null) {
154
- term = this.comparison.evaluate(context);
155
153
  } else if (this.returnBlock !== null) {
156
154
  term = this.returnBlock.evaluate(context);
157
155
  } else if (this.procedureCall !== null) {
@@ -162,6 +160,8 @@ export default define(class Expression {
162
160
  term = this.logicalExpression.evaluate(context);
163
161
  } else if (this.bracketedExpression !== null) {
164
162
  term = this.bracketedExpression.evaluate(context);
163
+ } else if (this.comparisonExpression !== null) {
164
+ term = this.comparisonExpression.evaluate(context);
165
165
  }
166
166
 
167
167
  return term;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ import { define } from "../../elements";
4
+
5
+ export default define(class BracketedTerm {
6
+ constructor(string, term) {
7
+ this.string = string;
8
+ this.term = term;
9
+ }
10
+
11
+ getString() {
12
+ return this.string;
13
+ }
14
+
15
+ getTerm() {
16
+ return this.term;
17
+ }
18
+
19
+ getType() { return this.term.getType(); }
20
+
21
+ evaluate(context) {
22
+ let term;
23
+
24
+ const bracketedTermString = this.string; ///
25
+
26
+ context.trace(`Evaluating the '${bracketedTermString}' bracketed term...`);
27
+
28
+ term = this.term.evaluate(context);
29
+
30
+ context.debug(`...evaluated the '${bracketedTermString}' bracketed term.`);
31
+
32
+ return term;
33
+ }
34
+
35
+ static name = "BracketedTerm";
36
+ });
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ import Exception from "../../exception";
4
+
5
+ import { define } from "../../elements";
6
+ import { termFromBoolean } from "../../utilities/term";
7
+
8
+ export default define(class ComparisonTerm {
9
+ constructor(string, negated, leftTerm, rightTerm) {
10
+ this.string = string;
11
+ this.negated = negated;
12
+ this.leftTerm = leftTerm;
13
+ this.rightTerm = rightTerm;
14
+ }
15
+
16
+ getString() {
17
+ return this.string;
18
+ }
19
+
20
+ isNegated() {
21
+ return this.negated;
22
+ }
23
+
24
+ getLeftTerm() {
25
+ return this.leftTerm;
26
+ }
27
+
28
+ getRightTerm() {
29
+ return this.rightTerm;
30
+ }
31
+
32
+ evaluate(context) {
33
+ let term;
34
+
35
+ const comparisonTermString = this.string; ///
36
+
37
+ context.trace(`Evaluating the '${comparisonTermString}' comparison term...`);
38
+
39
+ const leftTerm = this.leftTerm.evaluate(context),
40
+ rightTerm = this.rightTerm.evaluate(context),
41
+ leftTermType = leftTerm.getType(),
42
+ rightTermType = rightTerm.getType();
43
+
44
+ if (leftTermType !== rightTermType) {
45
+ const leftTermString = leftTerm.getString(),
46
+ rightTermString = rightTerm.getString(),
47
+ message = `The '${leftTermString}' left term's type is '${leftTermType}' whereas the '${rightTermString}' right term's type is '${rightTermType}'.`,
48
+ exception = Exception.fromMessage(message);
49
+
50
+ throw exception;
51
+ }
52
+
53
+ const leftTermEqualToRightTerm = leftTerm.isEqualTo(rightTerm);
54
+
55
+ let boolean = leftTermEqualToRightTerm; ///
56
+
57
+ if (this.negated) {
58
+ boolean = !boolean; ///
59
+ }
60
+
61
+ term = termFromBoolean(boolean, context);
62
+
63
+ context.debug(`...evaluated the '${comparisonTermString}' comparison term.`);
64
+
65
+ return term;
66
+ }
67
+
68
+ static name = "ComparisonTerm";
69
+ });
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ import Exception from "../../exception";
4
+
5
+ import { define } from "../../elements";
6
+ import { BOOLEAN_TYPE } from "../../types";
7
+ import { termFromBoolean } from "../../utilities/term";
8
+
9
+ export default define(class LogicaTerm {
10
+ constructor(string, type, disjunction, leftTerm, rightTerm) {
11
+ this.string = string;
12
+ this.type = type;
13
+ this.disjunction = disjunction;
14
+ this.leftTerm = leftTerm;
15
+ this.rightTerm = rightTerm;
16
+ }
17
+
18
+ getString() {
19
+ return this.string;
20
+ }
21
+
22
+ getType() {
23
+ return this.type;
24
+ }
25
+
26
+ isDisjunction() {
27
+ return this.disjunction;
28
+ }
29
+
30
+ getLeftTerm() {
31
+ return this.leftTerm;
32
+ }
33
+
34
+ getRightTerm() {
35
+ return this.rightTerm;
36
+ }
37
+
38
+ evaluate(context) {
39
+ let term;
40
+
41
+ const logicaTermString = this.string; ///
42
+
43
+ context.trace(`Evaluating the '${logicaTermString}' logical term...`);
44
+
45
+ const leftTerm = this.leftTerm.evaluate(context),
46
+ rightTerm = this.rightTerm.evaluate(context),
47
+ leftTermType = leftTerm.getType(),
48
+ rightTermType = rightTerm.getType();
49
+
50
+ if (leftTermType !== BOOLEAN_TYPE) {
51
+ const leftTermString = leftTerm.getString(),
52
+ message = `The '${leftTermString}' left term's type is '${leftTermType}' when it should be of type '${BOOLEAN_TYPE}'.`,
53
+ exception = Exception.fromMessage(message);
54
+
55
+ throw exception;
56
+ }
57
+
58
+ if (rightTermType !== BOOLEAN_TYPE) {
59
+ const rightTermString = rightTerm.getString(),
60
+ message = `The '${rightTermString}' right term's type is '${rightTermType}' when it should be of type '${BOOLEAN_TYPE}'.`,
61
+ exception = Exception.fromMessage(message);
62
+
63
+ throw exception;
64
+ }
65
+
66
+ const leftTermBoolean = leftTerm.getBoolean(),
67
+ rightTermBoolean = rightTerm.getBoolean(),
68
+ boolean = this.disjunction ?
69
+ (leftTermBoolean || rightTermBoolean) :
70
+ (leftTermBoolean && rightTermBoolean);
71
+
72
+ term = termFromBoolean(boolean, context);
73
+
74
+ context.debug(`...evaluated the '${logicaTermString}' logical term.`);
75
+
76
+ return term;
77
+ }
78
+
79
+ static name = "LogicaTerm";
80
+ });
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ import Exception from "../../exception";
4
+
5
+ import { define } from "../../elements";
6
+ import { BOOLEAN_TYPE } from "../../types";
7
+ import { termFromBoolean } from "../../utilities/term";
8
+
9
+ export default define(class NegatedTerm {
10
+ constructor(string, type, term) {
11
+ this.string = string;
12
+ this.type = type;
13
+ this.term = term;
14
+ }
15
+
16
+ getString() {
17
+ return this.string;
18
+ }
19
+
20
+ getType() {
21
+ return this.type;
22
+ }
23
+
24
+ getTerm() {
25
+ return this.term;
26
+ }
27
+
28
+ evaluate(context) {
29
+ let term;
30
+
31
+ const negatedTermString = this.string; ///
32
+
33
+ context.trace(`Evaluating the '${negatedTermString}' negated term...`);
34
+
35
+ term = this.term.evaluate(context);
36
+
37
+ const termType = term.getType();
38
+
39
+ if (termType !== BOOLEAN_TYPE) {
40
+ const termString = term.getString(),
41
+ message = `The '${termString}' left term's type is '${termType}' when it should be of type '${BOOLEAN_TYPE}'.`,
42
+ exception = Exception.fromMessage(message);
43
+
44
+ throw exception;
45
+ }
46
+
47
+ let boolean = term.getBoolean();
48
+
49
+ boolean = !boolean;
50
+
51
+ term = termFromBoolean(boolean, context);
52
+
53
+ context.debug(`...evaluated the '${negatedTermString}' negated term.`);
54
+
55
+ return term;
56
+ }
57
+
58
+ static name = "NegatedTerm";
59
+ });
@@ -3,10 +3,14 @@
3
3
  import { define } from "../elements";
4
4
 
5
5
  export default define(class Term {
6
- constructor(string, variable, primitive) {
6
+ constructor(string, variable, primitive, negatedTerm, logicalTerm, bracketedTerm, comparisonTerm) {
7
7
  this.string = string;
8
8
  this.variable = variable;
9
9
  this.primitive = primitive;
10
+ this.negatedTerm = negatedTerm;
11
+ this.logicalTerm = logicalTerm;
12
+ this.bracketedTerm = bracketedTerm;
13
+ this.comparisonTerm = comparisonTerm;
10
14
  }
11
15
 
12
16
  getString() {
@@ -21,6 +25,22 @@ export default define(class Term {
21
25
  return this.primitive;
22
26
  }
23
27
 
28
+ getNegatedTerm() {
29
+ return this.negatedTerm;
30
+ }
31
+
32
+ getLogicalTerm() {
33
+ return this.logicalTerm;
34
+ }
35
+
36
+ getBreedingTerm() {
37
+ return this.bracketedTerm;
38
+ }
39
+
40
+ getComparisonTerm() {
41
+ return this.comparisonTerm;
42
+ }
43
+
24
44
  getNode() { return this.primitive.getNode(); }
25
45
 
26
46
  getNodes() { return this.primitive.getNodes(); }
@@ -40,6 +60,14 @@ export default define(class Term {
40
60
  type = this.variable.getType();
41
61
  } else if (this.primitive !== null) {
42
62
  type = this.primitive.getType();
63
+ } else if (this.negatedTerm !== null) {
64
+ type = this.negatedTerm.getType();
65
+ } else if (this.logicalTerm !== null) {
66
+ type = this.logicalTerm.getType();
67
+ } else if (this.bracketedTerm !== null) {
68
+ type = this.bracketedTerm.getType();
69
+ } else if (this.comparisonTerm !== null) {
70
+ type = this.comparisonTerm.getType();
43
71
  }
44
72
 
45
73
  return type;
@@ -54,14 +82,29 @@ export default define(class Term {
54
82
  term = this.variable.evaluate(context);
55
83
  } else if (this.primitive !== null) {
56
84
  term = this.primitive.evaluate(context);
85
+ } else if (this.negatedTerm !== null) {
86
+ term = this.negatedTerm.evaluate(context);
87
+ } else if (this.logicalTerm !== null) {
88
+ term = this.logicalTerm.evaluate(context);
89
+ } else if (this.bracketedTerm !== null) {
90
+ term = this.bracketedTerm.evaluate(context);
91
+ } else if (this.comparisonTerm !== null) {
92
+ term = this.comparisonTerm.evaluate(context);
57
93
  }
58
94
 
59
95
  return term;
60
96
  }
61
97
 
62
98
  isEqualTo(expression) {
63
- const primitive = expression.getPrimitive(),
64
- equalTo = this.primitive.isEqualTo(primitive);
99
+ let equalTo;
100
+
101
+ if (false) {
102
+ ///
103
+ } else if (this.variable !== null) {
104
+ equalTo = this.variable.isEqualTo();
105
+ } else if (this.primitive !== null) {
106
+ equalTo = this.primitive.isEqualTo();
107
+ }
65
108
 
66
109
  return equalTo;
67
110
  }
@@ -6,9 +6,9 @@ import { define } from "../elements";
6
6
  import { BOOLEAN_TYPE } from "../types";
7
7
 
8
8
  export default define(class Ternary {
9
- constructor(string, expression, ifExpression, elseExpression) {
9
+ constructor(string, term, ifExpression, elseExpression) {
10
10
  this.string = string;
11
- this.expression = expression;
11
+ this.term = term;
12
12
  this.ifExpression = ifExpression;
13
13
  this.elseExpression = elseExpression;
14
14
  }
@@ -17,8 +17,8 @@ export default define(class Ternary {
17
17
  return this.string;
18
18
  }
19
19
 
20
- getExpression() {
21
- return this.expression;
20
+ getTerm() {
21
+ return this.term;
22
22
  }
23
23
 
24
24
  getIfBlock() {
@@ -36,7 +36,7 @@ export default define(class Ternary {
36
36
 
37
37
  context.trace(`Evaluating the '${ternaryString}' ternary...`);
38
38
 
39
- term = this.expression.evaluate(context);
39
+ term = this.term.evaluate(context);
40
40
 
41
41
  const termType = term.getType();
42
42
 
@@ -2,15 +2,15 @@
2
2
 
3
3
  import { arrayUtilities } from "necessary";
4
4
 
5
- import NonTerminalNode from "../nonTerminalNode";
5
+ import ExpressionNode from "../../node/expression";
6
6
 
7
- import { NOT_EQUAL_TO } from "../constants";
8
- import { SPECIAL_TOKEN_TYPE } from "../tokenTypes";
9
- import { EXPRESSION_RULE_NAME } from "../ruleNames";
7
+ import { NOT_EQUAL_TO } from "../../constants";
8
+ import { SPECIAL_TOKEN_TYPE } from "../../tokenTypes";
9
+ import { EXPRESSION_RULE_NAME } from "../../ruleNames";
10
10
 
11
11
  const { first, second } = arrayUtilities;
12
12
 
13
- export default class ComparisonNode extends NonTerminalNode {
13
+ export default class ComparisonExpressionNode extends ExpressionNode {
14
14
  isNegated() {
15
15
  let negated = false;
16
16
 
@@ -31,7 +31,7 @@ export default class ComparisonNode extends NonTerminalNode {
31
31
 
32
32
  getExpressionNodes() {
33
33
  const ruleName = EXPRESSION_RULE_NAME,
34
- expressionNodes = this.getNodesByRuleName(ruleName);
34
+ expressionNodes = this.getNodesByRuleName(ruleName);
35
35
 
36
36
  return expressionNodes;
37
37
  }
@@ -64,5 +64,5 @@ export default class ComparisonNode extends NonTerminalNode {
64
64
  return secondExpressionNode;
65
65
  }
66
66
 
67
- static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return NonTerminalNode.fromRuleNameChildNodesOpacityAndPrecedence(ComparisonNode, ruleName, childNodes, opacity, precedence); }
67
+ static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return ExpressionNode.fromRuleNameChildNodesOpacityAndPrecedence(ComparisonExpressionNode, ruleName, childNodes, opacity, precedence); }
68
68
  }
@@ -8,14 +8,14 @@ import { SOME_RULE_NAME,
8
8
  TERNARY_RULE_NAME,
9
9
  VARIABLE_RULE_NAME,
10
10
  PRIMITIVE_RULE_NAME,
11
- COMPARISON_RULE_NAME,
12
11
  NODE_QUERY_RULE_NAME,
13
12
  NODES_QUERY_RULE_NAME,
14
13
  RETURN_BLOCK_RULE_NAME,
15
14
  PROCEDURE_CALL_RULE_NAME,
16
15
  NEGATED_EXPRESSION_RULE_NAME,
17
16
  LOGICAL_EXPRESSION_RULE_NAME,
18
- BRACKETED_EXPRESSION_RULE_NAME } from "../ruleNames";
17
+ BRACKETED_EXPRESSION_RULE_NAME,
18
+ COMPARISON_EXPRESSION_RULE_NAME } from "../ruleNames";
19
19
 
20
20
  export default class ExpressionNode extends NonTerminalNode {
21
21
  getSomeNode() {
@@ -74,13 +74,6 @@ export default class ExpressionNode extends NonTerminalNode {
74
74
  return nodeSQueryNode;
75
75
  }
76
76
 
77
- getComparisonNode() {
78
- const ruleName = COMPARISON_RULE_NAME,
79
- comparisonNode = this.getNodeByRuleName(ruleName);
80
-
81
- return comparisonNode;
82
- }
83
-
84
77
  getReturnBlockNode() {
85
78
  const ruleName = RETURN_BLOCK_RULE_NAME,
86
79
  returnBlockNode = this.getNodeByRuleName(ruleName);
@@ -116,6 +109,13 @@ export default class ExpressionNode extends NonTerminalNode {
116
109
  return bracketedExpressionRuleName;
117
110
  }
118
111
 
112
+ getComparisonExpressionNode() {
113
+ const ruleName = COMPARISON_EXPRESSION_RULE_NAME,
114
+ comparisonNode = this.getNodeByRuleName(ruleName);
115
+
116
+ return comparisonNode;
117
+ }
118
+
119
119
  static fromRuleNameChildNodesOpacityAndPrecedence(Class, ruleName, childNodes, opacity, precedence) {
120
120
  if (precedence === undefined) {
121
121
  precedence = opacity; ///
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ import TermNode from "../../node/term";
4
+
5
+ import { TERM_RULE_NAME } from "../../ruleNames";
6
+
7
+ export default class BracketedTermNode extends TermNode {
8
+ getTermNode() {
9
+ const ruleName = TERM_RULE_NAME,
10
+ termNode = this.getNodeByRuleName(ruleName);
11
+
12
+ return termNode;
13
+ }
14
+
15
+ static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return TermNode.fromRuleNameChildNodesOpacityAndPrecedence(BracketedTermNode, ruleName, childNodes, opacity, precedence); }
16
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ import { arrayUtilities } from "necessary";
4
+
5
+ import TermNode from "../../node/term";
6
+
7
+ import { NOT_EQUAL_TO } from "../../constants";
8
+ import { TERM_RULE_NAME } from "../../ruleNames";
9
+ import { SPECIAL_TOKEN_TYPE } from "../../tokenTypes";
10
+
11
+ const { first, second } = arrayUtilities;
12
+
13
+ export default class ComparisonTermNode extends TermNode {
14
+ isNegated() {
15
+ let negated = false;
16
+
17
+ const tokenType = SPECIAL_TOKEN_TYPE;
18
+
19
+ this.someTerminalNode((terminalNode) => {
20
+ const content = terminalNode.getContent();
21
+
22
+ if (content === NOT_EQUAL_TO) {
23
+ negated = true;
24
+ }
25
+
26
+ return true;
27
+ }, tokenType);
28
+
29
+ return negated;
30
+ }
31
+
32
+ getTermNodes() {
33
+ const ruleName = TERM_RULE_NAME,
34
+ termNodes = this.getNodesByRuleName(ruleName);
35
+
36
+ return termNodes;
37
+ }
38
+
39
+ getLeftTermNode() {
40
+ const firstTermNode = this.getFirstTermNode(),
41
+ leftTermNode = firstTermNode; ///
42
+
43
+ return leftTermNode;
44
+ }
45
+
46
+ getRightTermNode() {
47
+ const secondTermNode = this.getSecondTermNode(),
48
+ rightTermNode = secondTermNode; ///
49
+
50
+ return rightTermNode;
51
+ }
52
+
53
+ getFirstTermNode() {
54
+ const termNodes = this.getTermNodes(),
55
+ firstTermNode = first(termNodes);
56
+
57
+ return firstTermNode;
58
+ }
59
+
60
+ getSecondTermNode() {
61
+ const termNodes = this.getTermNodes(),
62
+ secondTermNode = second(termNodes);
63
+
64
+ return secondTermNode;
65
+ }
66
+
67
+ static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return TermNode.fromRuleNameChildNodesOpacityAndPrecedence(ComparisonTermNode, ruleName, childNodes, opacity, precedence); }
68
+ }