Skip to content

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:
    YamlAliasNode, YamlAnchorNode, YamlCommentNode, YamlSequenceNode, YamlMapNode, YamlErrorNode, YamlScalarNode, YamlMapEntryNode


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.

Constructor Summary

Constructor Description
YamlNode()
YamlNode(int line, int column) Constructs a new YamlNode with specific source coordinates.

Method Summary

Modifier and Type Method Description
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<CommentAstNode> getComments()
public void addComment(CommentAstNode comment) Associates a comment node with this specific AST node.
public YamlToken getToken()
public void setToken(YamlToken token)
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.

Method Details

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:

AstNode


getStartLine

public int getStartLine()

Specified By:

AstNode


getStartColumn

public int getStartColumn()

Specified By:

AstNode


getEndLine

public int getEndLine()

Specified By:

AstNode


getEndColumn

public int getEndColumn()

Specified By:

AstNode


getComments

public List<CommentAstNode> getComments()

Specified By:

AstNode


addComment

public void addComment(CommentAstNode comment)

Associates a comment node with this specific AST node.

Parameters:

comment - The comment node to add.


getToken

public YamlToken getToken()

Specified By:

AstNode


setToken

public void setToken(YamlToken token)


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.


hashCode

public int hashCode()

Generates a hash code based on the node's logical content.

Returns:

The hash code.