Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / sysconfig.aug
1 (* Variation of the Shellvars lens                                     *)
2 (* Supports only what's needed to handle sysconfig files               *)
3 (* Modified to strip quotes. In the put direction, add double quotes   *)
4 (* around values that need them                                        *)
5 (* To keep things simple, we also do not support shell variable arrays *)
6 module Sysconfig =
7
8   let eol = Shellvars.eol
9   let semicol_eol = Shellvars.semicol_eol
10
11   let key_re = Shellvars.key_re
12   let eq = Util.del_str "="
13
14   let eol_for_comment = del /([ \t]*\n)([ \t]*(#[ \t]*)?\n)*/ "\n"
15   let comment = Util.comment_generic_seteol /[ \t]*#[ \t]*/ "# " eol_for_comment
16   let comment_or_eol = Shellvars.comment_or_eol
17
18   let empty   = Util.empty
19
20   let bchar = /[^; \t\n"'\\]|\\\\./ (* " Emacs, relax *)
21   let qchar = /["']/  (* " Emacs, relax *)
22
23   (* We split the handling of right hand sides into a few cases:
24    *   bare  - strings that contain no spaces, optionally enclosed in
25    *           single or double quotes
26    *   quot  - strings that must be enclosed in single or double quotes
27    *   dquot - strings that contain at least one space or apostrophe,
28    *           which must be enclosed in double quotes
29    *   squot - strings that contain an unescaped double quote
30    *)
31   let bare = Quote.do_quote_opt (store bchar+)
32
33   let quot =
34     let word = bchar* . /[; \t]/ . bchar* in
35     Quote.do_quote (store word+)
36
37   let dquot =
38     let char = /[^"\\]|\\\\./ in             (* " *)
39     let word = char* . "'" . char* in
40     Quote.do_dquote (store word+)
41
42   let squot =
43     (* We do not allow escaped double quotes in single quoted strings, as  *)
44     (* that leads to a put ambiguity with bare, e.g. for the string '\"'.  *)
45     let char = /[^'\\]|\\\\[^"]/ in           (* " *)
46     let word = char* . "\"" . char* in
47     Quote.do_squote (store word+)
48
49   let kv (value:lens) =
50     let export = Shellvars.export in
51     let indent = Util.del_opt_ws "" in
52     [ indent . export? . key key_re . eq . value . comment_or_eol ]
53
54   let assign =
55     let nothing = del /(""|'')?/ "" . value "" in
56     kv nothing | kv bare | kv quot | kv dquot | kv squot
57
58   let var_action = Shellvars.var_action
59
60   let unset = [ var_action "unset" . comment_or_eol ]
61   let bare_export = [ var_action "export" . comment_or_eol ]
62
63   let source = [ Shellvars.source . comment_or_eol ]
64
65   let lns = empty* . (comment | source | assign | unset | bare_export)*
66
67 (*
68   Examples:
69
70   abc   -> abc -> abc
71   "abc" -> abc -> abc
72   "a b" -> a b -> "a b"
73   'a"b' -> a"b -> 'a"b'
74 *)