[augeas-devel] [PATCH 2 of 7] Rewrite inifile.aug entirely
Raphael Pinson
raphink at gmail.com
Thu Aug 14 15:52:04 UTC 2008
# HG changeset patch
# User Raphael Pinson <raphink at gmail.com>
# Date 1218728917 -7200
# Node ID 2d254500331759e7334d28d5af680e4b360da724
# Parent 9dfd488a44716a108971f084228d36dd1d682476
Rewrite inifile.aug entirely
diff -r 9dfd488a4471 -r 2d2545003317 lenses/inifile.aug
--- a/lenses/inifile.aug Thu Aug 14 09:57:31 2008 +0200
+++ b/lenses/inifile.aug Thu Aug 14 17:48:37 2008 +0200
@@ -10,90 +10,72 @@ module IniFile =
* USEFUL PRIMITIVES
*************************************************************************)
-let eol = Util.eol
+(* Internal primitives *)
+let eol = Util.eol
+let empty = [ eol ]
-let sep_gen (pat:regexp) (default:string)
+
+(* Define sep and defaults *)
+let sep (pat:regexp) (default:string)
= Util.del_opt_ws "" . del pat default
-let value_sep = sep_gen "=" "="
-let value_sepwithcolon = sep_gen /[:=]/ "="
+let sep_re = /[=:]/
+let sep_default = "="
-let value_to_eol = Util.del_opt_ws ""
+
+(* Define sto_* *)
+let sto_to_eol = Util.del_opt_ws ""
. store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
-let value_to_comment = Util.del_opt_ws ""
+let sto_to_comment = Util.del_opt_ws ""
. store /[^;# \t\n][^;#\n]*[^;# \t\n]|[^;# \t\n]/
-(* 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 ";" ";"
-
-let empty = Util.empty
+(* Define comment and defaults *)
+let comment (pat:regexp) (default:string)
+ = [ label "#comment" . sep pat default
+ . sto_to_eol . eol ]
+let comment_re = /[;#]/
+let comment_default = ";"
(************************************************************************
* ENTRY
*************************************************************************)
-(* 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
+(* entry includes comments *)
+
+let entry (kw:regexp) (sep:lens) (comment:lens)
+ = [ key kw . sep . sto_to_comment? . (comment|eol) ] | comment
+let entry_re = ( /[A-Za-z][A-Za-z0-9\._-]+/ - /#comment/ )
(************************************************************************
* RECORD
*************************************************************************)
-let title = Util.del_str "[" . store /[^]]+/
- . Util.del_str "]". eol
+let title (kw:regexp)
+ = Util.del_str "[" . key kw
+ . Util.del_str "]". eol
+let title_label (name:string) (kw:regexp)
+ = label name
+ . Util.del_str "[" . store kw
+ . 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)* ]
+let record_noempty (title:lens) (entry:lens)
+ = [ title
+ . entry* ]
+let record (title:lens) (entry:lens)
+ = record_noempty title ( entry | empty )
+let record_re = ( /[^]\n\/]+/ - /#comment/ )
+let record_label_re = /[^]\n]+/
(************************************************************************
* LENS
*************************************************************************)
+let lns_noempty (record:lens) (comment:lens)
+ = comment* . record*
+let lns (record:lens) (comment:lens)
+ = lns_noempty record (comment|empty)
-(* 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