[augeas-devel] Bool parsing and overlapping lenses in tree union.put

David Lutterkort lutter at redhat.com
Fri Jul 1 23:52:19 UTC 2011


Hi Michal,

sorry for the vacation-induced delay.

On Tue, 2011-06-14 at 18:59 +0200, Michal Hrušecký wrote:
> I'm trying to extend already existing lens (xorg one) to support bool
> values (because some of the options expect bool values). Parsing
> works, but I've got some difficulties to figure out how to fix
> "overlapping lenses in tree union.put" error. My current code is:
> 
> > let true = del /([Oo]n|[Tt]rue|[Yy]es)/ "True" . value "True"
> >
> > let false = del /([Oo]ff|[Ff]alse|[Nn]o)/ "False" . value "False"
> >
> > let bool = del /"?/ "\"" . true | false . del /"?/ "\""
> >
> > let entry_bool (canon:string) (re:regexp) =
> >       [ indent . del re canon . label canon . sep_spc . bool . eol ]
> 
> No matter how hard do I try, I don't see any overlapping between true
> and false. Full error is:
> 
> $ augparse -I . ./tests/test_xorg.aug
> Syntax error in lens definition
> ./xorg.aug:112.0-.23:Failed to compile bool
> ./xorg.aug:112.11-.23:exception: overlapping lenses in tree union.put
>     Example matched by both:
>     First lens: ./xorg.aug:108.11-.61:
>     Second lens: ./xorg.aug:110.12-.65:
> 
> ./tests/test_xorg.aug:40.7-.15:Could not load module Xorg for Xorg.lns
> ./tests/test_xorg.aug:40.7-.15:Undefined variable Xorg.lns
> 
> Where line 108 is definition of true, 110 of false and 122 of bool.
> 
> What am I overlooking? I admit that this is my first time trying to
> improve some lense...

You're tripping over a subtlety in Augeas' typechecker: in the put
direction (i.e. tree -> file) it only looks at the tree nodes that a
lens generates. Since true and false do not contain any '[ ... ]', they
do not produce any tree nodes, meaning as far as the typechecker is
concerned, they both match the empty tree - that's the overlap the
typechecker is complaining about.

One way out of that is to move the '|' out of the bool lens. This
requires restructuring the lens quite a bit. Here's a test module that
demonstrates that:

module T =

  let indent = Util.indent
  let sep_spc = Sep.space
  let eol = Util.eol

  (* Like Build.xchg, but with value *)
  let xchgv (m:regexp) (v:string) = del m v . value v

let entry_bool (canon:string) (re:regexp) =
  (* Note: this forces users to only ever write True or False into the tree *)
  let true = xchgv /([Oo]n|[Tt]rue|[Yy]es)/ "True" in
  let false = xchgv /([Oo]ff|[Ff]alse|[Nn]o)/ "False" in
  let entry (tf:lens) =
    [ indent . del re canon . label canon . sep_spc
    . del /"?/ "\"" . tf . del /"?/ "\"" . eol ] in
  entry true | entry false

let tst = entry_bool "test" /test/i

test tst get "Test On\n" = { "test" = "True" }
test tst put "Test On\n" after
  set "/test" "False" = "test \"False\"\n"

David





More information about the augeas-devel mailing list