File: pp.ml

package info (click to toggle)
ocaml-obuild 0.1.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 796 kB
  • sloc: ml: 6,570; sh: 171; ansic: 34; makefile: 11
file content (49 lines) | stat: -rw-r--r-- 939 bytes parent folder | download
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
open Ext.Fugue
open Ext.Compat

exception InvalidPreprocessor of string

(*
http://ocaml.org/tutorials/camlp4_3.10.html
*)
type package = string list

module Type = struct
  type t =
    | CamlP4O
    | CamlP4R

  let of_string s =
    match Ext.Compat.string_lowercase s with
    | "p4o" | "camlp4o" -> CamlP4O
    | "p4r" | "camlp4r" -> CamlP4R
    | _ -> raise (InvalidPreprocessor s)

  let to_string = function
    | CamlP4O -> "camlp4o"
    | CamlP4R -> "camlp4r"
end

type desc = {
  camlp4 : string;
  packages : package list;
}

type t = desc option

let some s pkgs = Some { camlp4 = s; packages = pkgs }
let none = None

let append pp pkgs =
  match pp with
  | None -> pp
  | Some d -> Some { d with packages = d.packages @ pkgs }

let to_params pp =
  maybe []
    (fun desc ->
      let s =
        desc.camlp4 ^ " " ^ String.concat " " (List.concat (List.map (fun x -> x) desc.packages))
      in
      [ "-pp"; s ])
    pp