|
Packit Service |
a2ae7a |
(* Variation of the Shellvars lens *)
|
|
Packit Service |
a2ae7a |
(* Supports only what's needed to handle sysconfig files *)
|
|
Packit Service |
a2ae7a |
(* Modified to strip quotes. In the put direction, add double quotes *)
|
|
Packit Service |
a2ae7a |
(* around values that need them *)
|
|
Packit Service |
a2ae7a |
(* To keep things simple, we also do not support shell variable arrays *)
|
|
Packit Service |
a2ae7a |
module Sysconfig =
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let eol = Shellvars.eol
|
|
Packit Service |
a2ae7a |
let semicol_eol = Shellvars.semicol_eol
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let key_re = Shellvars.key_re
|
|
Packit Service |
a2ae7a |
let eq = Util.del_str "="
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let eol_for_comment = del /([ \t]*\n)([ \t]*(#[ \t]*)?\n)*/ "\n"
|
|
Packit Service |
a2ae7a |
let comment = Util.comment_generic_seteol /[ \t]*#[ \t]*/ "# " eol_for_comment
|
|
Packit Service |
a2ae7a |
let comment_or_eol = Shellvars.comment_or_eol
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let empty = Util.empty
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let bchar = /[^; \t\n"'\\]|\\\\./ (* " Emacs, relax *)
|
|
Packit Service |
a2ae7a |
let qchar = /["']/ (* " Emacs, relax *)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* We split the handling of right hand sides into a few cases:
|
|
Packit Service |
a2ae7a |
* bare - strings that contain no spaces, optionally enclosed in
|
|
Packit Service |
a2ae7a |
* single or double quotes
|
|
Packit Service |
a2ae7a |
* quot - strings that must be enclosed in single or double quotes
|
|
Packit Service |
a2ae7a |
* dquot - strings that contain at least one space or apostrophe,
|
|
Packit Service |
a2ae7a |
* which must be enclosed in double quotes
|
|
Packit Service |
a2ae7a |
* squot - strings that contain an unescaped double quote
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
let bare = Quote.do_quote_opt (store bchar+)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let quot =
|
|
Packit Service |
a2ae7a |
let word = bchar* . /[; \t]/ . bchar* in
|
|
Packit Service |
a2ae7a |
Quote.do_quote (store word+)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let dquot =
|
|
Packit Service |
a2ae7a |
let char = /[^"\\]|\\\\./ in (* " *)
|
|
Packit Service |
a2ae7a |
let word = char* . "'" . char* in
|
|
Packit Service |
a2ae7a |
Quote.do_dquote (store word+)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let squot =
|
|
Packit Service |
a2ae7a |
(* We do not allow escaped double quotes in single quoted strings, as *)
|
|
Packit Service |
a2ae7a |
(* that leads to a put ambiguity with bare, e.g. for the string '\"'. *)
|
|
Packit Service |
a2ae7a |
let char = /[^'\\]|\\\\[^"]/ in (* " *)
|
|
Packit Service |
a2ae7a |
let word = char* . "\"" . char* in
|
|
Packit Service |
a2ae7a |
Quote.do_squote (store word+)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let kv (value:lens) =
|
|
Packit Service |
a2ae7a |
let export = Shellvars.export in
|
|
Packit Service |
a2ae7a |
let indent = Util.del_opt_ws "" in
|
|
Packit Service |
a2ae7a |
[ indent . export? . key key_re . eq . value . comment_or_eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let assign =
|
|
Packit Service |
a2ae7a |
let nothing = del /(""|'')?/ "" . value "" in
|
|
Packit Service |
a2ae7a |
kv nothing | kv bare | kv quot | kv dquot | kv squot
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let var_action = Shellvars.var_action
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let unset = [ var_action "unset" . comment_or_eol ]
|
|
Packit Service |
a2ae7a |
let bare_export = [ var_action "export" . comment_or_eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let source = [ Shellvars.source . comment_or_eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let lns = empty* . (comment | source | assign | unset | bare_export)*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
Examples:
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
abc -> abc -> abc
|
|
Packit Service |
a2ae7a |
"abc" -> abc -> abc
|
|
Packit Service |
a2ae7a |
"a b" -> a b -> "a b"
|
|
Packit Service |
a2ae7a |
'a"b' -> a"b -> 'a"b'
|
|
Packit Service |
a2ae7a |
*)
|