SIMPLE_YAML_QUICK

Zero-Configuration YAML for Beginners

v1.0.0 MIT

Overview

SIMPLE_YAML_QUICK provides one-liner YAML config file access with dot-path notation. Perfect for reading configuration files like database.host.

For YAML building and advanced features, use SIMPLE_YAML directly.

Quick Start

local
    yaml: SIMPLE_YAML_QUICK
    config: YAML_VALUE
do
    create yaml.make

    -- Load config file
    config := yaml.load ("config.yml")

    -- Get values with dot-path (like config files!)
    host := yaml.get_string (config, "database.host")
    port := yaml.get_integer (config, "database.port")
    debug := yaml.get_boolean (config, "logging.debug")
    timeout := yaml.get_real (config, "server.timeout")

    -- Get string list
    across yaml.get_list (config, "features.enabled") as f loop
        print (f)
    end

    -- One-liner file access
    host := yaml.string_from_file ("config.yml", "database.host")
    port := yaml.integer_from_file ("config.yml", "database.port")

    -- Check if key exists
    if yaml.has_key (config, "database.ssl") then ...

    -- Parse YAML string
    config := yaml.parse (yaml_string)

    -- Validation
    if yaml.is_valid (yaml_string) then ...

    -- Error handling
    if yaml.has_error then
        print (yaml.last_error)
    end
end

Example Config File

# config.yml
database:
  host: localhost
  port: 5432
  name: myapp

logging:
  level: info
  debug: false

features:
  enabled:
    - auth
    - cache
    - api
-- Access with dot-path
yaml.get_string (config, "database.host")     -- "localhost"
yaml.get_integer (config, "database.port")    -- 5432
yaml.get_boolean (config, "logging.debug")    -- False
yaml.get_list (config, "features.enabled")    -- ["auth", "cache", "api"]

API Reference

Loading

FeatureDescription
load (path)Load YAML file
parse (yaml_string)Parse YAML string

Dot-Path Getters

FeatureDescription
get_string (value, path)Get string at dot-path
get_integer (value, path)Get integer at dot-path
get_real (value, path)Get real number at dot-path
get_boolean (value, path)Get boolean at dot-path
get_list (value, path)Get string list at dot-path

One-Liner File Access

FeatureDescription
string_from_file (path, key)Load file and get string
integer_from_file (path, key)Load file and get integer
boolean_from_file (path, key)Load file and get boolean

Existence and Validation

FeatureDescription
has_key (value, path)Does path exist?
is_valid (yaml_string)Is string valid YAML?
has_errorDid last operation fail?
last_errorLast error message