Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / yaml.aug
1 (*
2 Module: Yaml
3   Only valid for the following subset:
4
5 > defaults: &anchor
6 >   repo1: master
7 >
8 > host:
9 >   # Inheritance
10 >   <<: *anchor
11 >   repo2: branch
12
13 Author: Dimitar Dimitrov <mitkofr@yahoo.fr>
14 *)
15 module YAML =
16
17 (* Group: helpers *)
18 let colon = Sep.colon
19 let space = Sep.space
20 let val = store Rx.word
21 let eol = Util.eol
22 let empty = Util.empty
23 let comment = Util.comment_noindent
24
25 (*
26 View: indent
27   the imposed indent is 2 spaces
28 *)
29 let indent = del /[ \t]+/ "  "
30
31 let mval = [ label "@mval" . Util.del_str "|-" . eol
32            . [ label "@line" . indent . store Rx.space_in . eol ]+ ]
33
34 (*
35 View: inherit
36 > <<: *anchor
37 *)
38 let _inherit = [ key "<<" . colon . space . Util.del_str "*" . val . eol ]
39 let inherit = indent . _inherit . (indent . comment)*
40
41 (*
42 View: repo
43 > { "repo" = "branch" }
44 *)
45 let _repo = [ key Rx.word . colon . space . (val | mval) . eol ]
46 let repo = indent . _repo . (indent . comment)*
47
48 (*
49 View: anchor
50 > &anchor
51 *)
52 let anchor = Util.del_str "&" . val
53
54 (*
55 View: entry
56 > host:
57 >   # Inheritance
58 >   <<: *anchor
59 >   repo2: branch
60 *)
61 let entry = [ key Rx.word . colon . (space . anchor)? . eol
62             . (indent . comment)*
63             . ((inherit . (repo+)?) | repo+)
64             ]
65
66 (* View: header *)
67 let header = [ label "@yaml" . Util.del_str "---"
68              . (Sep.space . store Rx.space_in)? . eol ]
69
70 (*
71 View: lns
72   The yaml lens
73 *)
74 let lns = ((empty|comment)* . header)? . (entry | comment | empty)*