Source file display_rule.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
open Base
type t =
| Input of
{ wave_format : Hardcaml.Wave_format.t option
; alignment : Text_alignment.t
}
| Output of
{ wave_format : Hardcaml.Wave_format.t option
; alignment : Text_alignment.t
}
| Default
| Regexp of
{ re : (Re.re[@sexp.opaque])
; wave_format : Hardcaml.Wave_format.t option
; alignment : Text_alignment.t
}
| Names of
{ names : Port_name.t list
; wave_format : Hardcaml.Wave_format.t option
; alignment : Text_alignment.t
}
| Custom of (Port.t -> Hardcaml.Wave_format.t option)
| Custom_with_alignment of
(Port.t -> (Hardcaml.Wave_format.t * Text_alignment.t) option)
| Divider of string
[@@deriving sexp_of]
module Regexp = struct
type t =
| Glob of string
| Posix of string
| Perl of string
| Re of (Re.re[@sexp.opaque])
[@@deriving sexp_of]
let compile re =
match re with
| Glob re -> Re.Glob.glob re |> Re.compile
| Posix re -> Re.Posix.re re |> Re.compile
| Perl re -> Re.Perl.re re |> Re.compile
| Re re -> re
;;
end
let default = Default
let port_name_is_one_of ?(alignment = Text_alignment.Left) ?wave_format names =
Names { names = List.map names ~f:Port_name.of_string; wave_format; alignment }
;;
let port_name_is ?alignment ?wave_format name =
port_name_is_one_of [ name ] ?wave_format ?alignment
;;
let port_name_matches ?(alignment = Text_alignment.Left) ?wave_format re =
Regexp { re = Regexp.compile re; wave_format; alignment }
;;
let custom ~f = Custom f
let custom_with_alignment ~f = Custom_with_alignment f
let divider name = Divider name
let input ?(alignment = Text_alignment.Left) ?wave_format () =
Input { wave_format; alignment }
;;
let output ?(alignment = Text_alignment.Left) ?wave_format () =
Output { wave_format; alignment }
;;
module type States = sig
type t [@@deriving sexp_of, enumerate]
end