GitHub - w3Abhishek/nimhuml: A fast and lightweight HUML parser for Nim

1 min read Original article ↗

A Nim implementation of the HUML (Human-Oriented Markup Language) parser and serializer.

HUML is a machine-readable markup language with a focus on readability by humans. It borrows YAML's visual appearance, but avoids its complexities and ambiguities.

Installation

Or add to your .nimble file:

requires "nimhuml >= 0.2.0"

Usage

import nimhuml
import std/json

# Parse HUML string into a JsonNode
let data = loads("""
%HUML v0.2.0
name: "nimhuml"
version: "0.2.0"
features::
  - "fast"
  - "simple"
  - "readable"
""")

echo data.pretty()

# Serialize a JsonNode back to HUML
let obj = %* {
  "name": "example",
  "count": 42,
  "enabled": true
}
echo dumps(obj)

# File I/O
let parsed = load("config.huml")
dump(parsed, "output.huml")

Supported HUML v0.2.0 Features

  • Scalars: strings (quoted + multiline """), integers, floats, booleans (true/false), null, nan, inf
  • Numbers: decimal, hex (0x), octal (0o), binary (0b), scientific notation, underscores
  • Collections: multiline dicts/lists, inline dicts/lists, empty {} / []
  • Vectors: :: indicator for nested collections
  • Comments: # comment (full-line and inline)
  • Version directive: %HUML v0.2.0
  • Strict formatting: no trailing spaces, consistent indentation (2 spaces)

Running Tests

# Clone test data
cd tests && git clone https://github.com/huml-lang/tests.git && cd ..

# Run tests
nimble test

License

Licensed under the MIT License.