glaml

Types

A YAML document.
To get the root Node call document_root on it, like this:

let document = Document(root: NodeNil)
let assert NodeNil = document_root(document)
pub type Document {
  Document(root: Node)
}

Constructors

  • Document(root: Node)

A YAML document node.

pub type Node {
  NodeNil
  NodeStr(String)
  NodeBool(Bool)
  NodeInt(Int)
  NodeFloat(Float)
  NodeSeq(List(Node))
  NodeMap(List(#(Node, Node)))
}

Constructors

  • NodeNil
  • NodeStr(String)
  • NodeBool(Bool)
  • NodeInt(Int)
  • NodeFloat(Float)
  • NodeSeq(List(Node))
  • NodeMap(List(#(Node, Node)))

A Node selection used by Selector.

pub type Selection {
  SelectMap(key: Node)
  SelectSeq(index: Int)
}

Constructors

  • SelectMap(key: Node)
  • SelectSeq(index: Int)

A document selector that contains a sequence of selections leading to a Node.

pub type Selector {
  Selector(List(Selection))
}

Constructors

  • Selector(List(Selection))
pub type SelectorError {
  NodeNotFound(at: Int)
  SelectorParseError
}

Constructors

  • NodeNotFound(at: Int)
  • SelectorParseError

A YAML document error containing a message — msg and it’s location — loc.

pub type YamlError {
  UnexpectedParsingError
  ParsingError(msg: String, loc: YamlErrorLoc)
}

Constructors

  • UnexpectedParsingError
  • ParsingError(msg: String, loc: YamlErrorLoc)
pub type YamlErrorLoc {
  YamlErrorLoc(line: Int, column: Int)
}

Constructors

  • YamlErrorLoc(line: Int, column: Int)

Functions

pub fn document_root(document: Document) -> Node

Gets the root Node of a YAML document.

Examples

let document = Document(root: NodeNil)
let assert NodeNil = document_root(document)
pub fn parse_file(
  path: String,
) -> Result(List(Document), YamlError)

Parse a YAML file located in path into a list of YAML documents.

pub fn parse_selector(
  selector: String,
) -> Result(Selector, SelectorError)

Parses selector as a Selector and

pub fn parse_string(
  string: String,
) -> Result(List(Document), YamlError)

Parse a string into a list of YAML documents.

pub fn select(
  from node: Node,
  selector selector: Selector,
) -> Result(Node, SelectorError)

Queries the given node with a Selector.

Examples

let map = NodeMap([
  #(NodeStr("lib name"), NodeStr("glaml")),
  #(NodeStr("stars"), NodeInt(7)),
])

let assert Ok(NodeInt(7)) = select(from: map, selector: Selector([SelectMap(NodeStr("stars"))]))
pub fn select_sugar(
  from node: Node,
  selector selector: String,
) -> Result(Node, SelectorError)

Parses the selector and queries the given node with it.

Examples

let map = NodeMap([
  #(NodeStr("list"), NodeMap([
    #(NodeStr("elements"), NodeSeq([NodeInt(101)]))
  ])),
  #(NodeStr("linked"), NodeBool(False)),
])

let assert Ok(NodeInt(101)) = select_sugar(from: map, selector: "list.elements.#0")
Search Document