yamlstar

package module
v0.1.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 24 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

YAMLStar

A YAML framework for all programming languages.

Documentation: https://yamlstar.org

Install

Install the yaml CLI and the libyamlstar shared library:

curl -sSL https://yamlstar.org/install | bash

Install only the CLI or only the shared library:

curl -sSL https://yamlstar.org/install | BIN=1 bash
curl -sSL https://yamlstar.org/install | LIB=1 bash

Install to a custom prefix:

curl -sSL https://yamlstar.org/install | PREFIX=/opt/yamlstar bash

Go users can use the pure-Go module without installing the shared library:

go get github.com/yaml/yamlstar-go

Homebrew is also supported on Linux x64 and macOS ARM64:

brew trust yaml/yamlstar
brew tap yaml/yamlstar

brew install yaml/yamlstar/yamlstar
brew install yaml/yamlstar/libyamlstar

CLI

The yaml command loads YAML and prints compact JSON by default. Use -Y to emit YAML through YAMLStar's dump stack:

printf 'a: 1\n' | yaml
yaml config.yaml
yaml -J config.yaml
yaml -Y config.yaml
yaml -s stream.yaml
yaml -Y -s stream.yaml
yaml -e 'a: 1' -o out.json
yaml -D parse config.yaml
yaml --version

Run yaml --help or see https://yamlstar.org/cli/ for the full CLI reference.

Detailed node output (-N) uses node: Document, node: Mapping, and other node types, including nested content. The same contract can be passed between YAMLStar and go-yaml:

printf 'a: b\n' | go-yaml -N | yaml -Y
printf 'a: b\n' | yaml -N | go-yaml -Y

Use -f node to force node input. The retired kind: spelling is not accepted as a detailed node contract.

Vision

YAMLStar aims to be the best YAML load/dump framework available, with these key features:

  • YAML 1.2 Spec Compliance: 100% compliant with the YAML 1.2 specification
  • Pure Clojure Parser: No dependencies on SnakeYAML or other external parsers
  • Dump Stack: Convert JSON-compatible native values back to YAML
  • Cross-Language Consistency: Identical behavior in 32 languages from the same YAMLStar core
  • Highly Configurable: Plugin system for extensibility (coming in Phase 3)
  • Lightweight: Minimal dependencies, fast startup, small binaries

Project Status

✅ Phase 1 Complete - Ready for production use with 32 language bindings!

