[augeas-devel] XML put ambiguity

Francis Giraldeau francis.giraldeau at usherbrooke.ca
Tue Aug 17 16:13:05 UTC 2010


Hi, 

I got a put ambuity with the xml lens when I try to desambiguate it. I
got one real ambiguity with a lens like this: 

let rec x = [ key /[a]/ . x* . del /[b]/ ]*

This lens is ambigous in the get direction, because it's like writing
(x*)*. So, removing one iter resolves the ambiguity. 

let rec x = [ key /[a]/ . x* . del /[b]/ ]

But, when I remove the subtree iteration in the xml lens, I got this
error: 

$ ./augparse -I ../lenses --nostdinc ../lenses/xml_put_ambig.aug 
Syntax error in lens definition
../lenses/xml_put_ambig.aug:59.0-.48:Failed to compile content
../lenses/xml_put_ambig.aug:57.21-56.51:exception: ambiguous tree
concatenation
      First regexp: /{ /[A-Za-z][.0-9A-Z\\_a-z-]*/ = /[^\001-\004
"]*/ }*/
      Second regexp: /(<<rec>> | { /#text/ = /[^\001-\004<>]+/ } |
{ /#comment/ = /[^\001-\004<>]*[^\001-\004-]/ })*/
      ' { "A" }' can be split into
      '|=| { "A" }'

     and
      ' { "A" }|=|'

    First lens: ../lenses/xml_put_ambig.aug:57.21-13.31:
    Second lens: ../lenses/xml_put_ambig.aug:56.46-.51:

The ambiguity is that a tree node with empty value can either match an
argument OR an element. I was thinking that it would be possible to
disambiguate based on the value side, but a NULL and empty string
overlap. It's shown by this lens:

module Empty = 
(* test if NULL and empty nodes are conflicting *)

let a = [ key /[a]/ . del /[b]*/ "b" ]
let b = [ key /[a]/ . store /[b]*/ ]

let z = a | b

It's worth to know, but, there seems to be a bug, because the iteration
ambiguity prevent detecting the put ambiguity. 

Cheer, 

Francis



-------------- next part --------------
(* XML lens for Augeas
   Author: Francis Giraldeau <francis.giraldeau at usherbrooke.ca>

   Reference: http://www.w3.org/TR/2006/REC-xml11-20060816/
*)

module Xml = 

(************************************************************************
 *                           Utilities lens
 *************************************************************************)

let dels (s:string)   = del s s 
let sep_spc           = del /[ \t\n]+/ " "
let sep_osp           = del /[ \t\n]*/ ""
let sep_eq            = del /[ \t]*=[ \t]*/ "="

let nmtoken             = /[a-zA-Z:_][a-zA-Z0-9:_\.-]*/
let word                = /[a-zA-Z][a-zA-Z0-9\._\-]*/ 
let sto_dquote          = dels "\"" . store /[^"]*/ . dels "\""
let sto_squote          = dels "'" . store /[^']*/ . dels "'"

(* FIXME: should allow <> in comment body, but have to handle ambig: 
../lenses/xml.aug:49.0-.57:Failed to compile _
../lenses/xml.aug:45.46-.51:exception: ambiguous iteration
      Iterated regexp: /(<!--)(.*[^-])(-->)/
      '<!--A--><!--\n-->' can be split into
      '<!--A-->|=|<!--\n-->'

     and
      '<!--A--><!--\n-->|=|'
*)
let comment             = [ label "#comment" . dels "<!--" . store /[^<>]*[^-]/ . dels "-->" ]
let pi                  = nmtoken - /[Xx][Mm][Ll]/ 
let empty               = Util.empty

(************************************************************************
 *                            Attributes
 *************************************************************************)
let attributes = [ sep_spc . key word . sep_eq . sto_dquote ]*

let prolog              = [ label "#declaration" 
                          . dels "<?xml" 
                          . attributes
                          . sep_osp
                          . dels "?>" ]


(************************************************************************
 *                            Tags
 *************************************************************************)

let text = [ label "#text" . store /[^<>]+/ ]

let element (body:lens) =  
    let h = attributes . sep_osp . dels ">" . body* . dels "</" in  
        [ dels "<" . square word h . del />[\n]?/ ">\n" ]*

let rec content = element (content|text|comment)
 
let doc = (sep_osp . prolog)? . sep_osp . content . sep_osp
-------------- next part --------------
(* XML lens for Augeas
   Author: Francis Giraldeau <francis.giraldeau at usherbrooke.ca>

   Reference: http://www.w3.org/TR/2006/REC-xml11-20060816/
*)

module Xml_put_ambig = 

(************************************************************************
 *                           Utilities lens
 *************************************************************************)

let dels (s:string)   = del s s 
let sep_spc           = del /[ \t\n]+/ " "
let sep_osp           = del /[ \t\n]*/ ""
let sep_eq            = del /[ \t]*=[ \t]*/ "="

let nmtoken             = /[a-zA-Z:_][a-zA-Z0-9:_\.-]*/
let word                = /[a-zA-Z][a-zA-Z0-9\._\-]*/ 
let sto_dquote          = dels "\"" . store /[^"]*/ . dels "\""
let sto_squote          = dels "'" . store /[^']*/ . dels "'"

(* FIXME: should allow <> in comment body, but have to handle ambig: 
../lenses/xml.aug:49.0-.57:Failed to compile _
../lenses/xml.aug:45.46-.51:exception: ambiguous iteration
      Iterated regexp: /(<!--)(.*[^-])(-->)/
      '<!--A--><!--\n-->' can be split into
      '<!--A-->|=|<!--\n-->'

     and
      '<!--A--><!--\n-->|=|'
*)
let comment             = [ label "#comment" . dels "<!--" . store /[^<>]*[^-]/ . dels "-->" ]
let pi                  = nmtoken - /[Xx][Mm][Ll]/ 
let empty               = Util.empty

(************************************************************************
 *                            Attributes
 *************************************************************************)
let attributes = [ sep_spc . key word . sep_eq . sto_dquote ]*

let prolog              = [ label "#declaration" 
                          . dels "<?xml" 
                          . attributes
                          . sep_osp
                          . dels "?>" ]


(************************************************************************
 *                            Tags
 *************************************************************************)

let text = [ label "#text" . store /[^<>]+/ ]

let element (body:lens) =  
    let h = attributes . sep_osp . dels ">" . body* . dels "</" in  
        [ dels "<" . square word h . del />[\n]?/ ">\n" ]

let rec content = element (content|text|comment)
 
let doc = (sep_osp . prolog)? . sep_osp . content . sep_osp


More information about the augeas-devel mailing list