File: ag_json.ml

package info (click to toggle)
atdgen 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,004 kB
  • sloc: ml: 7,028; makefile: 296; sh: 47
file content (52 lines) | stat: -rw-r--r-- 959 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
50
51
52
(* $Id: ag_json.ml 52210 2010-11-22 09:50:55Z martin $ *)

(*
  Mapping from ATD to JSON
*)

type json_list = [ `Array | `Object ]

type json_variant = { json_cons : string }

type json_field = {
  json_fname : string;
  json_unwrapped : bool
}

type json_repr =
    [ 
    | `Unit
    | `Bool
    | `Int
    | `Float

    | `String
    | `Sum
    | `Record
    | `Tuple
    | `List of json_list
    | `Option
    | `Shared
    | `External

    | `Cell
    | `Field of json_field
    | `Variant of json_variant
    | `Def
    ]

let json_list_of_string s : json_list option =
  match s with
      "array" -> Some `Array
    | "object" -> Some `Object
    | _ -> None

let get_json_list an =
  Atd_annot.get_field json_list_of_string `Array ["json"] "repr" an

let get_json_cons default an =
  Atd_annot.get_field (fun s -> Some s) default ["json"] "name" an

let get_json_fname default an =
  Atd_annot.get_field (fun s -> Some s) default ["json"] "name" an