[augeas-devel] Rewriting inifile.aug

David Lutterkort dlutter at redhat.com
Fri Aug 15 00:11:42 UTC 2008


On Thu, 2008-08-14 at 11:56 +0200, Raphaël Pinson wrote:
> As I'm playing with inifile.aug and applying it to php.aug, mysql.aug
> and dput.aug, I find so many different configurations that inifile.aug
> gets very complicated to my taste. Since functions in lenses cannot
> take defaults, I end up defining lots of them to set more or less
> variables. I would like to really simplify inifile.aug. This might
> mean making the lenses that use it a bit more complicated, but also
> clearer.
>
> Here is my proposal. Comments are very welcome:

I think overall, this would be a very good change.

> Writing a generic INI file using inifile.aug would look like this :
> 
> =========================================================
> let comment_re      = /[;#]/
> let comment_default = ";"
> let comment         = IniFile.comment comment_re comment_default
> 
> let empty           = IniFile.empty comment_re
> 
> let sep_re          = /[:=]/
> let sep_default     = "="
> let sep             = IniFile.sep sep_re sep_default
> 
> (* IniFile.entry_re  = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/ ) *)

You don't need to do the '-' here since '#comment' isn't the name of a
valid entry.

> Another example, with dput.aug :

I actually like that a lot since it has the things in which inifiles
vary right there in the lens.

> It is obviously longer than the current format, but also much clearer
> on what is accepted and what is not. Alternatively, this is php.aug:
> 
> =========================================================
> 
> let comment  = IniFile.comment IniFile.comment_re
> IniFile.comment_default
> let empty      = IniFile.empty IniFile.comment_re
> let eol          = IniFile.eol
> 
> let sep          = IniFile.sep IniFile.sep_re IniFile.set_default
> 
> (*
>   We have to remove the keyword "section" from possible entry keywords
>   otherwise it would lead to an ambiguity with the "section" label
>   since PHP allows entries outside of sections.
> *)
> let entry_re  = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/
> - /section/ )
> let entry = IniFile.entry entry_re sep comment

You should be able to stuff such 'bare' entries into a section with a
special label, e.g. '.anon' or so.

> let title
>            = label "section"
>              .Util.del_str "[" . store /[^]]+/
>              . Util.del_str "]". eol
>
> let record = [ title_label
>              . (entry | comment | empty)* ]

That would require a

        let anon_record [ label ".anon" . (entry | comment | empty)* ]

> let lns    = ( comment | empty | entry )* . record*

     let lns = (comment | empty)* . anon_record? . record*

Haven't tried it though, so the typechecker might get upset. That would
have the advantage that you can use the title of a section as a key (if
the regexp for that can be restructed to a regexp that doesn't match
'.anon')

David






More information about the augeas-devel mailing list