[augeas-devel] [PATCH 1 of 3] Reformat inifile.aug

Raphael Pinson raphink at gmail.com
Wed Aug 13 12:18:18 UTC 2008


# HG changeset patch
# User Raphael Pinson <raphink at gmail.com>
# Date 1218628615 -7200
# Node ID b22b3b7537c7992bce8eaea6e69f721763e883a7
# Parent  7ac7473e10636235227b7c98acff5b99ca794821
Reformat inifile.aug
Ignore empty comments

diff -r 7ac7473e1063 -r b22b3b7537c7 lenses/inifile.aug
--- a/lenses/inifile.aug	Wed Aug 13 12:58:02 2008 +0200
+++ b/lenses/inifile.aug	Wed Aug 13 13:56:55 2008 +0200
@@ -5,48 +5,95 @@
 
 module IniFile  =
 
-    (* Define useful shortcuts *)
 
-    let eol                = del /[ \t]*\n/ "\n"
-    let value_sep          = del /[ \t]*=/ " = "
-    let value_sepwithcolon = del /[ \t]*(=|:)/ " = "
-    let value_to_eol       = del /[ \t]*/ " " . store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
-    let value_to_comment   = del /[ \t]*/ " " . store /[^;# \t\n][^;#\n]*[^;# \t\n]|[^;# \t\n]/
+(************************************************************************
+ *                           USEFUL PRIMITIVES
+ *************************************************************************)
 
+let eol                  = Util.eol
 
-    (* Define comment and empty strings *)
-    (* Some implementations of INI file allow "#" as a comment sign *)
-    let comment_generic (pattern:regexp) = [ label "comment" . del pattern "; " .  value_to_eol? . eol ]
-    let comment = comment_generic /[ \t]*(#|;)/
-    let comment_nosharp = comment_generic /[ \t]*;/
+let sep_gen (pat:regexp) (default:string) 
+                       = Util.del_opt_ws " " . del pat default
+let value_sep          = sep_gen "=" "="
+let value_sepwithcolon = sep_gen /[:=]/ "="
 
-    let empty  = [ del /[ \t]*\n/ "" ]
+let value_to_eol       = Util.del_opt_ws " "
+                         . store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
+let value_to_comment   = Util.del_opt_ws " "
+                         . store /[^;# \t\n][^;#\n]*[^;# \t\n]|[^;# \t\n]/
 
 
-    (* Define entry function *)
-    (* Some implementations of INI file allow ";" as separator *)
-    let entry_generic (kw:regexp) (sep:lens) (comment:lens) = [ key kw . sep . value_to_comment? . (comment|eol) ]
-    let entry (kw:regexp)                                   = entry_generic kw value_sepwithcolon comment
-    let entry_setcomment (kw:regexp) (comment:lens)         = entry_generic kw value_sepwithcolon comment
-    let entry_nocolon (kw:regexp)                           = entry_generic kw value_sep comment
-    let entry_nocolon_setcomment (kw:regexp) (comment:lens) = entry_generic kw value_sep comment
+(* Define comment and empty strings *)
+(* Some implementations of INI file allow "#" as a comment sign *)
 
+let comment_generic (pat:regexp) (default:string)
+                         = [ label "comment" . sep_gen pat default
+			   .  value_to_eol . eol ]
+let comment              = comment_generic /[#;]/ ";"
+let comment_nosharp      = comment_generic ";" ";"
 
-    (* Define record *)
+let empty                = Util.empty
 
-    let title = Util.del_str "[" . store /[^]]+/ . Util.del_str "]". eol
-    let record (label_name:string) (entry:lens) = [ label label_name . title . (entry | comment | empty)* ] 
-    let record_setcomment (label_name:string) (entry:lens) (comment:lens) = [ label label_name . title . (entry | comment | empty)* ] 
-    (* Some implementations of INI File do not allow empty lines *)
-    let record_noempty (label_name:string) (entry:lens) = [ label label_name . title . (entry | comment)* ] 
-    let record_noempty_setcomment (label_name:string) (entry:lens) (comment:lens) = [ label label_name . title . (entry | comment)* ] 
 
-    (* Generic INI file lens *)
-    let lns (record:lens) = ( comment | empty )* . record*
-    (* Let the user choose the type of comment they want *)
-    let lns_setcomment (record:lens) (comment:lens) = ( comment | empty )* . record*
+(************************************************************************
+ *                             ENTRY
+ *************************************************************************)
 
-    (* Some implementations of INI File do not allow empty lines *)
-    let lns_noempty (record:lens) = comment* . record*
-    (* Let the user choose the type of comment they want *)
-    let lns_noempty_setcomment (record:lens) (comment:lens) = comment* . record*
+(* Some implementations of INI file allow ";" as separator *)
+let entry_generic (kw:regexp) (sep:lens) (comment:lens)
+                    = [ key kw . sep . value_to_comment? . (comment|eol) ]
+let entry (kw:regexp)
+                    = entry_generic kw value_sepwithcolon comment
+let entry_setcomment (kw:regexp) (comment:lens)
+                    = entry_generic kw value_sepwithcolon comment
+let entry_nocolon (kw:regexp)
+                    = entry_generic kw value_sep comment
+let entry_nocolon_setcomment (kw:regexp) (comment:lens)
+                    = entry_generic kw value_sep comment
+
+
+(************************************************************************
+ *                             RECORD 
+ *************************************************************************)
+
+let title                = Util.del_str "[" . store /[^]]+/
+                           . Util.del_str "]". eol
+
+let record (label_name:string) (entry:lens)
+                         = [ label label_name  . title
+			   . (entry | comment | empty)* ]
+
+let record_setcomment (label_name:string) (entry:lens)
+          (comment:lens) = [ label label_name . title
+                           . (entry | comment | empty)* ]
+
+(* Some implementations of INI File do not allow empty lines *)
+let record_noempty (label_name:string) (entry:lens)
+                         = [ label label_name . title
+                           . (entry | comment)* ]
+
+let record_noempty_setcomment (label_name:string) (entry:lens)
+          (comment:lens) = [ label label_name . title
+                           . (entry | comment)* ] 
+
+
+(************************************************************************
+ *                              LENS
+ *************************************************************************)
+
+
+(* Generic INI file lens *)
+let lns (record:lens)         = ( comment | empty )* . record*
+
+(* Let the user choose the type of comment they want *)
+let lns_setcomment (record:lens) (comment:lens)
+                              = ( comment | empty )* . record*
+
+(* Some implementations of INI File do not allow empty lines *)
+let lns_noempty (record:lens) = comment* . record*
+
+(* Let the user choose the type of comment they want *)
+let lns_noempty_setcomment (record:lens) (comment:lens)
+                              = comment* . record*
+
+




More information about the augeas-devel mailing list