Package io.github.qishr.cascara.lang.yaml.ast
Class YamlNode
java.lang.Object
io.github.qishr.cascara.lang.yaml.ast.YamlNode
All Implemented Interfaces:
AstNode
Direct Known Subtypes:
YamlAnchor, YamlStream, YamlMapEntry, YamlComment, YamlMap, YamlDocument, YamlAlias, YamlDirective, YamlScalar, YamlSequence
public abstract class YamlNode
Base implementation for all YAML AST nodes.This class provides the foundational structure for YAML nodes, including source coordinates (line and column), the source URI, and support for YAML anchors and comments.
Field Summary
| Modifier and Type | Field | Description |
|---|---|---|
| protected NodeStyle | nodeStyle | |
| protected YamlOptions | options | |
| protected YamlToken | token |
Constructor Summary
| Constructor | Description |
|---|---|
| YamlNode() | |
| YamlNode(YamlOptions options) | |
| YamlNode(YamlToken token) | Constructs a new YamlNode with specific source coordinates obtained from a YamLToken |
| YamlNode(YamlToken token, YamlOptions options) | Constructs a new YamlNode with specific source coordinates obtained from a YamLToken and a set of YAML options. |
| YamlNode(int line, int column, YamlOptions options) | Constructs a new YamlNode with specific source coordinates and a set of YAML options. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
| public abstract void | accept(YamlVisitor visitor) | |
| public YamlOptions | getOptions() | |
| public NodeStyle | getNodeStyle() | |
| public YamlNode | setNodeStyle(NodeStyle nodeStyle) | |
| public String | getTag() | |
| public void | setTag(String tag) | |
| public String | getAnchor() | Gets the YAML anchor associated with this node (e.g., &anchorName). |
| public void | setAnchor(String anchor) | Sets the YAML anchor for this node. |
| public abstract List<? extends YamlNode> | getChildren() | Implementation-specific nodes must return their constituent children. For example, a Map node returns its entries. |
| public int | getStartLine() | |
| public int | getStartColumn() | |
| public int | getEndLine() | |
| public int | getEndColumn() | |
| public List<YamlComment> | getComments() | |
| public void | addComment(YamlComment comment) | Associates a comment node with this specific AST node. |
| public void | addComments(int pos, List<YamlComment> comments) | Associates a comment node with this specific AST node. |
| public YamlToken | getToken() | |
| public boolean | equals(Object o) | Compares this node with another for equality based on its content. |
| public int | hashCode() | Generates a hash code based on the node's logical content. |
Field Details
nodeStyle
protected NodeStyle nodeStyle
options
protected YamlOptions options
token
protected YamlToken token
Method Details
accept
public abstract void accept(YamlVisitor visitor)
getOptions
public YamlOptions getOptions()
getNodeStyle
public NodeStyle getNodeStyle()
setNodeStyle
public YamlNode setNodeStyle(NodeStyle nodeStyle)
getTag
public String getTag()
setTag
public void setTag(String tag)
getAnchor
public String getAnchor()
Gets the YAML anchor associated with this node (e.g., &anchorName).
Returns:
The anchor string, or null if no anchor is defined.
setAnchor
public void setAnchor(String anchor)
Sets the YAML anchor for this node.
Parameters:
anchor - The anchor string to associate with this node.
getChildren
public abstract List<? extends YamlNode> getChildren()
Implementation-specific nodes must return their constituent children. For example, a Map node returns its entries.
Specified By:
getStartLine
public int getStartLine()
Specified By:
getStartColumn
public int getStartColumn()
Specified By:
getEndLine
public int getEndLine()
Specified By:
getEndColumn
public int getEndColumn()
Specified By:
getComments
public List<YamlComment> getComments()
Specified By:
addComment
public void addComment(YamlComment comment)
Associates a comment node with this specific AST node.
Parameters:
comment - The comment node to add.
addComments
public void addComments(int pos, List<YamlComment> comments)
Associates a comment node with this specific AST node.
getToken
@io.github.qishr.cascara.common.lang.annotation.Nullable
public YamlToken getToken()
Specified By:
equals
public boolean equals(Object o)
Compares this node with another for equality based on its content.Note: Source coordinates (line and column) are intentionally excluded from equality checks to allow programmatically created nodes to match parsed nodes during map lookups.
Parameters:
o - The object to compare with.
Returns:
true if the nodes represent logically equivalent data.
Overrides:
hashCode
public int hashCode()
Generates a hash code based on the node's logical content.
Returns:
The hash code.
Overrides: