Skip to content

Package io.github.qishr.cascara.lang.yaml.ast

Class YamlScalar

java.lang.Object
        io.github.qishr.cascara.lang.yaml.ast.YamlNode
                io.github.qishr.cascara.lang.yaml.ast.YamlScalar

All Implemented Interfaces:
    ScalarAstNode<YamlNode>


public class YamlScalar
extends YamlNode

Represents a leaf node in the YAML AST containing a single scalar value.

Constructor Summary

Constructor Description
YamlScalar(YamlToken token, PrimitiveType primitiveType, YamlOptions options) Constructor for use in parsers.
YamlScalar(YamlToken token, String content, PrimitiveType primitiveType, ScalarStyle scalarStyle, YamlOptions options) Constructor for use in parsers.
YamlScalar(Object jvmValue, ScalarStyle scalarStyle, YamlOptions options) A programmatic and serializer constructor.
YamlScalar(Object jvmValue, ScalarStyle scalarStyle) A programmatic and serializer constructor.
YamlScalar(Object jvmValue) A programmatic and serializer constructor.
YamlScalar() The default constructor

Method Summary

Modifier and Type Method Description
public YamlOptions getOptions()
public PrimitiveType getPrimitiveType()
public boolean isQuoted()
public ScalarStyle getScalarStyle()
public YamlScalar setScalarStyle(ScalarStyle scalarStyle)
public QuoteStyle getQuoteStyle() Gets the quoting style used for this scalar.
public YamlScalar setQuoteStyle(QuoteStyle quoteStyle) Sets the quoting style.
public ChompingStyle getChompingStyle()
public YamlScalar setChompingStyle(ChompingStyle style)
public String getLexeme() Returns the original raw (unescaped) string as seen in the source file.
public String getContent()
public Object getPrimitive() Returns the dialect-aware JVM value (cached).
public String asString()
public int asInteger()
public int asInteger(int defaultValue)
public double asDouble()
public double asDouble(double defaultValue)
public boolean asBoolean() Returns the boolean value of the scalar, if there is one.
public boolean asBoolean(boolean defaultValue) Returns the boolean value of the scalar, if there is one, otherwise the specified default is returned.
public List<YamlNode> getChildren() Implementation-specific nodes must return their constituent children. For example, a Map node returns its entries. Scalars are leaf nodes and have no children.
public void accept(YamlVisitor visitor)
public boolean equals(Object o) Compares this scalar with another for equality.
public int hashCode() Generates a hash code based on the node's logical content.
public String toString()
public static ScalarStyle inferQuoteStyle(Object value)
public PrimitiveType inferType(String raw, ScalarStyle quoteStyle)
public Object parse(String raw, ScalarStyle quoteStyle)
public String unescape(String text, ScalarStyle style)

Methods inherited from YamlNode

getNodeStyle, getTag, setAnchor, getStartColumn, addComments, getStartLine, getEndColumn, getEndLine, getComments, setTag, setNodeStyle, addComment, getToken, getAnchor

Method Details

getOptions

public YamlOptions getOptions()


getPrimitiveType

public PrimitiveType getPrimitiveType()

Specified By:

ScalarAstNode


isQuoted

public boolean isQuoted()


getScalarStyle

public ScalarStyle getScalarStyle()


setScalarStyle

public YamlScalar setScalarStyle(ScalarStyle scalarStyle)


getQuoteStyle

public QuoteStyle getQuoteStyle()

Gets the quoting style used for this scalar.

Specified By:

ScalarAstNode


setQuoteStyle

public YamlScalar setQuoteStyle(QuoteStyle quoteStyle)

Sets the quoting style.

Specified By:

ScalarAstNode


getChompingStyle

public ChompingStyle getChompingStyle()


setChompingStyle

public YamlScalar setChompingStyle(ChompingStyle style)


getLexeme

public String getLexeme()

Returns the original raw (unescaped) string as seen in the source file.

Specified By:

ScalarAstNode


getContent

public String getContent()

Specified By:

ScalarAstNode


getPrimitive

public Object getPrimitive()

Returns the dialect-aware JVM value (cached).

Specified By:

ScalarAstNode


asString

public String asString()

Specified By:

ScalarAstNode


asInteger

public int asInteger()

Specified By:

ScalarAstNode


asInteger

public int asInteger(int defaultValue)

Specified By:

ScalarAstNode


asDouble

public double asDouble()

Specified By:

ScalarAstNode


asDouble

public double asDouble(double defaultValue)

Specified By:

ScalarAstNode


asBoolean

public boolean asBoolean()

Returns the boolean value of the scalar, if there is one.

Specified By:

ScalarAstNode


asBoolean

public boolean asBoolean(boolean defaultValue)

Returns the boolean value of the scalar, if there is one, otherwise the specified default is returned.

Specified By:

ScalarAstNode


getChildren

public List<YamlNode> getChildren()

Implementation-specific nodes must return their constituent children. For example, a Map node returns its entries. Scalars are leaf nodes and have no children.

Overrides:

YamlNode


accept

public void accept(YamlVisitor visitor)

Overrides:

YamlNode


equals

public boolean equals(Object o)

Compares this scalar with another for equality.https://yaml.org/spec/1.2.2/#3213-node-comparison

Two nodes must have the same tag and content to be equal. Since each tag applies to exactly one kind, this implies that the two nodes must have the same kind to be equal.

Two scalars are equal only when their tags and canonical forms are equal character-by-character. Equality of collections is defined recursively. Note: Source coordinates (line and column) are intentionally excluded from equality checks to allow programmatically created nodes to match parsed nodes during map lookups.

Overrides:

YamlNode


hashCode

public int hashCode()

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

Overrides:

YamlNode


toString

public String toString()

Overrides:

Object


inferQuoteStyle

public static ScalarStyle inferQuoteStyle(Object value)


inferType

public PrimitiveType inferType(String raw, ScalarStyle quoteStyle)


parse

public Object parse(String raw, ScalarStyle quoteStyle)


unescape

public String unescape(String text, ScalarStyle style)