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