Imported Upstream version 1.3.0
[platform/upstream/augeas.git] / lenses / xendconfsxp.aug
1 module Xendconfsxp =
2     autoload xfm
3
4 let spc1 = /[ \t\n]+/
5 let ws = del spc1 " "
6
7 let lbrack = del /[ \t]*\([ \t\n]*/ "("
8 let rbrack = del /[ \t\n]*\)/ ")"
9
10 let empty_line = [ del /[ \t]*\n/ "\n" ]
11
12 let no_ws_comment =
13     [ label "#comment" . del /#[ \t]*/ "# " . store /[^ \t]+[^\n]*/ . del /\n/ "\n" ]
14
15 let standalone_comment = [ label "#scomment" . del /#/ "#" . store /.*/ . del /\n/ "\n" ]
16 (* Minor bug: The initial whitespace is stored, not deleted. *)
17
18 let ws_and_comment = ws . no_ws_comment
19
20 (* Either a word or a quoted string *)
21 let str_store = store /[A-Za-z0-9_.\/-]+|\"([^\"\\\\]|(\\\\.))*\"|'([^'\\\\]|(\\\\.))*'/
22
23 let str = [ label "string" . str_store ]
24
25 let var_name = key Rx.word
26
27 let rec thing =
28     let array = [ label "array" . lbrack . Build.opt_list thing ws . ws_and_comment? . rbrack ] in
29     let str = [ label "item" . str_store ] in
30     str | array
31
32 let sexpr = [ lbrack . var_name . ws . no_ws_comment? . thing . ws_and_comment? . rbrack ]
33
34 let lns = ( empty_line | standalone_comment | sexpr ) *
35
36 let filter = incl "xend-config.sxp"
37 let xfm = transform lns filter