[augeas-devel] [PATCH] phpvars lens

free at 64studio.com free at 64studio.com
Sat Dec 20 11:32:07 UTC 2008


commit 235549e7080e9d91d1086e9a84840cb8a217d8a8
Author: Free Ekanayaka <free at 64studio.com>
Date:   Sat Dec 20 00:23:54 2008 +0000

    Add lens and test for config files using PHP-style variables, like /etc/squirrelmail/config.php

diff --git a/lenses/phpvars.aug b/lenses/phpvars.aug
new file mode 100644
index 0000000..d0ac3d4
--- /dev/null
+++ b/lenses/phpvars.aug
@@ -0,0 +1,118 @@
+(* Phpvars module for Augeas
+ Author: Free Ekanayaka <free at 64studio.com>
+
+ Reference: PHP syntax
+
+*)
+
+module Phpvars =
+
+   autoload xfm
+
+(************************************************************************
+ *                           USEFUL PRIMITIVES
+ *************************************************************************)
+
+let eol        = Util.eol
+let indent     = Util.indent
+let empty      = Util.empty
+
+let sep_php    = del /<\?php\n/ "<?php\n"
+let sep_eq     = del /[ \n]*=/ " ="
+let sep_spc    = del /[ \n]+/ " "
+let sep_dollar = del /\$/ "$"
+let sep_scl    = del /[ \t]*;/ ";"
+
+let chr_blank = /[ \t]/
+let chr_nblank = /[^ \t\n]/
+let chr_any    = /./
+let chr_star   = /\*/
+let chr_nstar  = /[^\* \t\n]/
+let chr_slash  = /\//
+let chr_nslash = /[^\/ \t\n]/
+
+let sto_to_scl = store /([^ \t\n].*[^ \t\n;]|[^ \t\n;])/
+let sto_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
+
+(************************************************************************
+ *                              COMMENTS
+ *************************************************************************)
+
+let comment_re = chr_nblank
+               | ( chr_nblank . chr_any*
+                   . ( chr_star  . chr_nslash
+                     | chr_nstar . chr_slash
+                     | chr_nstar . chr_nslash
+                     | chr_blank . chr_nblank ) )
+
+let comment_first_line
+               = [ indent
+                 . seq "#comment"
+                 . store comment_re
+                  ]
+let comment_other_line
+               = [ del /[ \t]*\n[ \t\n]*/ "\n"
+                 . seq "#comment"
+                 . store comment_re
+                  ]
+let comment_end
+               = del /[ \t\n]*/ "" . del (chr_star . chr_slash) "*/"
+
+let comment_extended
+                 = [ indent
+                 . del (chr_slash . chr_star) "/*"
+                 . label "#comment"
+                 . counter "#comment"
+                 . ( (comment_first_line . comment_other_line+)
+                   | comment_first_line?)
+                 . comment_end
+                 . eol ]
+
+let comment_inline
+                 = [ indent
+                 . del (chr_slash . chr_slash) "//"
+                 . label "#inline"
+                 . indent
+                 . sto_to_eol
+                 . eol ]
+
+let comment      = comment_extended | comment_inline
+
+(************************************************************************
+ *                               ENTRIES
+ *************************************************************************)
+
+let global     = [ key "global"
+                 . sep_spc
+                 . sep_dollar
+                 . sto_to_scl
+                 . sep_scl
+                 . eol ]
+
+let variable_re
+               = /\$[][A-Za-z0-9'_-]+/
+let variable   = [ key variable_re
+                 . sep_eq
+                 . sep_spc
+                 . sto_to_scl
+                 . sep_scl
+                 . eol ]
+
+let include    = [ key "@include"
+                 . sep_spc
+                 . sto_to_scl
+                 . sep_scl
+               .   eol ]
+
+let entry      = global|variable|include
+
+(************************************************************************
+ *                                LENS
+ *************************************************************************)
+
+let lns        = sep_php . (empty|comment|entry)*
+
+let filter     = incl "/etc/squirrelmail/config.php"
+               . Util.stdexcl
+
+let xfm        = transform lns filter
diff --git a/lenses/tests/test_phpvars.aug b/lenses/tests/test_phpvars.aug
new file mode 100644
index 0000000..91e2497
--- /dev/null
+++ b/lenses/tests/test_phpvars.aug
@@ -0,0 +1,39 @@
+module Test_phpvars =
+
+let conf = "<?php
+/**/
+/**
+ * Multi line comment
+ *
+ */
+
+/* One line comment */
+
+// Inline comment
+global $version;
+global $config_version;
+$config_version = '1.4.0';
+
+$theme[0]['NAME'] = 'Default';
+$theme[0]['PATH'] = SM_PATH . 'themes/default_theme.php';
+ at include SM_PATH . 'config/config_local.php';
+"
+
+test Phpvars.lns get conf =
+   { "#comment" }
+   { "#comment" 
+      { "1" = "*" }
+      { "2" = "* Multi line comment" }
+      { "3" = "*" } }
+   {}
+   { "#comment" 
+      { "1" = "One line comment" } }
+   {}
+   { "#inline" = "Inline comment" }
+   { "global" = "version" }
+   { "global" = "config_version" }
+   { "$config_version" = "'1.4.0'" }
+   {}
+   { "$theme[0]['NAME']" = "'Default'"}
+   { "$theme[0]['PATH']" = "SM_PATH . 'themes/default_theme.php'"}
+   { "@include" = "SM_PATH . 'config/config_local.php'"}




More information about the augeas-devel mailing list