Last active
December 14, 2015 15:41
-
-
Save raphink/afdffa332f0178e243ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Test_YAML = | |
(* Simple value *) | |
test YAML.lns get "aa: master\n" = | |
{ "aa" = "master" } | |
(* Simple label *) | |
test YAML.lns get "aa: &bb\n" = | |
{ "aa" { "@label" = "bb" } } | |
(* Simple recursive *) | |
test YAML.lns get "aa: | |
bbb: master\n" = | |
{ "aa" { "bbb" = "master" } } | |
(* Label + recursive *) | |
test YAML.lns get "aa: &bb | |
bbb: master\n" = | |
{ "aa" { "@label" = "bb" } { "bbb" = "master" } } | |
(* Inherit in hash *) | |
test YAML.lns get "aa: | |
<<: *production\n" = | |
{ "aa" { "<<" { "@inherits" = "production" } } } | |
(* Full get test *) | |
test YAML.lns get " | |
aa: master | |
bbb: master | |
production: &production | |
ccc: 6e72bde9098b4f5dcb9a9efe4df4a1c2abd815a2 | |
dev: | |
<<: *production | |
qa: | |
<<: *defaults\n" = | |
{ } | |
{ "aa" = "master" } | |
{ "bbb" = "master" } | |
{ "production" | |
{ "@label" = "production" } | |
{ "ccc" = "6e72bde9098b4f5dcb9a9efe4df4a1c2abd815a2" } } | |
{ "dev" | |
{ "<<" | |
{ "@inherits" = "production" } } } | |
{ "qa" | |
{ "<<" | |
{ "@inherits" = "defaults" } } } | |
(* Put test *) | |
test YAML.lns put "aa: bb\n" | |
after set "/aa" "cc" = "aa: cc\n" | |
(* Put test with label *) | |
test YAML.lns put "aa: &bb\n" | |
after set "/aa/@label" "cc" = "aa: cc\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module YAML = | |
let empty = Util.empty | |
let eol = Util.eol | |
let space = Sep.space | |
(* indent is two spaces by default *) | |
let indent = del /[ \t]+/ " " | |
let val = store Rx.word | |
let lbl = [ label "@label" . Util.del_str "&" . store Rx.word ] | |
let inherit = [ label "@inherits" . Util.del_str "*" . store Rx.word ] | |
let rec entry = [ key (Rx.word | "<<") . Sep.colon | |
. ( (space . (val | lbl | inherit) . eol) | |
| ((space . lbl)? . eol . indent . entry) | |
) ] | |
let lns = (entry|empty)+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment