Standard library · Data formats
data/yaml
Imported as import "data/yaml" as yaml, its names are then yaml.…. Every signature below is the one the checker infers.
Types
YParsed
What is left to read, and the value read so far. It used to be a line number into the list of lines, and every step then cost a walk from the front to reach it — nth to read a line, len to ask whether there were any left. Both are linear in a list, both were called per line, and an eight-hundred-entry config took fifty-five milliseconds to read because of it. Carrying the rest of the lines instead makes each step O(1) and the whole parse linear.
YParsed(value: Json, rest: List(Str))
Functions
fn parse_yaml(text: Str) -> Json
import "data/json" yaml.parse_yaml("name: ada\nage: 36\n") # => JObj(Cons(Field(name, JStr(ada)), Cons(Field(age, JInt(36)), Nil))) yaml.parse_yaml("- a\n- b\n") # => JArr(Cons(JStr(a), Cons(JStr(b), Nil))) yaml.parse_yaml("on: true # a comment\n") # => JObj(Cons(Field(on, JBool(true)), Nil)) doc = yaml.parse_yaml("server:\n port: 8080\n hosts:\n - a\n - b\n") path(doc, Cons("server", Cons("port", Nil))) # => Some(JInt(8080))