Named blocks standardization

Contents

Rationale

Several lenses (logrotate.aug, xinetd.aug, keepalived.aug, aptconf.aug, dhclient.aug, shellvars.aug) use named blocks with the following syntax:

  block_name {
     entry+
  }

but each lens implements it differently. It would be good to add a (or several types of) block entry to build.aug to make it easier to build such blocks in a standard way.


Existing implementations

The following are existing implementations of such blocks. They are not working examples, but they show the general pattern of each implementation.


xinetd.aug

Code

 let body (attr:lens) = del /\n\{[ \t]*\n/ "\n{\n"
                      . (empty|comment|attr)*
                      . del /[ \t]*\}[ \t]*\n/ "}\n"
  
 let service =
    let sto_re = /[^# \t\n\/]+/ in
    [ key "service" . Sep.space . store sto_re . body service_attr ]


Notes


logrotate.aug

Code

  let body = del /\{[ \t]*\n/ "{\n"
                      . ( comment "\t" | attrs "\t" | hooks | empty )*
                      . del /[ \t]*\}[ \t]*\n/ "}\n"
  
  let rule =
    [ label "rule" . Util.indent .
        [ label "file" . store filename ] .
        [ del /[ \t\n]+/ " " . label "file" . store filename ]* .
        del /[ \t\n]*/ " " . body ]


Notes


keepalived.aug

Code

  let lbracket = Util.del_str "{"
  
  let rbracket = Util.del_str "}"
  
  let lens_block (title:lens) (sto:lens) = [ indent . title . opt_eol . lbracket
                                        . (sto | empty | comment)+
                                        . indent . rbracket . eol ]

Notes


aptconf.aug

Code

 let rec entry_noeol =
  let value =
     Util.del_str "\"" . store /[^"\n]+/
                       . del /";?/ "\";" in
  let opt_eol = del /[ \t\n]*/ "\n" in
  let long_eol = del /[ \t]*\n+/ "\n" in
  let list_elem = [ opt_eol . label "@elem" . value ] in
  let eol_comment = del /([ \t\n]*\n)?/ "" . comment in
      [ key name_re . Sep.space . value ]
    | [ key name_re . del /[ \t\n]*\{/ " {" .
          ( (opt_eol . entry_noeol) |
            list_elem |
            eol_comment
            )* .
          del /[ \t\n]*\};?/ "\n};" ]
    | [ key name_re . Util.del_str "::" . entry_noeol ]
 
 let entry = indent . entry_noeol . eol

Notes


Comparison of existing implementations

eol before lbracket eol after lbracket eol before rbracket block name
xinetd mandatory mandatory mandatory
logrotate optional mandatory mandatory
keepalived optional optional mandatory
aptconf optional optional optional

Problems

The main issue has to do with newlines:

MediaWiki
GNU Free Documentation License 1.2