[augeas-devel] [PATCH] Spacevars lens

Free Ekanayaka free at 64studio.com
Mon Aug 25 07:53:45 UTC 2008


# HG changeset patch
# User Free Ekanayaka <free at 64studio.com>
# Date 1219650573 -7200
# Node ID d7b3272871a540071227073890e3748b4ae1db72
# Parent  1e3fcce82205849cc5478708ce7d22248ed7b392
Spacevars lens

diff -r 1e3fcce82205 -r d7b3272871a5 lenses/spacevars.aug
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/spacevars.aug	Mon Aug 25 09:49:33 2008 +0200
@@ -0,0 +1,33 @@
+(* Spacevars module for Augeas
+ Author: Free Ekanayaka <free at 64studio.com>
+
+ Reference: man interfaces
+ This is a generic lens for simple key/value configuration files where
+ keys and values are separated by a sequence of spaces or tabs.
+
+*)
+
+module Spacevars =
+
+(************************************************************************
+ *                           USEFUL PRIMITIVES
+ *************************************************************************)
+
+let eol     = Util.eol
+let spc     = Util.del_ws_spc
+let comment = Util.comment
+let empty   = Util.empty
+
+(************************************************************************
+ *                               ENTRIES
+ *************************************************************************)
+
+let keyword = key /[A-Za-z0-9\._-]+(\[[0-9]+\])?/
+let value   = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
+let entry   = [ keyword . spc . value . eol ]
+
+(************************************************************************
+ *                                LENS
+ *************************************************************************)
+
+let lns     = (comment|empty|entry) *
diff -r 1e3fcce82205 -r d7b3272871a5 lenses/tests/test_spacevars.aug
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lenses/tests/test_spacevars.aug	Mon Aug 25 09:49:33 2008 +0200
@@ -0,0 +1,19 @@
+module Test_spacevars = 
+
+    let conf ="# This a spaced key/value configuration file.
+keyword value
+
+# I like comments
+very.useful-key my=value
+
+		
+"
+
+    test Spacevars.lns get conf =
+        { "#comment" = "This a spaced key/value configuration file."}
+        { "keyword" = "value" }
+        {}
+        { "#comment" = "I like comments"}
+        { "very.useful-key" = "my=value" }
+	{}
+	{}




More information about the augeas-devel mailing list