Build

Generic functions to build lenses

Author: Raphael Pinson rap.nosp@m.hink@gmai.nosp@m.l.com

Summary
BuildGeneric functions to build lenses
LicenseThis file is licensed under the LGPLv2+, like the rest of Augeas.
ReferenceThis file provides generic functions to build Augeas lenses
GENERIC CONSTRUCTIONS
bracketsPut a lens inside brackets
LIST CONSTRUCTIONS
listBuild a list of identical lenses separated with a given separator (at least 2 elements)
opt_listSame as list, but there might be only one element in the list
LABEL OPERATIONS
xchgReplace 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
xchgsSame as xchg, but the pattern is the default string
SUBNODE CONSTRUCTIONS
key_value_lineA subnode with a keyword, a separator and a storing lens, and an end of line
key_value_line_commentSame as key_value_line, but allows to have a comment in the end of a line and an end of line
key_valueSame as key_value_line, but does not end with an end of line
flagA simple flag subnode, consisting of a single key

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

let brackets (l:lens) (r:lens) (lns:lens) = l . lns . r

Put a lens inside brackets

Parameters

l:lensthe left bracket lens
r: lensthe right bracket lens
lns:lensthe lens to put inside brackets

LIST CONSTRUCTIONS

list

let list (lns:lens) (sep:lens) = lns . ( sep . lns )+

Build a list of identical lenses separated with a given separator (at least 2 elements)

Parameters

lns:lensthe lens to repeat in the list
sep:lensthe separator lens, which can be taken from the Sep module

opt_list

let opt_list (lns:lens) (sep:lens) = lns . ( sep . lns )*

Same as list, but there might be only one element in the list

Parameters

lns:lensthe lens to repeat in the list
sep:lensthe separator lens, which can be taken from the Sep module

LABEL OPERATIONS

xchg

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

Parameters

m:regexpthe pattern to match
d:stringthe default value when a node in created
l:stringthe label to apply for such nodes

xchgs

let xchgs (m:string) (l:string) = xchg m m l

Same as xchg, but the pattern is the default string

Parameters

m:stringthe string to replace, also used as default
l:stringthe label to apply for such nodes

SUBNODE CONSTRUCTIONS

key_value_line

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

Parameters

kw:regexpthe pattern to match as key
sep:lensthe separator lens, which can be taken from the Sep module
sto:lensthe storing lens

key_value_line_comment

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

Parameters

kw:regexpthe pattern to match as key
sep:lensthe separator lens, which can be taken from the Sep module
sto:lensthe storing lens
comment:lensthe comment lens, which can be taken from Util

key_value

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

Parameters

kw:regexpthe pattern to match as key
sep:lensthe separator lens, which can be taken from the Sep module
sto:lensthe storing lens

flag

let flag (kw:regexp) = [ key kw ]

A simple flag subnode, consisting of a single key

Parameters

kw:regexpthe pattern to match as key
let brackets (l:lens) (r:lens) (lns:lens) = l . lns . r
Put a lens inside brackets
let list (lns:lens) (sep:lens) = lns . ( sep . lns )+
Build a list of identical lenses separated with a given separator (at least 2 elements)
let opt_list (lns:lens) (sep:lens) = lns . ( sep . lns )*
Same as list, but there might be only one element in the list
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
let xchgs (m:string) (l:string) = xchg m m l
Same as xchg, but the pattern is the default string
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
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
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
let flag (kw:regexp) = [ key kw ]
A simple flag subnode, consisting of a single key
Generic separators to build lenses
Generic module providing useful primitives
Close