[augeas-devel] Re: Rewriting inifile.aug

Raphaël Pinson raphink at gmail.com
Thu Aug 14 10:07:47 UTC 2008


On Thu, Aug 14, 2008 at 11:56 AM, Raphaël Pinson <raphink at gmail.com> wrote:

> Hi there,
>
>
> 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:
>
> 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/ ) *)
> let entry_re        = IniFile.entry_re
> let entry            = IniFile.entry entry_re sep comment
>
> (* IniFile.record_re = ( /[^]\n\/]+/ - /#comment/ ) *)
> let record_re      = IniFile.record_re
> let record          = IniFile.record record_re entry comment empty
>
>
> let lns             = IniFile.lns record comment
> =========================================================
>
>
> This would be a bit longer than it is currently, but much clearer, too.
>
> The values taken by the setting fields would be:
>
> comment_re        := ";"| "#" | /[;#]/
> comment_default := ";" | "#"
>
> sep_re                 := ":" | "=" | /[:=]/
> sep_default          := ";" | "="
>
> entry_re               := IniFile.entry_re | your_own_re
>
> record_re             := IniFile.record_re | your_own_re
>
> Other values for these fields could not be certified to work properly.
>
>
> Default values provided:
>
> IniFile.comment_re        = /[;#]/
> IniFile.comment_default = ";"
> IniFile.sep_re                = /[:=]/
> IniFile.sep_default         = "="
> IniFile.entry_re              = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/ )
> IniFile.record_re            = ( /[^]\n\/]+/ - /#comment/ )
>
>
> Additionally, IniFile.record_noempty and IniFile.lns_noempty would be
> provided, since I don't know how to deal with these.
>
>
> Another example, with dput.aug :
>
> =========================================================
>
> let comment  = IniFile.comment IniFile.comment_re IniFile.comment_default
> let empty      = IniFile.empty IniFile.comment_re
>
> let sep          = IniFile.sep IniFile.sep_re IniFile.set_default
>
> let setting = "allow_non-us_software"
>                | "allow_unsigned_uploads"
>                | "check_version"
>                | "default_host_main"
>                | "default_host_non-us"
>                | "fqdn"
>                | "hash"
>                | "incoming"
>                | "login"
>                | "method"
>                | "passive_ftp"
>                | "post_upload_command"
>                | "pre_upload_command"
>                | "progress_indicator"
>                | "run_dinstall"
>                | "run_lintian"
>                | "scp_compress"
>                | "ssh_config_options"
> let entry = IniFile.entry setting sep comment
>
> let record  = IniFile.record IniFile.record_re entry comment empty
>
> let lns    = IniFile.lns record comment
> =========================================================
>
>
> 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
>
> let title
>            = label "section"
>              .Util.del_str "[" . store /[^]]+/
>              . Util.del_str "]". eol
>
> let record = [ title_label
>              . (entry | comment | empty)* ]
>
> let lns    = ( comment | empty | entry )* . record*
> =========================================================
>
>

Alternatively, PHP.lns could be

let lns = IniFile.lns record (comment|entry)

This trick would send (comment|entry) as the comment lens for IniFile.lns,
so lns would be equivalent to:

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



Raphaël
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080814/e8f99c61/attachment.htm>


More information about the augeas-devel mailing list