File: pass_nested_sections.aug

package info (click to toggle)
augeas 0.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,216 kB
  • ctags: 5,097
  • sloc: ansic: 48,281; sh: 11,387; cpp: 624; yacc: 515; ruby: 444; makefile: 319; lex: 198; perl: 27; pascal: 27
file content (54 lines) | stat: -rw-r--r-- 923 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Pass_nested_sections =

let word = /[a-zA-Z0-9]+/
let ws = /[ \t]*/
let nl = /\n/

let eol = del (ws . nl) "\n"
let eq = del (ws . "=" . ws) "="
let lbr = del (ws . "{" . ws . nl) " {\n"
let rbr = del (ws . "}" . ws . nl) "}\n"
let indent = del ws ""

let entry = [ indent . key word . eq . store word . eol ]

let rec lns =
  let sec = [ indent . key word . lbr . lns . rbr ] in
  (sec | entry)+


test lns get "key = value\n" = { "key" = "value" }

test lns get "section {
  key1 = v1
  key2 = v2
  section {
    section {
      key4 = v4
    }
  }
  section {
    key5 = v5
  }
}\n" =
  { "section"
    { "key1" = "v1" }
    { "key2" = "v2" }
    { "section" { "section" { "key4" = "v4" } } }
    { "section" { "key5" = "v5" } } }


test lns get "section {
  section {
    key2 = v2
  }
}
section {
  key3 = v3
}
" =
  { "section"
    { "section"
      { "key2" = "v2" } } }
  { "section"
    { "key3" = "v3" } }