add value to ast node
This commit is contained in:
@ -7,10 +7,17 @@ import java.util.List;
|
||||
public class Node {
|
||||
|
||||
private final String name;
|
||||
private String value;
|
||||
private final List<Node> children = new ArrayList<>();
|
||||
|
||||
public Node(String name) {
|
||||
this.name = name;
|
||||
this.value = "";
|
||||
}
|
||||
|
||||
public Node(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void addChild(Node node) {
|
||||
@ -25,6 +32,10 @@ public class Node {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Node) {
|
||||
@ -51,6 +62,10 @@ public class Node {
|
||||
private void print(StringBuilder buffer, String prefix, String childrenPrefix) {
|
||||
buffer.append(prefix);
|
||||
buffer.append(this.name);
|
||||
if (!this.value.isBlank()) {
|
||||
buffer.append(": ");
|
||||
buffer.append(this.value);
|
||||
}
|
||||
buffer.append('\n');
|
||||
|
||||
for (Iterator<Node> it = this.children.listIterator(); it.hasNext(); ) {
|
||||
|
Reference in New Issue
Block a user