[augeas-devel] Re: Towards generic modules
Raphaël Pinson
raphink at gmail.com
Tue Jul 22 08:58:27 UTC 2008
Actually, here is an even more compact version :
inifile.aug :
==============================================================
module IniFile =
(* Define useful shortcuts *)
let eol = Util.del_str "\n"
let del_to_eol = del /[^\n]*/ ""
let value_sep = del /[ \t]*=[ \t]*/ "="
let value_to_eol = store /([^ \t\n][^\n]*)?/
(* Define entry function *)
let entry (kw:regexp) = [ key kw . value_sep . value_to_eol . eol ]
(* Define comment and empty strings *)
let comment = [ label "comment" . del /#[ \t]*/ "#" . store /([^
\t\n][^\n]*)?/ . eol ]
let empty = [ del /[ \t]*/ "" . eol ]
(* Define record *)
let title = Util.del_str "[" . store /[^]= ]+/ . Util.del_str "]". eol
let record (label_name:string) (entry:lens) = [ label label_name . title
. entry* ]
let lns (record:lens) = ( comment | empty | record )*
==============================================================
and dput.aug :
==============================================================
module Dput =
autoload xfm
let settings = IniFile.entry "allow_non-us_software"
| IniFile.entry "allow_unsigned_uploads"
| IniFile.entry "check_version"
| IniFile.entry "default_host_main"
| IniFile.entry "default_host_non-us"
| IniFile.entry "fqdn"
| IniFile.entry "hash"
| IniFile.entry "incoming"
| IniFile.entry "login"
| IniFile.entry "method"
| IniFile.entry "passive_ftp"
| IniFile.entry "post_upload_command"
| IniFile.entry "pre_upload_command"
| IniFile.entry "run_dinstall"
| IniFile.entry "run_lintian"
| IniFile.entry "scp_compress"
let record = IniFile.record "target" settings
let lns = IniFile.lns record
let filter = (incl "/etc/dput.cf")
. (incl "~/.dput.cf")
. Util.stdexcl
let xfm = transform lns filter
==============================================================
On Tue, Jul 22, 2008 at 10:54 AM, Raphaël Pinson <raphink at gmail.com> wrote:
> Hi guys,
>
> I'm experimenting with generic modules. My first one is for Ini files.
>
>
> ==============================================================
> module IniFile =
>
> (* Define useful shortcuts *)
>
> let eol = Util.del_str "\n"
> let del_to_eol = del /[^\n]*/ ""
> let value_sep = del /[ \t]*=[ \t]*/ "="
> let value_to_eol = store /([^ \t\n][^\n]*)?/
>
>
> (* Define entry function *)
>
> let entry (kw:regexp) = [ key kw . value_sep . value_to_eol . eol ]
>
> (* Define comment and empty strings *)
>
> let comment = [ label "comment" . del /#[ \t]*/ "#" . store /([^
> \t\n][^\n]*)?/ . eol ]
> let empty = [ del /[ \t]*/ "" . eol ]
>
>
> (* Define record *)
>
> let title = Util.del_str "[" . store /[^]= ]+/ . Util.del_str "]". eol
>
> let record (label_name:string) (entry:lens) = [ label label_name .
> title . entry* ]
> ==============================================================
>
>
> which allows me to rewrite dput.aug as :
>
>
> ==============================================================
>
> module Dput =
> autoload xfm
>
> let settings = IniFile.entry "allow_non-us_software"
> | IniFile.entry "allow_unsigned_uploads"
> | IniFile.entry "check_version"
> | IniFile.entry "default_host_main"
> | IniFile.entry "default_host_non-us"
> | IniFile.entry "fqdn"
> | IniFile.entry "hash"
> | IniFile.entry "incoming"
> | IniFile.entry "login"
> | IniFile.entry "method"
> | IniFile.entry "passive_ftp"
> | IniFile.entry "post_upload_command"
> | IniFile.entry "pre_upload_command"
> | IniFile.entry "run_dinstall"
> | IniFile.entry "run_lintian"
> | IniFile.entry "scp_compress"
>
>
> let record = IniFile.record "target" settings
>
>
> let lns = ( IniFile.comment | record | IniFile.empty )*
>
> let filter = (incl "/etc/dput.cf")
> . (incl "~/.dput.cf")
> . Util.stdexcl
>
> let xfm = transform lns filter
>
>
> ==============================================================
>
>
> Obviously, this is a work in progress, which might not yet support all
> kinds of generic IniFiles syntax. All comments and contributions are
> welcome.
>
>
> Cheers,
>
>
> Raphaël
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080722/8f7b9efb/attachment.htm>
More information about the augeas-devel
mailing list