Roadmap
  • Phase 1: Minimal Viable YAML Stack ✅ Complete

    • YAML 1.2 loading
    • YAML dumping for JSON-compatible values
    • Event-based parser integration
    • Clojure data structure output
    • GraalVM native-image shared library
    • Language bindings (Ada, Clojure, Crystal, C#, D, Dart, Delphi, Dyalog APL, Elixir, Erlang, F#, Fortran, Go, Haskell, Java, Julia, Kotlin, Lua, MoonBit, Nim, Node.js, Perl, PHP, PowerShell, Python, R, Raku, Ruby, Rust, Scala, Swift, Zig)
  • Phase 2: Glojure Migration ✅ Complete

    • Port to Glojure (Clojure on Go)
    • AOT compilation to Go
    • Eliminate GraalVM from the shared-library build
    • Improved cross-platform support
  • Phase 3: Plugin System

    • Custom tag handlers (!include, !env, etc.)
    • Schema validation plugins
    • Expression evaluation (YAMLScript-like features)

Architecture

YAML Input
    ↓
Parser (pure Clojure, YAML 1.2)
    ↓
Composer (events → node tree)
    ↓
Resolver (nodes → Clojure data)
    ↓
Output (maps, vectors, scalars)

Dumping follows the reverse stack:

Native Data
    ↓
Representer (data → node tree)
    ↓
Desolver (tags/styles for readable YAML)
    ↓
Serializer (nodes → events)
    ↓
Emitter (events → YAML text)
    ↓
YAML Output

Current Status

✅ Phase 1A Complete - Core implementation finished!

  • Pure Clojure YAML 1.2 parser integrated (100% spec compliant)
  • Event-to-node composer implemented
  • Node-to-data resolver implemented
  • Complete test suite covering all major features
  • Zero external dependencies (except Clojure + data.json)
  • Gloat/Glojure shared library (libyamlstar.so)
  • Pure-Go module generated by Gloat/Glojure
  • 32 language bindings: Ada, Clojure, Crystal, C#, D, Dart, Delphi, Dyalog APL, Elixir, Erlang, F#, Fortran, Go, Haskell, Java, Julia, Kotlin, Lua, MoonBit, Nim, Node.js, Perl, PHP, PowerShell, Python, R, Raku, Ruby, Rust, Scala, Swift, Zig

Ready for testing! Run make test in the core/ directory, or try any of the language bindings.

Quick Start

Run Tests

The build system automatically installs all dependencies (Gloat, Glojure, Leiningen, etc.) on first run:

cd core
make test
Use in REPL
cd core
make repl
(require '[yamlstar.core :as yaml])

;; Load a YAML string
(yaml/load "key: value")
;=> {"key" "value"}

;; Load with type coercion
(yaml/load "num: 42\nbool: true\nnull: null")
;=> {"num" 42, "bool" true, "null" nil}

;; Load multiple documents
(yaml/load-all "---\ndoc1\n---\ndoc2")
;=> ["doc1" "doc2"]

;; Dump native values as YAML
(yaml/dump {"foo" [["bar"]]})
;=> "foo:\n- - bar\n"

;; Dump multiple documents
(yaml/dump-all ["doc1" {"a" 1} ["b"]])
;=> "---\ndoc1\n---\na: 1\n---\n- b\n"

;; Complex nested structures
(yaml/load "
person:
  name: Alice
  age: 30
  hobbies: [reading, coding]
")
;=> {"person" {"name" "Alice", "age" 30, "hobbies" ["reading" "coding"]}}

See DEVELOPMENT.md for detailed development guide.

Language Bindings

YAMLStar provides bindings for multiple programming languages from the same core implementation. Most native bindings use the Gloat/Glojure shared library (libyamlstar.so); Go uses generated Go code directly.

For language bindings that use FFI, install the matching libyamlstar release with the install script or Homebrew before loading YAML. Native Windows support varies by binding. Ada, Crystal, Erlang, F#, Haskell, Julia, PowerShell, Raku, and Scala are currently verified on Linux/macOS shared-library paths. FreeBSD x64 verifies the C ABI and Python binding.

Language Directory Test Command
Ada ada/ make test (auto-installs GNAT)
Clojure clojure/ make test (auto-installs lein)
Crystal crystal/ make test (auto-installs crystal)
C# csharp/ make test (auto-installs dotnet)
Erlang erlang/ make test (auto-installs Erlang)
F# fsharp/ make test (auto-installs dotnet)
Fortran fortran/ make test (auto-installs gfortran, FPM)
Go go/ make test (auto-installs go)
Haskell haskell/ make test (auto-installs GHC, Cabal)
Java java/ make test (auto-installs lein, Maven)
Julia julia/ make test (auto-installs julia)
Lua lua/ make test (auto-installs lua, luarocks)
Node.js nodejs/ make test (auto-installs node, npm)
Perl perl/ make test (auto-installs perl, cpanm)
PHP php/ make test
PowerShell powershell/ make test (requires or auto-installs pwsh when supported)
Python python/ make test (auto-installs python, pip)
Raku raku/ make test (auto-installs raku)
Ruby ruby/ make test (auto-installs ruby)
Rust rust/ make test (auto-installs cargo)
Scala scala/ make test (requires scala-cli)
Quick Example (Node.js)
const YAMLStar = require('yamlstar');
const ys = new YAMLStar();

const data = ys.load('key: value');
console.log(data);  // { key: 'value' }

const text = ys.dump({foo: [['bar']]});
console.log(text);
// foo:
// - - bar

ys.close();
Quick Example (Python)
from yamlstar import YAMLStar

ys = YAMLStar()
data = ys.load('key: value')
print(data)  # {'key': 'value'}

text = ys.dump({'foo': [['bar']]})
print(text)
# foo:
# - - bar

ys.close()
Quick Example (Clojure)
(require '[yamlstar.core :as yaml])

(yaml/load "key: value")
;=> {"key" "value"}

(yaml/dump {"foo" [["bar"]]})
;=> "foo:\n- - bar\n"

Each binding directory contains its own ReadMe.md with detailed installation and usage instructions.

Plugins

YAMLStar has a plugin system that can swap internal processing components per load operation. Parser plugins select a parser implementation. The json-comments plugin API adds JSON-style comments before parsing:

printf '%s\n' '{"a": true /* comment */}' |
  yaml --plugin=json-comments

The native CLI installs a missing official shared plugin automatically. Language bindings require an explicit opt-in before libyamlstar installs a missing plugin.

See Plugins for the full options format, installation policy, and plugin ABI.

Comparison to YAMLScript

YAMLStar is derived from YAMLScript but with a different focus:

Feature YAMLScript YAMLStar
Purpose YAML + scripting language YAML load/dump framework
Runtime Includes SCI interpreter No runtime evaluation
Pipeline 7 stages (parser → runtime) load and dump stacks
Dependencies Heavy (Babashka, SCI, etc.) Minimal (Clojure only)
Extensibility Built-in scripting Plugin system (Phase 3)

License

MIT License - See LICENSE file

Credits

Created by Ingy döt Net, inventor of YAML and YAMLScript.

Built on the YAML Reference Parser (pure Clojure implementation).

Documentation

Overview

Package yamlstar provides a pure-Go YAML 1.2 loader and dumper.

YAMLStar is implemented in Clojure and compiled to Go by Gloat and Glojure. The generated runtime is included in this module; using this package does not require cgo or the libyamlstar shared library.

Index

Constants

View Source
const Version = "0.1.23"

Version is the YAMLStar module version.

Variables

View Source
var ErrNotInitialized = errors.New("yamlstar: runtime not initialized")

ErrNotInitialized is retained for compatibility with the former cgo binding. Initialization failures are returned directly.

View Source
var ErrNullResponse = errors.New("yamlstar: received null response")

ErrNullResponse is returned when the generated runtime returns no response.

Functions

func Dump

func Dump(value any, opts ...Option) (string, error)

Dump serializes a JSON-compatible Go value as YAML.

func DumpAll

func DumpAll(values []any, opts ...Option) (string, error)

DumpAll serializes JSON-compatible Go values as a YAML stream.

func LibVersion

func LibVersion() (string, error)

LibVersion returns the version reported by the generated YAMLStar runtime.

The name is retained for compatibility with the former shared-library binding.

func Load

func Load(input string, opts ...Option) (any, error)

Load parses a YAML string and returns its first document as a Go value.

Values are represented as nil, bool, float64, string, []any, and map[string]any.

func LoadAll

func LoadAll(input string, opts ...Option) ([]any, error)

LoadAll parses a YAML stream and returns all its documents.

Types

type AliasDataConfig added in v0.1.23

type AliasDataConfig struct {
	Data   map[string]any
	File   string
	Env    any
	Stream bool
}

AliasDataConfig configures external alias values and stream anchor scope. Env accepts true, a string pattern, or a sequence of exact names.

type IndentConfig added in v0.1.23

type IndentConfig struct {
	Mode      IndentMode
	LoadStyle IndentStyle
	DumpStyle IndentStyle
	Scope     IndentScope
}

IndentConfig configures the built-in tab-indent plugin.

type IndentMode added in v0.1.23

type IndentMode string

IndentMode supplies loading and dumping defaults.

const (
	IndentModeAuto IndentMode = "auto"
	IndentModeTabs IndentMode = "tabs"
)

type IndentScope added in v0.1.23

type IndentScope string

IndentScope controls how long an auto-detected style remains active.

const (
	IndentScopeDocument IndentScope = "document"
	IndentScopeStream   IndentScope = "stream"
)

type IndentStyle added in v0.1.23

type IndentStyle string

IndentStyle identifies the characters used for structural indentation.

const (
	IndentStyleAuto   IndentStyle = "auto"
	IndentStyleSpaces IndentStyle = "spaces"
	IndentStyleTabs   IndentStyle = "tabs"
)

type Option added in v0.1.19

type Option func(*options)

Option configures a YAML load or dump operation.

func WithPlugin added in v0.1.19

func WithPlugin(plugin Plugin) Option

WithPlugin adds a plugin option fragment.

type Plugin added in v0.1.19

type Plugin func(*options)

Plugin is a YAMLStar plugin option fragment.

func AliasData added in v0.1.23

func AliasData(config ...AliasDataConfig) Plugin

AliasData enables the built-in Alias-Data policy. With no configuration, it enables stream-scoped anchors.

func TabIndent added in v0.1.23

func TabIndent(config ...IndentConfig) Plugin

TabIndent enables tab-aware loading and tab-indented dumping.

func YAMLEmitter added in v0.1.23

func YAMLEmitter(name string) Plugin

YAMLEmitter selects the YAML emitter plugin used for dumping.

func YAMLParser added in v0.1.23

func YAMLParser(name string) Plugin

YAMLParser selects the YAML parser plugin used for loading.

type YAMLError

type YAMLError struct {
	Cause   string `json:"cause"`
	Type    string `json:"type"`
	Message string `json:"message,omitempty"`
}

YAMLError represents an error returned by YAMLStar.

func (*YAMLError) Error

func (e *YAMLError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL