Generic functions to build lenses
Author: Raphael Pinson rap@gmai l.com hink
Build | Generic functions to build lenses |
License | This file is licensed under the LGPLv2+, like the rest of Augeas. |
Reference | This file provides generic functions to build Augeas lenses |
GENERIC CONSTRUCTIONS | |
brackets | Put a lens inside brackets |
LIST CONSTRUCTIONS | |
list | Build a list of identical lenses separated with a given separator (at least 2 elements) |
opt_list | Same as list, but there might be only one element in the list |
LABEL OPERATIONS | |
xchg | Replace a pattern with a different label in the tree, thus emulating a key but allowing to replace the keyword with a different value than matched |
xchgs | Same as xchg, but the pattern is the default string |
SUBNODE CONSTRUCTIONS | |
key_value_line | A subnode with a keyword, a separator and a storing lens, and an end of line |
key_value_line_comment | Same as key_value_line, but allows to have a comment in the end of a line and an end of line |
key_value | Same as key_value_line, but does not end with an end of line |
key_ws_value | Store a key/value pair where key and value are separated by whitespace and the value goes to the end of the line. |
flag | A simple flag subnode, consisting of a single key |
flag_line | A simple flag line, consisting of a single key |
let list (lns:lens) (sep:lens) = lns . ( sep . lns )+
Build a list of identical lenses separated with a given separator (at least 2 elements)
lns:lens | the lens to repeat in the list |
sep:lens | the separator lens, which can be taken from the Sep module |
let xchg (m:regexp) (d:string) (l:string) = del m d . label l
Replace a pattern with a different label in the tree, thus emulating a key but allowing to replace the keyword with a different value than matched
m:regexp | the pattern to match |
d:string | the default value when a node in created |
l:string | the label to apply for such nodes |
let xchgs (m:string) (l:string) = xchg m m l
Same as xchg, but the pattern is the default string
m:string | the string to replace, also used as default |
l:string | the label to apply for such nodes |
let key_value_line (kw:regexp) (sep:lens) (sto:lens) = [ key kw . sep . sto . eol ]
A subnode with a keyword, a separator and a storing lens, and an end of line
kw:regexp | the pattern to match as key |
sep:lens | the separator lens, which can be taken from the Sep module |
sto:lens | the storing lens |
let key_value_line_comment (kw:regexp) (sep:lens) (sto:lens) (comment:lens) = [ key kw . sep . sto . (eol|comment) ]
Same as key_value_line, but allows to have a comment in the end of a line and an end of line
kw:regexp | the pattern to match as key |
sep:lens | the separator lens, which can be taken from the Sep module |
sto:lens | the storing lens |
comment:lens | the comment lens, which can be taken from Util |
let key_value (kw: regexp) (sep:lens) (sto:lens) = [ key kw . sep . sto ]
Same as key_value_line, but does not end with an end of line
kw:regexp | the pattern to match as key |
sep:lens | the separator lens, which can be taken from the Sep module |
sto:lens | the storing lens |
let key_ws_value (kw:regexp) = key_value_line kw Util.del_ws_spc (store Rx.space_in)
Store a key/value pair where key and value are separated by whitespace and the value goes to the end of the line. Leading and trailing whitespace is stripped from the value. The end of line is consumed by this lens
kw:regexp | the pattern to match as key |
Put a lens inside brackets
let brackets (l:lens) (r:lens) (lns:lens) = l . lns . r
Build a list of identical lenses separated with a given separator (at least 2 elements)
let list (lns:lens) (sep:lens) = lns . ( sep . lns )+
Same as list, but there might be only one element in the list
let opt_list (lns:lens) (sep:lens) = lns . ( sep . lns )*
Replace a pattern with a different label in the tree, thus emulating a key but allowing to replace the keyword with a different value than matched
let xchg (m:regexp) (d:string) (l:string) = del m d . label l
Same as xchg, but the pattern is the default string
let xchgs (m:string) (l:string) = xchg m m l
A subnode with a keyword, a separator and a storing lens, and an end of line
let key_value_line (kw:regexp) (sep:lens) (sto:lens) = [ key kw . sep . sto . eol ]
Same as key_value_line, but allows to have a comment in the end of a line and an end of line
let key_value_line_comment (kw:regexp) (sep:lens) (sto:lens) (comment:lens) = [ key kw . sep . sto . (eol|comment) ]
Same as key_value_line, but does not end with an end of line
let key_value (kw: regexp) (sep:lens) (sto:lens) = [ key kw . sep . sto ]
Store a key/value pair where key and value are separated by whitespace and the value goes to the end of the line.
let key_ws_value (kw:regexp) = key_value_line kw Util.del_ws_spc (store Rx.space_in)
A simple flag subnode, consisting of a single key
let flag (kw:regexp) = [ key kw ]
A simple flag line, consisting of a single key
let flag_line (kw:regexp) = [ key kw . eol ]