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 *)
8 let eol = Shellvars.eol
9 let semicol_eol = Shellvars.semicol_eol
11 let key_re = Shellvars.key_re
12 let eq = Util.del_str "="
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
18 let empty = Util.empty
20 let bchar = /[^; \t\n"'\\]|\\\\./ (* " Emacs, relax *)
21 let qchar = /["']/ (* " Emacs, relax *)
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
31 let bare = Quote.do_quote_opt (store bchar+)
34 let word = bchar* . /[; \t]/ . bchar* in
35 Quote.do_quote (store word+)
38 let char = /[^"\\]|\\\\./ in (* " *)
39 let word = char* . "'" . char* in
40 Quote.do_dquote (store word+)
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+)
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 ]
55 let nothing = del /(""|'')?/ "" . value "" in
56 kv nothing | kv bare | kv quot | kv dquot | kv squot
58 let var_action = Shellvars.var_action
60 let unset = [ var_action "unset" . comment_or_eol ]
61 let bare_export = [ var_action "export" . comment_or_eol ]
63 let source = [ Shellvars.source . comment_or_eol ]
65 let lns = empty* . (comment | source | assign | unset | bare_export)*