projects
/
SXSI
/
xpathcomp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Finish porting to the Grammar2 API
[SXSI/xpathcomp.git]
/
src
/
grammar2.ml
diff --git
a/src/grammar2.ml
b/src/grammar2.ml
index
0c509bf
..
d2d497e
100644
(file)
--- a/
src/grammar2.ml
+++ b/
src/grammar2.ml
@@
-200,16
+200,16
@@
struct
loop 1 l
in
Hashtbl.iter (fun lhs rhs ->
loop 1 l
in
Hashtbl.iter (fun lhs rhs ->
- let Node( head,
_
) = lhs in
+ let Node( head,
args
) = lhs in
let Node( tag1, params) = rhs in
let tag2, pos2 = pos_id2 params in
let id1 = h_find ~msg:"7" tag_to_id tag1
let Node( tag1, params) = rhs in
let tag2, pos2 = pos_id2 params in
let id1 = h_find ~msg:"7" tag_to_id tag1
- and id2 = h_find ~msg:"8" tag_to_id tag2
- in
+ and id2 = h_find ~msg:"8" tag_to_id tag2 in
let rule_ = id2 lsl 27 in
let rule_ = (rule_ lor id1) lsl 2 in
let rule_ = (rule_ lor pos2) lsl 2 in
let rule_ = id2 lsl 27 in
let rule_ = (rule_ lor id1) lsl 2 in
let rule_ = (rule_ lor pos2) lsl 2 in
- let rule_ = rule_ lor (List.length params) in
+ let rule_ = (rule_ lor (List.length params)) lsl 2 in
+ let rule_ = rule_ lor (List.length args) in
r_array.((h_find ~msg:"9" tag_to_id head) - rules_offset ) <- rule_
) rules;
(*let l = Array.length renum_tags in *)
r_array.((h_find ~msg:"9" tag_to_id head) - rules_offset ) <- rule_
) rules;
(*let l = Array.length renum_tags in *)
@@
-258,23
+258,14
@@
let save g f =
let load f =
let cin = open_in f in
let load f =
let cin = open_in f in
- let pr_pos () =
- Printf.eprintf "Position: %i kiB\n" (pos_in cin / 1024)
- in
let read () = Marshal.from_channel cin in
if read () != _GRAMMAR_MAGIC then failwith "Invalid grammar file";
if read () != _GRAMMAR_VERSION then failwith "Deprecated grammar format";
let read () = Marshal.from_channel cin in
if read () != _GRAMMAR_MAGIC then failwith "Invalid grammar file";
if read () != _GRAMMAR_VERSION then failwith "Deprecated grammar format";
- pr_pos();
let tags : int array = read () in
let tags : int array = read () in
- pr_pos();
let rules : int array = read () in
let rules : int array = read () in
- pr_pos();
let rules_offset : int = read () in
let rules_offset : int = read () in
- pr_pos();
let tag_to_id : (string, int) Hashtbl.t = read () in
let tag_to_id : (string, int) Hashtbl.t = read () in
- pr_pos();
let tag_of_id : string array = read () in
let tag_of_id : string array = read () in
- pr_pos();
let fd = Unix.descr_of_in_channel cin in
let pos = pos_in cin in
ignore(Unix.lseek fd pos Unix.SEEK_SET);
let fd = Unix.descr_of_in_channel cin in
let pos = pos_in cin in
ignore(Unix.lseek fd pos Unix.SEEK_SET);
@@
-303,6
+294,11
@@
type t_symbol = t_type Node.t
type tn_symbol = [ any_type ] Node.t
type tn_symbol = [ any_type ] Node.t
+type partial =
+ Leaf of node
+ | Node of tn_symbol * partial array
+
+
let is_nil (t : t_symbol) =
(Node.to_int t) == 4
let is_nil (t : t_symbol) =
(Node.to_int t) == 4
@@
-312,7
+308,7
@@
let nil_symbol : t_symbol =
let translate_tag _ t = if t == 4 then ~-1 else t
let to_string t tag =
if tag < Array.length t.tag_of_id then t.tag_of_id.(Tag.to_int tag)
let translate_tag _ t = if t == 4 then ~-1 else t
let to_string t tag =
if tag < Array.length t.tag_of_id then t.tag_of_id.(Tag.to_int tag)
- else "<!INVALIDTAG!>"
+ else "<!INVALID
TAG!>"
let register_tag t s =
try Hashtbl.find t.tag_to_id s with
let register_tag t s =
try Hashtbl.find t.tag_to_id s with
@@
-325,14
+321,16
@@
let tag_operations t = {
}
let start_root : node = Node.of_int 0
}
let start_root : node = Node.of_int 0
-let start_tag t (idx : node) =
- t.tags.(Bp.preorder_rank t.start (Node.to_int idx))
+let start_tag g (idx : node) : [<any_type] Node.t =
+ Node.of_int (g.tags.(Bp.preorder_rank g.start (Node.to_int idx)))
+
+;;
let start_first_child t (idx : node) =
let start_first_child t (idx : node) =
-
Bp.first_child t.start (Node.to_int idx
)
+
Node.of_int (Bp.first_child t.start (Node.to_int idx)
)
let start_next_sibling t (idx : node) =
let start_next_sibling t (idx : node) =
-
Bp.next_sibling t.start (Node.to_int idx
)
+
Node.of_int (Bp.next_sibling t.start (Node.to_int idx)
)
let is_non_terminal t (n : [< any_type ] Node.t) =
let n = Node.to_int n in
let is_non_terminal t (n : [< any_type ] Node.t) =
let n = Node.to_int n in
@@
-341,7
+339,7
@@
let is_non_terminal t (n : [< any_type ] Node.t) =
let is_terminal t (n : [< any_type ] Node.t) = not(is_non_terminal t n)
external terminal : [< any_type ] Node.t -> t_symbol = "%identity"
let is_terminal t (n : [< any_type ] Node.t) = not(is_non_terminal t n)
external terminal : [< any_type ] Node.t -> t_symbol = "%identity"
-external non_terminal : [< any_type ] Node.t ->
t
_symbol = "%identity"
+external non_terminal : [< any_type ] Node.t ->
n
_symbol = "%identity"
let tag (n : t_symbol) : Tag.t = Obj.magic n
let tag (n : t_symbol) : Tag.t = Obj.magic n
@@
-351,14
+349,19
@@
let get_rule g (r : n_symbol) : rhs =
let get_id1 (r : rhs) : tn_symbol =
Node.of_int(
let get_id1 (r : rhs) : tn_symbol =
Node.of_int(
- ((Node.to_int r) lsr
4
) land 0x7ffffff)
+ ((Node.to_int r) lsr
6
) land 0x7ffffff)
let get_id2 (r : rhs) : tn_symbol =
let get_id2 (r : rhs) : tn_symbol =
- Node.of_int((Node.to_int r) lsr 31)
+ Node.of_int((Node.to_int r) lsr 33)
+
+let get_rank (r : rhs) : int =
+ (Node.to_int r) land 0b11
-let get_
param_pos
(r : rhs) : int =
+let get_
id1_rank
(r : rhs) : int =
((Node.to_int r) lsr 2) land 0b11
((Node.to_int r) lsr 2) land 0b11
-let
num_param
s (r : rhs) : int =
- (
Node.to_int r
) land 0b11
+let
get_id2_po
s (r : rhs) : int =
+ (
(Node.to_int r) lsr 4
) land 0b11
+let get_id2_rank (r : rhs) : int =
+ get_rank r + 1 - get_id1_rank r