yaml

YAML parsing and generation for Kit

Files

FileDescription
kit.tomlPackage manifest with metadata and dependencies
src/yaml.kitYAML generation and value conversion utilities
tests/yaml.test.kitTests for generation and value-to-string conversion
examples/basic.kitParse YAML and access typed values
examples/debug.kitDebug line splitting and filtering
examples/yaml.kitFull demo of parsing, nesting, and generation
LICENSEMIT license file

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-yaml.git

Usage

import Kit.Yaml

License

MIT License - see LICENSE for details.

Exported Functions & Types

YamlValue

YAML value types for typed access.

Variants

YamlString {String}
Text value (quoted or unquoted)
YamlInt {Int}
Integer value
YamlFloat {Float}
Floating-point value
YamlBool {Bool}
Boolean value (true/false, yes/no)
YamlNull
Null/empty value (null, ~, or empty)
YamlList {_0}
List of YAML values

YamlError

YAML parse error types.

Variants

SyntaxError {line, message}
General syntax error
InvalidIndentation {line, message}
Invalid indentation
InvalidValue {line, key, message}
Invalid value for a key
UnclosedString {line}
Unclosed string literal at line
UnclosedList {line}
Unclosed list at line
DuplicateKey {line, key}
Duplicate key definition

Yaml

Marker type for the YAML format. Used with StringEncode/StringDecode traits to distinguish YAML serialization.

Variants

Yaml

generate

Generates YAML string from list of {key, value} records.

Creates a simple flat YAML document with key: value pairs.

Parameters:

Returns:

[{key: String, value: YamlValue}] -> String

pairs = [
  {key: "name", value: YamlString "MyApp"},
  {key: "port", value: YamlInt 8080},
  {key: "enabled", value: YamlBool true}
]
yaml-str = YAML.generate pairs
# Output:
# name: "MyApp"
# port: 8080
# enabled: true

value-to-string

Converts a YamlValue to its string representation.

Parameters:

Returns:

YamlValue -> String

str-val = YAML.value-to-string (YamlString "hello")
# Returns: "hello"

int-val = YAML.value-to-string (YamlInt 42)
# Returns: 42

bool-val = YAML.value-to-string (YamlBool true)
# Returns: true

list-val = YAML.value-to-string (YamlList [YamlInt 1, YamlInt 2])
# Returns: [1, 2]