Hi Adam,
On Tue, 2010-01-19 at 11:13 -0500, Adam Stokes wrote:
> test Shellvars.lns get "#example:\n" =
> { "#comment" = "example:" }
The problem is a minor bug in the patch you sent yesterday: the atd file
actually contains the line "#example: \n" (note the extra space), and
the comment lens does not allow that. The solution is to change the
'del /\n/ "\n"' you had at the end of the comment lens to an 'eol'.
Attached is a new version of your patch that takes care of this and adds
a test for trailing space in comments.
David
>From 0d1ca5000f77d952b8f53852aea4dac2fe0e3f8e Mon Sep 17 00:00:00 2001
From: Adam Stokes <[email protected]>
Date: Tue, 19 Jan 2010 09:21:32 -0800
Subject: [PATCH] Shellvars: schema change for commented settings
We used to treat commented settings like
# VAR=VALUE
as an ordinary comment. Now they get mapped to a tree node very similar to
the non-commented setting, i.e. to
{ "VAR" = "VALUE" { "commented" } }
---
lenses/shellvars.aug | 15 +++++++++++----
lenses/tests/test_shellvars.aug | 20 +++++++++++++++++++-
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index b407bac..eb0596c 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -5,10 +5,14 @@ module Shellvars =
let eol = Util.eol
- let key_re = /[A-Za-z0-9_]+(\[[0-9]+\])?/ - "unset" - "export"
- let eq = Util.del_str "="
- let comment = Util.comment
+ let key_re = /[A-Za-z0-9_]+(\[[0-9]+\])?/ - "unset" - "export"
+ let eq = Util.del_str "="
let empty = Util.empty
+ let comment =
+ let simple_key_re =/((unset|export)[ \t]+)?[A-Za-z0-9_]+(\[[0-9]+\])?/ in
+ let commented_setting = /[ \t]*/ . simple_key_re . /=.*/ in
+ let line_re = /([^ \t\n].*[^ \t\n]|[^ \t\n])/ - commented_setting in
+ [ label "#comment" . del /#[ \t]*/ "# " . store line_re . eol ]
let char = /[^() '"\t\n]|\\\\"/
let dquot = /"([^"\\\n]|\\\\.)*"/ (* " Emacs, relax *)
@@ -32,7 +36,10 @@ module Shellvars =
store (char* | dquot | squot | bquot | empty_array)
let export = [ key "export" . Util.del_ws_spc ]
- let kv = [ export? . key key_re . eq . (simple_value | array) . eol ]
+ let marker = [ del /#[ \t]*/ "# " . label "commented" ]
+ let kv =
+ [ marker? . export? . key key_re . eq . (simple_value | array) . eol ]
+
let unset = [ key "unset" . Util.del_ws_spc . store key_re . eol ]
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 94fb747..054779a 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -24,7 +24,8 @@ unset ONBOOT
{ "HWADDR" = "ab:cd:ef:12:34:56" }
{ "IPADDR" = "172.31.0.31"
{ "export" } }
- { "#comment" = "DHCP_HOSTNAME=host.example.com" }
+ { "DHCP_HOSTNAME" = "host.example.com"
+ { "commented" } }
{ "NETMASK" = "255.255.255.0" }
{ "NETWORK" = "172.31.0.0" }
{ "unset" = "ONBOOT" }
@@ -106,6 +107,23 @@ unset ONBOOT
{ "2" = "v2" }
{ "3" = "v3" } }
+ test Shellvars.lns get "MOUNTD_PORT=892\n" = { "MOUNTD_PORT" = "892" }
+
+ test Shellvars.lns get "# MOUNTD_PORT=892\n" =
+ { "MOUNTD_PORT" = "892"
+ { "commented" } }
+
+ test Shellvars.lns put "MOUNTD_PORT=892\n" after
+ clear "/MOUNTD_PORT/commented"
+ = "# MOUNTD_PORT=892\n"
+
+ test Shellvars.lns put "# MOUNTD_PORT=892\n" after
+ rm "/MOUNTD_PORT/commented"
+ = "MOUNTD_PORT=892\n"
+
+ test Shellvars.lns get "#example: \n" =
+ { "#comment" = "example:" }
+
(* Local Variables: *)
(* mode: caml *)
(* End: *)
--
1.6.5.2
_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel