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:
    YamlNodeProperty, 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(YamlToken token, 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 List<YamlNodeProperty> getProperties()
public NodeStyle getNodeStyle()
public YamlNode setNodeStyle(NodeStyle nodeStyle)
public boolean fileEndsWithNewLine()
public void setFileEndsWithNewLine(boolean b)
public boolean isPreceededByNewLine()
public YamlNode setPreceededByNewLine(boolean b)
public String getTag()
public void setTag(String tag)
public String getResolvedTag()
public void setResolvedTag(String resolvedTag)
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 int getSemanticColumn() Set the semantic column number of this node.
public YamlNode setSemanticColumn(int n) Retrieves the semantic column number of this node.
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.
public String toString()

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()


getProperties

public List<YamlNodeProperty> getProperties()


getNodeStyle

public NodeStyle getNodeStyle()


setNodeStyle

public YamlNode setNodeStyle(NodeStyle nodeStyle)


fileEndsWithNewLine

public boolean fileEndsWithNewLine()


setFileEndsWithNewLine

public void setFileEndsWithNewLine(boolean b)


isPreceededByNewLine

public boolean isPreceededByNewLine()


setPreceededByNewLine

public YamlNode setPreceededByNewLine(boolean b)


getTag

public String getTag()


setTag

public void setTag(String tag)


getResolvedTag

public String getResolvedTag()


setResolvedTag

public void setResolvedTag(String resolvedTag)


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


getSemanticColumn

public int getSemanticColumn()

Set the semantic column number of this node.This is the column number of the node itself, unless it has properties on the same line, in which case it is the column number of the leftmost property.


setSemanticColumn

public YamlNode setSemanticColumn(int n)

Retrieves the semantic column number of this node.This is the column number of the node itself, unless a semantic column has been set, in which case that semantic column value is returned.


getComments

public List<YamlComment> getComments()

Specified By:

AstNode


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.annotation.Nullable
public YamlToken getToken()

Specified By:

AstNode


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:

Object


hashCode

public int hashCode()

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

Returns:

The hash code.

Overrides:

Object


toString

public String toString()

Overrides:

Object