X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=tag.ml;h=c692e980970d69b43c598c1f2f3754e44a8aa552;hb=df5fdb22632be887ecd9f5c46a014e7e970148a2;hp=e5c382091f1fe6837ecb2a9be5046a1da3613be6;hpb=c10ce35cd399aff15a49f3b24a31b38cb2191da0;p=SXSI%2Fxpathcomp.git diff --git a/tag.ml b/tag.ml index e5c3820..c692e98 100644 --- a/tag.ml +++ b/tag.ml @@ -13,27 +13,55 @@ type pool external null_pool : unit -> pool = "caml_xml_tree_nullt" external null_tag : unit -> t = "caml_xml_tree_nullt" external register_tag : pool -> string -> t = "caml_xml_tree_register_tag" -external tag_name : pool -> t -> string = "caml_xml_tree_tag_name" +external tag_name : pool -> t -> string = "caml_xml_tree_get_tag_name" let nullt = null_tag () -let pcdata = max_int -let attribute = max_int - 1 +let dummy = nullt +(* Defined in XMLTree.cpp *) +let document_node = 0 +let attribute = 1 +let pcdata = 2 +let attribute_data= 3 +let document_node_close = 4 +let attribute_close = 5 +let pcdata_close = 6 +let attribute_data_close= 7 -let pool = ref (null_pool ()) -let init p = pool := p +let pool = Weak.create 1 + +let init p = Weak.set pool 0 (Some p) + +let get_pool () = match Weak.get pool 0 with + | Some x -> x + | None -> failwith "Tag.ml: Uninitialized Document" let tag s = match s with | "<$>" -> pcdata | "<@>" -> attribute - | _ -> register_tag !pool s + | "" -> document_node + | "<@$>" -> attribute_data + | _ -> register_tag (get_pool()) s let compare = (-) let equal = (==) + +let hash x = x + + let to_string t = - if t = pcdata then "<$>" - else if t = attribute then "<@>" - else tag_name !pool t + if t == pcdata then "<$>" + else if t == attribute_data then "<@$>" + else if t == attribute then "<@>" + else if t == nullt then "" + else tag_name (get_pool()) t let print ppf t = Format.fprintf ppf "%s" (to_string t) +(* Check internal invariants *) +let check t = + if (t != tag (to_string t)) + then failwith "module Tag: internal check failed" + +let dump = print +