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
module Ast = struct
type t =
[ `String of string
| `Float of float
| `Int of int
| `Intlit of
string
| `Bool of bool
| `Null
| `Assoc of (string * t) list
| `List of t list ]
let rec to_string = function
| `String s -> Printf.sprintf "%S" s
| `Float f -> string_of_float f
| `Int i -> string_of_int i
| `Intlit s -> s
| `Bool b -> string_of_bool b
| `Null -> "null"
| `Assoc obj ->
let items =
List.map (fun (k, v) -> Printf.sprintf "%S: %s" k (to_string v)) obj
in
Printf.sprintf "{ %s }" (String.concat "; " items)
| `List lst ->
let items = List.map to_string lst in
Printf.sprintf "[ %s ]" (String.concat "; " items)
end
exception ParseError of string * Lexing.position