[augeas-devel] Basic support for multipart key

Francis Giraldeau Francis.Giraldeau at USherbrooke.ca
Mon Oct 18 20:19:17 UTC 2010


Hi,

To avoid put ambiguity in put direction for similar node, I tried to  
prefix a key with a label. In XML lens, element names and attributes  
have the same keys, so we have to put attributes in a store to avoid  
put ambiguity, and it produce a less pretty tree structure. Here is an  
example of a put ambiguity.

module Put_ambig =

let dir = [ key /[a]+/ . del "x" "x" ]
let sec = [ key /[a]+/ . del "y" "y" ]
let foo = (dir|sec)*
test foo get "axaay" = ?

$ augparse -I lenses/ --nostdinc put_ambig.aug
Syntax error in lens definition
put_ambig.aug:5.0-.20:Failed to compile foo
put_ambig.aug:5.10-.18:exception: overlapping lenses in tree union.put
     Example matched by both:  { "a" }
     First lens: put_ambig.aug:3.10-.38:
     Second lens: put_ambig.aug:4.10-.38:

Here is the actual way to fix this ambiguity, but moving keys into a store.

module Put_unambig =

let dir = [ label "dir" . store /[a]+/ . del "x" "x" ]
let sec = [ label "sec" . store /[a]+/ . del "y" "y" ]
let foo = (dir|sec)*
test foo get "axaay" = ?
test foo put "ax" after set "/sec" "aa" = ?

$ augparse -I lenses/ --nostdinc put_unambig.aug
Test result: put_unambig.aug:6.0-.24:
   { "dir" = "a" }
   { "sec" = "aa" }

Test result: put_unambig.aug:7.0-.43:
"axaay"

Now, let's add a prefix for each tree node labels:

module Multipart =

let dir = [ label "@" . key /[a]+/ . del "x" "x" ]
let sec = [ label "#" . key /[a]+/ . del "y" "y" ]
let foo = (dir|sec)*
test foo get "axaay" = ?
test foo put "ax" after clear "/#aa" = ?

$ augparse -I lenses/ --nostdinc multipart.aug
Test result: multipart.aug:6.0-.24:
   { "@a" }
   { "#aa" }
Test result: multipart.aug:7.0-.40:
"axaay"

Then the put ambiguity is avoided and the tree structure is more  
natural, because the key is on the tree path.

Attached is a patch for basic support of multipart key. There is a  
memory leak and it fail with some recursive lens, but it shows the idea.

Cheer,

Francis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Basic-support-for-multipart-keys.patch
Type: text/x-patch
Size: 11389 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20101018/6cc901c5/attachment.bin>


More information about the augeas-devel mailing list