Generic functions to build lenses
Author: Raphael Pinson raphink@gmail.com
| 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 |
| flag | A simple flag subnode, 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 |
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 ]
A simple flag subnode, consisting of a single key
let flag ( kw:regexp ) = [ key kw ]