<div dir="ltr">Actually, here is an even more compact version :<br><br>inifile.aug :<br><br>==============================================================<br>module IniFile  =<br><br>    (* Define useful shortcuts *)<br><br>
    let eol = Util.del_str "\n"<br>    let del_to_eol = del /[^\n]*/ ""<br>    let value_sep = del /[ \t]*=[ \t]*/ "="<br>    let value_to_eol = store /([^ \t\n][^\n]*)?/<br><br><br>    (* Define entry function *)<br>
<br>    let entry (kw:regexp) = [ key kw . value_sep . value_to_eol . eol ]<br><br>    (* Define comment and empty strings *)<br><br>    let comment = [ label "comment" . del /#[ \t]*/ "#" .  store /([^ \t\n][^\n]*)?/ . eol ]<br>
    let empty  = [ del /[ \t]*/ "" . eol ]<br><br><br>    (* Define record *)<br><br>    let title = Util.del_str "[" . store /[^]= ]+/ . Util.del_str "]". eol<br><br>    let record (label_name:string) (entry:lens) = [ label label_name . title . entry* ]<br>
<br><br>    let lns (record:lens) = ( comment | empty | record )*<br><br><br><br>==============================================================<br><br>and dput.aug :<br><br>==============================================================<br>
<br>module Dput =<br>  autoload xfm<br><br>    let settings = IniFile.entry "allow_non-us_software"<br>                 | IniFile.entry "allow_unsigned_uploads"<br>                 | IniFile.entry "check_version"<br>
                 | IniFile.entry "default_host_main"<br>                 | IniFile.entry "default_host_non-us"<br>                 | IniFile.entry "fqdn"<br>                 | IniFile.entry "hash"<br>
                 | IniFile.entry "incoming"<br>                 | IniFile.entry "login"<br>                 | IniFile.entry "method"<br>                 | IniFile.entry "passive_ftp"<br>
                 | IniFile.entry "post_upload_command"<br>                 | IniFile.entry "pre_upload_command"<br>                 | IniFile.entry "run_dinstall"<br>                 | IniFile.entry "run_lintian"<br>
                 | IniFile.entry "scp_compress"<br><br><br>    let record = IniFile.record "target" settings<br><br><br>    let lns = IniFile.lns record<br><br>    let filter = (incl "/etc/<a href="http://dput.cf">dput.cf</a>")<br>
        . (incl "~/.<a href="http://dput.cf">dput.cf</a>")<br>        . Util.stdexcl<br><br>    let xfm = transform lns filter<br><br>==============================================================<br><br><br><div class="gmail_quote">
On Tue, Jul 22, 2008 at 10:54 AM, Raphaël Pinson <<a href="mailto:raphink@gmail.com">raphink@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">Hi guys,<br><br>I'm experimenting with generic modules. My first one is for Ini files.<br><br><br>==============================================================<br>module IniFile  =<br><br>    (* Define useful shortcuts *)<br>

<br>    let eol = Util.del_str "\n"<br>    let del_to_eol = del /[^\n]*/ ""<br>    let value_sep = del /[ \t]*=[ \t]*/ "="<br>    let value_to_eol = store /([^ \t\n][^\n]*)?/<br><br><br>    (* Define entry function *)<br>

<br>    let entry (kw:regexp) = [ key kw . value_sep . value_to_eol . eol ]<br><br>    (* Define comment and empty strings *)<br><br>    let comment = [ label "comment" . del /#[ \t]*/ "#" .  store /([^ \t\n][^\n]*)?/ . eol ]<br>

    let empty  = [ del /[ \t]*/ "" . eol ]<br><br><br>    (* Define record *)<br><br>    let title = Util.del_str "[" . store /[^]= ]+/ . Util.del_str "]". eol<br><br>    let record (label_name:string) (entry:lens) = [ label label_name . title . entry* ]<br>

==============================================================<br><br><br>which allows me to rewrite dput.aug as :<br><br><br>==============================================================<br><br>module Dput =<br>  autoload xfm<br>

<br>    let settings = IniFile.entry "allow_non-us_software"<br>                 | IniFile.entry "allow_unsigned_uploads"<br>                 | IniFile.entry "check_version"<br>                 | IniFile.entry "default_host_main"<br>

                 | IniFile.entry "default_host_non-us"<br>                 | IniFile.entry "fqdn"<br>                 | IniFile.entry "hash"<br>                 | IniFile.entry "incoming"<br>

                 | IniFile.entry "login"<br>                 | IniFile.entry "method"<br>                 | IniFile.entry "passive_ftp"<br>                 | IniFile.entry "post_upload_command"<br>

                 | IniFile.entry "pre_upload_command"<br>                 | IniFile.entry "run_dinstall"<br>                 | IniFile.entry "run_lintian"<br>                 | IniFile.entry "scp_compress"<br>

<br><br>    let record = IniFile.record "target" settings<br><br><br>    let lns = ( IniFile.comment | record | IniFile.empty )*<br><br>    let filter = (incl "/etc/<a href="http://dput.cf" target="_blank">dput.cf</a>")<br>

        . (incl "~/.<a href="http://dput.cf" target="_blank">dput.cf</a>")<br>        . Util.stdexcl<br><br>    let xfm = transform lns filter<br><br><br>==============================================================<br>
<br><br>
Obviously, this is a work in progress, which might not yet support all kinds of generic IniFiles syntax. All comments and contributions are welcome.<br><br><br>Cheers,<br><br><br>Raphaël<br></div>
</blockquote></div><br></div>