File: quotation.ml

package info (click to toggle)
camlp5 8.04.00-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,968 kB
  • sloc: ml: 137,918; makefile: 2,055; perl: 1,729; sh: 1,653; python: 38
file content (38 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (3)
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
(* camlp5r *)
(* quotation.ml,v *)
(* Copyright (c) INRIA 2007-2017 *)

type expander =
  [ ExStr of bool -> string -> string
  | ExAst of (string -> MLast.expr * string -> MLast.patt) ]
;

value expanders_table = ref [];

value default = ref "";
value translate = ref (fun x -> x);

value expander_name name =
  match translate.val name with
  [ "" -> default.val
  | name -> name ]
;

value find name = List.assoc (expander_name name) expanders_table.val;

value add name f =
  if List.mem_assoc name expanders_table.val then do {
    Printf.fprintf stderr "Failure: Quotation.add: cannot add the quotation \"%s\" twice\n%!" name ;
    Ploc.raise Ploc.dummy (Failure Printf.(sprintf"Quotation.add: cannot add the quotation \"%s\" twice" name))
  }
  else
    expanders_table.val := [(name, f) :: expanders_table.val]
;

value upsert name f = do {
  if List.mem_assoc name expanders_table.val then
    Printf.fprintf stderr "Warning: Quotation.upsert: overwriting the quotation \"%s\"\n%!" name
  else () ;
  expanders_table.val := [(name, f) :: expanders_table.val]
}
;