On Fri, 2010-01-15 at 23:45 +0100, Tim Stoop wrote:
> Hi David,
>
> On Fri, Jan 15, 2010 at 8:34 PM, <[email protected]> wrote:
> > This adds a new lens primitive 'value'. It is the counterpart of the label
> > lens in that it sets the value of a tree node to a constant, rather than
> > the label.
>
> Thanks for that! At least I assume this is in response to my previous email
> ;-)
>
> Any tips on how to use this for my [OR] situation? As an example:
>
> RewriteCond %{var} val [OR]
> RewriteCond %{var} lue
>
> How do I say, "if the line ends in [OR], add a { "chain_as" = "or" },
> otherwise add a { "chain_as" = "and" }?
One way to do that is like this:
module Chain =
let word = /[^ \t\n]+/
let ws = del /[ \t]+/ " "
let lns = [ key "RewriteCond" . ws .
[ label "eq" . store word ] . ws . store word .
([ label "chain_as" . ws . del "[OR]" "[OR]" . value "or"]
|[ label "chain_as" . value "and" ]) ]
test lns get "RewriteCond %{var} val [OR]" =
{ "RewriteCond" = "val"
{ "eq" = "%{var}" }
{ "chain_as" = "or" } }
test lns get "RewriteCond %{var} lue" =
{ "RewriteCond" = "lue"
{ "eq" = "%{var}" }
{ "chain_as" = "and" } }
Be warned though, the patch I posted for value has a little bug; you
need to apply the attached incremental patch.
David
diff --git a/src/lens.c b/src/lens.c
index 40942c7..f65bb80 100644
--- a/src/lens.c
+++ b/src/lens.c
@@ -505,6 +505,8 @@ struct value *lns_make_prim(enum lens_tag tag, struct info *info,
/* Set the vtype */
if (tag == L_STORE) {
lens->vtype = restrict_regexp(lens->regexp);
+ } else if (tag == L_VALUE) {
+ lens->vtype = make_regexp_literal(info, lens->string->str);
}
return make_lens_value(lens);
_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel