[augeas-devel] ConfigObj: working lens seeking tips/improvements

Yclept Nemo orbisvicis at gmail.com
Mon Nov 2 16:56:49 UTC 2015


Hi,

> I'm sorry to say that, but personally, I have too little time to learn
your lens to the same level as you know it

That's no-problem/understandable, for others I've substituted the
ConfigObj_Simple module with generic constructs.

> I can only repeat a tip from the parallel mail thread: Use variables and
constructs from the generic Augeas modules like Rx, Util, Sep and Build.
> Hence they are very refined and allow people foreign to your code a quick
start

Here is the ConfigObj_Simple module with as much as possible substituted
with generic module constructs. There really isn't much simplification
possible due to the differing definitions of both comments (module Util)
and quotes (module Quote):

(* ConfigObj_Simple lens:
   Pro:
    * removes extraneous nodes "type" and "commented = false"
    * fast
   Con:
    * returns raw values - stripping surrounding quotes from value_qstring
creates overlapping lenses in union.put
    * does not validate value types internally
    * child nodes of record are still order-dependent: "commented" before
".comment"
*)

module ConfigObj_Simple =
    let spaces              = Util.del_opt_ws " "
    let newline             = Util.del_str "\n"
    let option              = key /[a-z]([a-z_]*[a-z])?/
    let value_all           = store (/"([^\n\"]*([\].)*)*"/ | /[^ \t\n"#][^
\t\n#]*/)
    let sep_comment         = Util.del_str "#"
    let comment_label       = label ".comment"
    let record_commented    = [ sep_comment . spaces . label "commented" ]
    let record_comment      = [ comment_label . sep_comment . store /.*/ ]
    let record_simple       = option . spaces . Sep.equal . (spaces .
value_all)? . (Sep.opt_space | (spaces . record_comment))
    let record              = [ record_commented? . record_simple ]
    let comment             = [ comment_label . sep_comment . store (/.*/ -
(/[ \t]*/ . lens_ctype record_simple)) ]
    let entry               = Util.indent . ( record | comment ) . newline
    let empty               = [ Util.eol ]
    let line                = empty | entry
    let lns                 = line *

> Besides that, the generic Build module provides functions, that show you,
how you could combine lenses with no strict ordering or existence:
http://augeas.net/docs/references/lenses/files/build-aug.html#Build.COMBINATORICS
.

That is a good idea but doesn't help in situtations such as
ConfigObj_Simple or (simplified):

module AmbiguousCombinatorics =
    let a   = store /a/ . [ label ".comment" ]
    let b   = [ label "commented" ]
    let c   = [ Build.combine_two a b ]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20151102/19ebdb7c/attachment.htm>


More information about the augeas-devel mailing list