Skip to content

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

Class YamlEmitter

java.lang.Object
        io.github.qishr.cascara.lang.yaml.processor.AbstractYamlProcessor<io.github.qishr.cascara.lang.yaml.processor.YamlEmitter>
                io.github.qishr.cascara.lang.yaml.processor.YamlEmitter

All Implemented Interfaces:
    Emitter


public class YamlEmitter
extends AbstractYamlProcessor<YamlEmitter>

Responsible for converting a YamlNode AST back into a valid YAML string.This emitter is high-fidelity: it prioritizes preserving the original CollectionStyle and QuoteStyle of nodes while ensuring that comments are placed correctly relative to their owner nodes.

Indentation Logic

The emitter maintains a virtual column through the indent parameters passed during recursive calls. It handles special cases like "compact" sequences where the mapping starts on the same line as the sequence dash (- key: value).

Constructor Summary

Constructor Description
YamlEmitter()

Method Summary

Modifier and Type Method Description
protected YamlEmitter self()
public YamlEmitter setOptions(LanguageOptions<?> options)
public void emitScalar(String value)
public void emitMapStart()
public void emitMapEnd()
public void emitSequenceStart()
public void emitSequenceEnd()
public void emitPropertySeparator()
public void emitItemSeparator()
public void emitNewLine()
public void indent()
public void dedent()
public String getOutput()
public String emit(YamlNode root) Primary entry point for emitting a full document.

Methods inherited from AbstractYamlProcessor

setReporter, getContentType, getServiceProperties

Method Details

self

protected YamlEmitter self()


setOptions

public YamlEmitter setOptions(LanguageOptions<?> options)


emitScalar

public void emitScalar(String value)

Specified By:

Emitter


emitMapStart

public void emitMapStart()

Specified By:

Emitter


emitMapEnd

public void emitMapEnd()

Specified By:

Emitter


emitSequenceStart

public void emitSequenceStart()

Specified By:

Emitter


emitSequenceEnd

public void emitSequenceEnd()

Specified By:

Emitter


emitPropertySeparator

public void emitPropertySeparator()

Specified By:

Emitter


emitItemSeparator

public void emitItemSeparator()

Specified By:

Emitter


emitNewLine

public void emitNewLine()

Specified By:

Emitter


indent

public void indent()

Specified By:

Emitter


dedent

public void dedent()

Specified By:

Emitter


getOutput

public String getOutput()

Specified By:

Emitter


emit

public String emit(YamlNode root)

Primary entry point for emitting a full document.

Parameters:

root - AST root.

Returns:

A formatted YAML string.