-
Notifications
You must be signed in to change notification settings - Fork 0
/
internalNode.js
48 lines (41 loc) · 1.24 KB
/
internalNode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2019-2021 Jonathan Wood (www.softcircuits.com)
// Copyright (c) 2020-2022 Ronald M. Clifford
// Licensed under the MIT license.
/**
* @typedef {import("./types/index").ConjunctionType} ConjunctionType
* @typedef {import("./types/index").INode} INode
*/
/**
* Internal (non-leaf) expression node class.
*/
class InternalNode {
/**
* Constructor for InternalNode.
*/
constructor() {
this.exclude = false;
this.grouped = false;
/** @type {INode} */
this.leftChild = null;
/** @type {INode} */
this.rightChild = null;
/** @type {ConjunctionType} */
this.conjunction = null;
}
/**
* @returns {string} The node represented as a string.
*/
toString() {
if (!this.leftChild && !this.rightChild) {
return "";
}
if (!this.leftChild) {
return this.rightChild.toString();
}
if (!this.rightChild) {
return this.leftChild.toString();
}
return `${this.grouped ? "(" : ""}${this.leftChild.toString()} ${this.conjunction ? `${this.conjunction.toUpperCase()} ` : ""}${this.rightChild.toString()}${this.grouped ? ")" : ""}`;
}
}
module.exports = InternalNode;