[augeas-devel] [PATCH] Add support for end of line comments in entry*
raphink at gmail.com
raphink at gmail.com
Wed Jul 23 12:34:17 UTC 2008
# HG changeset patch
# User rpinson at lab64.echo-net.net
# Date 1216816426 -7200
# Node ID 8f1909e6885c5f1ac7007b22a28f7f9a8559b873
# Parent 48bba9ca2e8b09d96f37763e8a15a7a447c4fe64
Add support for end of line comments in entry*
Add new entry* lenses for comments_nosharp
Make more generic entry and comment lenses
Update test_inifile.aug to test end of line comments
diff -r 48bba9ca2e8b -r 8f1909e6885c lenses/inifile.aug
--- a/lenses/inifile.aug Wed Jul 23 12:43:19 2008 +0200
+++ b/lenses/inifile.aug Wed Jul 23 14:33:46 2008 +0200
@@ -7,24 +7,29 @@ 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_sepwithcolon = del /[ \t]*(=|:)[ \t]*/ " = "
- let value_to_eol = store /([^ \t\n][^\n]*)?/
+ let eol = del /[ \t]*\n/ "\n"
+ let value_sep = del /[ \t]*=/ " = "
+ let value_sepwithcolon = del /[ \t]*(=|:)/ " = "
+ let value_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
+ let value_to_comment = del /[ \t]*/ "" . store /[^;# \t\n]+/
+
+
+ (* 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]*(#|;)[ \t]*/
+ let comment_nosharp = comment_generic /[ \t]*;[ \t]*/
+
+ let empty = [ del /[ \t]*\n/ "" ]
(* Define entry function *)
(* Some implementations of INI file allow ";" as separator *)
- let entry (kw:regexp) = [ key kw . value_sepwithcolon . value_to_eol . eol ]
- let entry_nocolon (kw:regexp) = [ key kw . value_sep . value_to_eol . eol ]
-
- (* Define comment and empty strings *)
- (* Some implementations of INI file allow "#" as a comment sign *)
- let comment = [ label "comment" . del /(#|;)[ \t]*/ "; " . store /([^ \t\n][^\n]*)?/ . eol ]
- let comment_nosharp = [ label "comment" . del /;[ \t]*/ "; " . store /([^ \t\n][^\n]*)?/ . eol ]
-
- let empty = [ del /[ \t]*/ "" . eol ]
+ 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 record *)
diff -r 48bba9ca2e8b -r 8f1909e6885c lenses/tests/test_inifile.aug
--- a/lenses/tests/test_inifile.aug Wed Jul 23 12:43:19 2008 +0200
+++ b/lenses/tests/test_inifile.aug Wed Jul 23 14:33:46 2008 +0200
@@ -14,7 +14,8 @@ module Test_IniFile =
let conf_ace = "# comment with sharp
[section1]
-test_ace = value
+test_ace = value # end of line comment
+test_ace =
; comment with colon
"
@@ -22,7 +23,9 @@ test_ace = value
{ "comment" = "comment with sharp" }
{}
{ "record_ace" = "section1"
- { "test_ace" = "value" }
+ { "test_ace" = "value"
+ { "comment" = "end of line comment" } }
+ { "test_ace" }
{ "comment" = "comment with colon" }
{} }
@@ -33,54 +36,65 @@ test_ace = value
let lns_acf = IniFile.lns_noempty record_acf
let conf_acf = "# comment with sharp
[section1]
-test_acf = value
-test_acf : value2
+test_acf = value
+test_acf =
+test_acf : value2 # end of line comment
; comment with colon
"
test lns_acf get conf_acf =
{ "comment" = "comment with sharp" }
{ "record_acf" = "section1"
{ "test_acf" = "value" }
- { "test_acf" = "value2" }
+ { "test_acf" }
+ { "test_acf" = "value2"
+ { "comment" = "end of line comment" } }
{ "comment" = "comment with colon" } }
(* TEST a/d/e *)
- let entry_ade = IniFile.entry "test_ade"
- let record_ade = IniFile.record_setcomment "record_ade" entry_ade IniFile.comment_nosharp
- let lns_ade = IniFile.lns_setcomment record_ade IniFile.comment_nosharp
- let conf_ade = "; a first comment with colon
+ let comment_ade = IniFile.comment_nosharp
+ let entry_ade = IniFile.entry_setcomment "test_ade" comment_ade
+ let record_ade = IniFile.record_setcomment "record_ade" entry_ade comment_ade
+ let lns_ade = IniFile.lns_setcomment record_ade comment_ade
+ let conf_ade = "; a first comment with colon
[section1]
test_ade = value
-test_ade : value2
+test_ade : value2 ; end of line comment
; comment with colon
+test_ade =
"
test lns_ade get conf_ade =
{ "comment" = "a first comment with colon" }
{ "record_ade" = "section1"
{ "test_ade" = "value" }
- { "test_ade" = "value2" }
+ { "test_ade" = "value2"
+ { "comment" = "end of line comment" } }
{ "comment" = "comment with colon" }
- {} }
+ {}
+ { "test_ade" } }
(* TEST a/d/f *)
- let entry_adf = IniFile.entry "test_adf"
- let record_adf = IniFile.record_noempty_setcomment "record_adf" entry_adf IniFile.comment_nosharp
- let lns_adf = IniFile.lns_noempty_setcomment record_adf IniFile.comment_nosharp
- let conf_adf = "; a first comment with colon
+ let comment_adf = IniFile.comment_nosharp
+ let entry_adf = IniFile.entry_setcomment "test_adf" comment_adf
+ let record_adf = IniFile.record_noempty_setcomment "record_adf" entry_adf comment_adf
+ let lns_adf = IniFile.lns_noempty_setcomment record_adf comment_adf
+ let conf_adf = "; a first comment with colon
[section1]
test_adf = value
-test_adf : value2
+test_adf : value2 ; end of line comment
; comment with colon
+test_adf =
"
test lns_adf get conf_adf =
{ "comment" = "a first comment with colon" }
{ "record_adf" = "section1"
{ "test_adf" = "value" }
- { "test_adf" = "value2" }
- { "comment" = "comment with colon" } }
+ { "test_adf" = "value2"
+ { "comment" = "end of line comment" } }
+ { "comment" = "comment with colon" }
+ { "test_adf" } }
(* TEST b/c/e *)
@@ -90,17 +104,20 @@ test_adf : value2
let conf_bce = "# comment with sharp
[section1]
-test_bce = value
+test_bce = value # end of line comment
; comment with colon
+test_bce =
"
test lns_bce get conf_bce =
{ "comment" = "comment with sharp" }
{}
{ "record_bce" = "section1"
- { "test_bce" = "value" }
+ { "test_bce" = "value"
+ { "comment" = "end of line comment" } }
{ "comment" = "comment with colon" }
- {} }
+ {}
+ { "test_bce" } }
(* TEST b/c/f *)
@@ -109,50 +126,61 @@ test_bce = value
let lns_bcf = IniFile.lns_noempty record_bcf
let conf_bcf = "# comment with sharp
[section1]
-test_bcf = value
+test_bcf = value # end of line comment
; comment with colon
+test_bcf =
"
test lns_bcf get conf_bcf =
{ "comment" = "comment with sharp" }
{ "record_bcf" = "section1"
- { "test_bcf" = "value" }
- { "comment" = "comment with colon" } }
+ { "test_bcf" = "value"
+ { "comment" = "end of line comment" } }
+ { "comment" = "comment with colon" }
+ { "test_bcf" } }
(* TEST b/d/e *)
- let entry_bde = IniFile.entry_nocolon "test_bde"
- let record_bde = IniFile.record_setcomment "record_bde" entry_bde IniFile.comment_nosharp
- let lns_bde = IniFile.lns_setcomment record_bde IniFile.comment_nosharp
- let conf_bde = "; first comment with colon
+ let comment_bde = IniFile.comment_nosharp
+ let entry_bde = IniFile.entry_nocolon_setcomment "test_bde" comment_bde
+ let record_bde = IniFile.record_setcomment "record_bde" entry_bde comment_bde
+ let lns_bde = IniFile.lns_setcomment record_bde comment_bde
+ let conf_bde = "; first comment with colon
[section1]
-test_bde = value
+test_bde = value ; end of line comment
; comment with colon
+test_bde =
"
test lns_bde get conf_bde =
{ "comment" = "first comment with colon" }
{}
{ "record_bde" = "section1"
- { "test_bde" = "value" }
+ { "test_bde" = "value"
+ { "comment" = "end of line comment" } }
{ "comment" = "comment with colon" }
- {} }
+ {}
+ { "test_bde" } }
(* TEST b/d/f *)
- let entry_bdf = IniFile.entry_nocolon "test_bdf"
- let record_bdf = IniFile.record_noempty_setcomment "record_bdf" entry_bdf IniFile.comment_nosharp
- let lns_bdf = IniFile.lns_noempty_setcomment record_bdf IniFile.comment_nosharp
- let conf_bdf = "; first comment with colon
+ let comment_bdf = IniFile.comment_nosharp
+ let entry_bdf = IniFile.entry_nocolon_setcomment "test_bdf" comment_bdf
+ let record_bdf = IniFile.record_noempty_setcomment "record_bdf" entry_bdf comment_bdf
+ let lns_bdf = IniFile.lns_noempty_setcomment record_bdf comment_bdf
+ let conf_bdf = "; first comment with colon
[section1]
-test_bdf = value
+test_bdf = value ; end of line comment
; comment with colon
+test_bdf =
"
test lns_bdf get conf_bdf =
{ "comment" = "first comment with colon" }
{ "record_bdf" = "section1"
- { "test_bdf" = "value" }
- { "comment" = "comment with colon" } }
+ { "test_bdf" = "value"
+ { "comment" = "end of line comment" } }
+ { "comment" = "comment with colon" }
+ { "test_bdf" } }
More information about the augeas-devel
mailing list