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:
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:
setQuoteStyle
public YamlScalar setQuoteStyle(QuoteStyle quoteStyle)
Sets the quoting style.
Specified By:
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:
getContent
public String getContent()
Specified By:
getPrimitive
public Object getPrimitive()
Returns the dialect-aware JVM value (cached).
Specified By:
asString
public String asString()
Specified By:
asInteger
public int asInteger()
Specified By:
asInteger
public int asInteger(int defaultValue)
Specified By:
asDouble
public double asDouble()
Specified By:
asDouble
public double asDouble(double defaultValue)
Specified By:
asBoolean
public boolean asBoolean()
Returns the boolean value of the scalar, if there is one.
Specified By:
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:
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:
accept
public void accept(YamlVisitor visitor)
Overrides:
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:
hashCode
public int hashCode()
Generates a hash code based on the node's logical content.
Overrides:
toString
public String toString()
Overrides:
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)