Fix stupid bug with Tag indices
[SXSI/xpathcomp.git] / tag.ml
1 (******************************************************************************)
2 (*  SXSI : XPath evaluator                                                    *)
3 (*  Kim Nguyen (Kim.Nguyen@nicta.com.au)                                      *)
4 (*  Copyright NICTA 2008                                                      *)
5 (*  Distributed under the terms of the LGPL (see LICENCE)                     *)
6 (******************************************************************************)
7 (*  maybe utf8 string... *)
8
9
10 type t = int
11 type pool
12
13 external null_pool : unit -> pool = "caml_xml_tree_nullt"
14 external null_tag : unit -> t = "caml_xml_tree_nullt"
15 external register_tag : pool -> string -> t = "caml_xml_tree_register_tag"
16 external tag_name : pool -> t -> string = "caml_xml_tree_tag_name"
17
18 let nullt = null_tag ()   
19 let pcdata = max_int
20 let attribute = max_int - 1
21
22 let pool = ref (null_pool ())
23
24 let init p = pool := p
25
26 let tag s = match s with
27   | "<$>" -> pcdata
28   | "<@>" -> attribute
29   | _ -> register_tag !pool s
30
31 let compare = (-)
32 let equal = (==)
33 let to_string t = 
34   if t = pcdata then "<$>"
35   else if t = attribute then "<@>"
36   else tag_name !pool t
37
38
39 let print ppf t = Format.fprintf ppf "%s" (to_string t)