Debian Codegraph @

vendor/re/src/view.ml

raw
1 open Import
2
3 module Cset = struct
4 include Cset
5
6 module Range = struct
7 type t =
8 { first : Char.t
9 ; last : Char.t
10 }
11
12 let first t = t.first
13 let last t = t.last
14 end
15
16 let view t =
17 fold_right t ~init:[] ~f:(fun first last acc ->
18 let range = { Range.first = Cset.to_char first; last = Cset.to_char last } in
19 range :: acc)
20 ;;
21 end
22
23 module Sem = Automata.Sem
24 module Rep_kind = Automata.Rep_kind
25
26 type t =
27 | Set of Cset.t
28 | Sequence of Ast.t list
29 | Alternative of Ast.t list
30 | Repeat of Ast.t * int * int option
31 | Beg_of_line
32 | End_of_line
33 | Beg_of_word
34 | End_of_word
35 | Not_bound
36 | Beg_of_str
37 | End_of_str
38 | Last_end_of_line
39 | Start
40 | Stop
41 | Sem of Automata.Sem.t * Ast.t
42 | Sem_greedy of Automata.Rep_kind.t * Ast.t
43 | Group of string option * Ast.t
44 | No_group of Ast.t
45 | Nest of Ast.t
46 | Case of Ast.t
47 | No_case of Ast.t
48 | Intersection of Ast.t list
49 | Complement of Ast.t list
50 | Difference of Ast.t * Ast.t
51 | Pmark of Pmark.t * Ast.t
52
53 let view_ast f (t : _ Ast.ast) : t =
54 match t with
55 | Alternative a -> Alternative (List.map ~f a)
56 | No_case a -> No_case (f a)
57 | Case a -> Case (f a)
58 ;;
59
60 let view_set (cset : Ast.cset) : t =
61 match cset with
62 | Cset set -> Set set
63 | Intersection sets -> Intersection (List.map sets ~f:Ast.t_of_cset)
64 | Complement sets -> Complement (List.map sets ~f:Ast.t_of_cset)
65 | Difference (x, y) -> Difference (Ast.t_of_cset x, Ast.t_of_cset y)
66 | Cast ast -> view_ast Ast.t_of_cset ast
67 ;;
68
69 let view : Ast.t -> t = function
70 | Set s -> view_set s
71 | Ast s -> view_ast (fun x -> x) s
72 | Sem (sem, a) -> Sem (sem, a)
73 | Sem_greedy (sem, a) -> Sem_greedy (sem, a)
74 | Sequence s -> Sequence s
75 | Repeat (t, x, y) -> Repeat (t, x, y)
76 | Beg_of_line -> Beg_of_line
77 | End_of_line -> End_of_line
78 | Beg_of_word -> Beg_of_word
79 | End_of_word -> End_of_word
80 | Not_bound -> Not_bound
81 | Beg_of_str -> Beg_of_str
82 | End_of_str -> End_of_str
83 | Last_end_of_line -> Last_end_of_line
84 | Start -> Start
85 | Stop -> Stop
86 | No_group a -> No_group a
87 | Group (name, t) -> Group (name, t)
88 | Nest t -> Nest t
89 | Pmark (pmark, t) -> Pmark (pmark, t)
90 ;;