-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathname.ml
34 lines (30 loc) · 858 Bytes
/
name.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
(** Names of variables. *)
type fixity =
| Word
| Prefix
| Infix of Level.infix
let fixity x =
let s = Bindlib.name_of x in
if String.length s = 0 then
Word
else if String.length s > 1 && s.[0] = '*' && s.[1] = '*' then Infix Level.Infix4
else
match s.[0] with
| '~' | '?' | '!' -> Prefix
| '=' | '<' | '>' | '|' | '&' | '$' -> Infix Level.Infix0
| '@' | '^' -> Infix Level.Infix1
| '+' | '-' -> Infix Level.Infix2
| '*' | '/' | '%' -> Infix Level.Infix3
| _ -> Word
let anonymous =
let k = ref 0 in
fun () -> (incr k ; "_" ^ string_of_int !k)
let print_var ?(parentheses=true) x ppf =
let s = Bindlib.name_of x in
match fixity x with
| Word -> Format.fprintf ppf "%s" s
| Prefix | Infix _ ->
if parentheses then
Format.fprintf ppf "(%s)" s
else
Format.fprintf ppf "%s" s