Skip to main content

module lang::yaml::Model

rascal-0.40.16

AST model for YAML (loosely based on the serialization model of http://www.yaml.org/spec/1.2/spec.html).

Usage

import lang::yaml::Model;

Dependencies

import List;
import Map;
import Set;

data Node

Generic representation for YAML nodes.

data Node (int anchor=-1, type[value] \tag = #void) 
= sequence(list[Node] \list)
| scalar(value \value)
| reference()
| mapping(map[Node, Node] \map)
;

Tagging (using the \tag field) will be used to do typed serialization for ADTs in the future.

In valid YAML anchors always occur before any references this should also hold in our YAML data type. Dumping will throw index out of bound exception if references are out of order.

Anchors are only currently valid on seq/map nodes. and should be unique.

function loadYAML

Node loadYAML(str src)

function dumpYAML

str dumpYAML(Node yaml)

function checkYAML

set[str] checkYAML(Node n)

function badAnchors

set[Node] badAnchors(Node n)

function wronglyTypedScalars

set[Node] wronglyTypedScalars(Node n)

function okValue

bool okValue(type[&T <: value] _, value v)

function unsupportedTypes

set[type[value]] unsupportedTypes(Node n)

function untaggedScalars

set[Node] untaggedScalars(Node n)

function duplicateAnchors

set[int] duplicateAnchors(Node n)

function undefinedRefs

tuple[set[int], set[int]] undefinedRefs(reference(anchor=i), set[int] seen, set[int] dupl)

tuple[set[int], set[int]] undefinedRefs(s:sequence(ns), set[int] seen, set[int] dupl)

tuple[set[int], set[int]] undefinedRefs(nod:mapping(m), set[int] seen, set[int] dupl)

default tuple[set[int], set[int]] undefinedRefs(Node n, set[int] seen, set[int] dupl)

function equalNodes

bool equalNodes(Node x, Node y)

Tests

test testLoadDump

public test bool testLoadDump() {
Node n = loadYAML(TEST_YAML);
str y = dumpYAML(n);
return equalNodes(n, loadYAML(y));
}