moonyaml — YAML for MoonBit. Reads and writes YAML 1.2.2 into the same `Json` tree every other reader in this family produces: block and flow collections, the five block scalar forms, anchors and aliases, tags, and multi-document streams. What it does not understand it refuses rather than guesses.
let config = @moonyaml.loads(
#|server:
#| host: 0.0.0.0
#| port: 12000
#| motd: |
#| welcome
#| to the party
#|limits: &shared { files: 1000, bytes: 1048576 }
#|upload: *shared
)
@moonyaml.dumps(config) // back to YAML, block style
@moonyaml.loads_all(stream) // every document in a `---` stream| Collections | Block mappings and sequences, flow {} and [], nested in either direction, a sequence in its parent key's own column |
| Scalars | Plain over several lines, single- and double-quoted with the escapes of §5.7, literal \| and folded > with chomping and explicit indentation |
| Structure | Anchors and aliases, tags including %TAG handles and verbatim !<…>, %YAML, --- and ... document markers |
| Resolution | The core schema of §10.2: null/~, booleans, decimal, 0o and 0x integers, floats with exponents, .inf and .nan |
@moonyaml.loads(src, flavor=@moonyaml.Flavor::new(duplicates=Reject))
@moonyaml.loads(src, flavor={ ..@moonyaml.strict, budget: 1000 })| Knob | Preset | Why |
|---|---|---|
| depth | 500 | Between Jackson's 1000 and serde_json's 128, the same as this family's JSON |
| duplicates | Last | What every loader in reach does; First and Reject are there because a key written twice is usually a mistake |
| aliases | true | An alias is part of the language; false refuses one outright |
| budget | 10 000 000 | An alias can name a node holding aliases, so a dozen lines can expand to billions — the "billion laughs", which libyaml and PyYAML's safe_load both still perform faithfully. There is no common value to follow, so this takes the safe side |
moon add moonbitstack/moonyamlpub(all) struct Flavor {
depth : Int
duplicates : Duplicates
aliases : Bool
budget : Int
} derive(Eq, Debug)let budget : Intlet depth : Intlet indent : IntInstall
Download zipmoonyaml — YAML for MoonBit. Reads and writes YAML 1.2.2 into the same `Json` tree every other reader in this family produces: block and flow collections, the five block scalar forms, anchors and aliases, tags, and multi-document streams. What it does not understand it refuses rather than guesses.