[augeas-devel] augeas: master - New utility modules Build, Rx, and Sep

David Lutterkort lutter at fedoraproject.org
Fri Apr 3 23:05:53 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=2be88bc66cf7b7c0d9e5c3cdd449c4b45bf52071
Commit:        2be88bc66cf7b7c0d9e5c3cdd449c4b45bf52071
Parent:        1a604208c21a3fd2a2aa4d7896b88623099579d3
Author:        Raphael Pinson <raphink at gmail.com>
AuthorDate:    Tue Mar 31 12:13:23 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Fri Apr 3 16:01:05 2009 -0700

New utility modules Build, Rx, and Sep

---
 lenses/build.aug         |   34 ++++++++++++++++++++++++
 lenses/rx.aug            |   64 ++++++++++++++++++++++++++++++++++++++++++++++
 lenses/sep.aug           |   20 ++++++++++++++
 lenses/tests/test_rx.aug |   15 +++++++++++
 4 files changed, 133 insertions(+), 0 deletions(-)

diff --git a/lenses/build.aug b/lenses/build.aug
new file mode 100644
index 0000000..756b645
--- /dev/null
+++ b/lenses/build.aug
@@ -0,0 +1,34 @@
+(*
+Module: Build
+   Generic functions to build lenses
+
+Author: Raphael Pinson <raphink at gmail.com>
+
+About: License
+  This file is licensed under the LGPLv2+, like the rest of Augeas.
+*)
+
+
+module Build =
+
+let eol = Util.eol
+
+(* Generic constructions *)
+let brackets (l:lens) (r:lens) (lns:lens) = l . lns . r
+
+(* List constructions *)
+let list (lns:lens) (sep:lens) = lns . ( sep . lns )+
+let opt_list (lns:lens) (sep:lens) = lns . ( sep . lns )*
+
+(* Labels *)
+let xchg (m:regexp) (d:string) (l:string) = del m d . label l
+
+(* Keys *)
+let key_value_line (kw: regexp) (sep:lens) (sto:lens) =
+                                   [ key kw . sep . sto . eol ]
+
+let key_value (kw: regexp) (sep:lens) (sto:lens) =
+                                   [ key kw . sep . sto ]
+
+
+
diff --git a/lenses/rx.aug b/lenses/rx.aug
new file mode 100644
index 0000000..6b1457a
--- /dev/null
+++ b/lenses/rx.aug
@@ -0,0 +1,64 @@
+(*
+Module: Rx
+   Generic regexps to build lenses
+
+Author: Raphael Pinson <raphink at gmail.com>
+
+About: License
+  This file is licensed under the LGPLv2+, like the rest of Augeas.
+*)
+
+
+module Rx =
+
+(* Spaces *)
+let space     = /[ \t]+/
+let opt_space = /[ \t]*/
+let space_in  = /[^ \t\n].*[^ \t\n]|[^ \t\n]/
+let no_spaces = /[^ \t\n]+/
+
+(* Generic fields *)
+let word      = /[A-Za-z0-9_.-]+/
+let integer   = /[0-9]+/
+let decimal   = /[0-9]+[.,][0-9]+/
+
+(* All but... *)
+(* Anything but a space, a comma or a comment sign *)
+let neg1      = /[^,# \n\t]+/
+
+
+(*
+ * IPs
+ * Cf. http://blog.mes-stats.fr/2008/10/09/regex-ipv4-et-ipv6/ (in fr)
+ *)
+let ipv4 =
+  let dot     = "." in
+  let digits  = /(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/ in
+    digits . dot . digits . dot . digits . dot . digits
+
+let ipv6 =
+  /(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})/
+  | /(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})/
+  | /(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})/
+  | /(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})/
+  | /(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})/
+  | /(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})/
+  | (    /([0-9A-Fa-f]{1,4}:){6}/
+           . /((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}/
+           . /(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)/
+    )
+  | (    /([0-9A-Fa-f]{1,4}:){0,5}:/
+           . /((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}/
+           . /(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)/
+    )
+  | (    /::([0-9A-Fa-f]{1,4}:){0,5}/
+           . /((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}/
+           . /(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)/
+    )
+  | (    /[0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}/
+           . /[0-9A-Fa-f]{1,4}/
+    )
+  | /(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})/
+  | /(([0-9A-Fa-f]{1,4}:){1,7}:)/
+
+let ip        = ipv4 | ipv6
diff --git a/lenses/sep.aug b/lenses/sep.aug
new file mode 100644
index 0000000..c49927e
--- /dev/null
+++ b/lenses/sep.aug
@@ -0,0 +1,20 @@
+(*
+Module: Sep
+   Generic separators to build lenses
+
+Author: Raphael Pinson <raphink at gmail.com>
+
+About: License
+  This file is licensed under the LGPLv2+, like the rest of Augeas.
+*)
+
+
+module Sep =
+
+let colon = Util.del_str ":"
+let comma = Util.del_str ","
+let space = del Rx.space " "
+let tab   = del Rx.space "\t"
+let opt_space = del Rx.opt_space " "
+let opt_tab   = del Rx.opt_space "\t"
+
diff --git a/lenses/tests/test_rx.aug b/lenses/tests/test_rx.aug
new file mode 100644
index 0000000..bf194be
--- /dev/null
+++ b/lenses/tests/test_rx.aug
@@ -0,0 +1,15 @@
+module Test_rx =
+
+let sto_ipv4 = [ label "IP" . store Rx.ipv4 ]
+
+test sto_ipv4 get "192.168.0.1"     = { "IP" = "192.168.0.1"     }
+test sto_ipv4 get "255.255.255.254" = { "IP" = "255.255.255.254" }
+
+let sto_ipv6 = [ label "IP" . store Rx.ipv6 ]
+test sto_ipv6 get "fe80::215:f2ff:fea4:b8d9" = { "IP" = "fe80::215:f2ff:fea4:b8d9" }
+
+let sto_ip = [ label "IP" . store Rx.ip ]
+
+test sto_ip get "192.168.0.1"              = { "IP" = "192.168.0.1"              }
+test sto_ip get "255.255.255.254"          = { "IP" = "255.255.255.254"          }
+test sto_ip get "fe80::215:f2ff:fea4:b8d9" = { "IP" = "fe80::215:f2ff:fea4:b8d9" }




More information about the augeas-devel mailing list