Skip to content

Commit

Permalink
Fixed bug introduced in the previous bugfix: "predefined" ignored in the
Browse files Browse the repository at this point in the history
first definition of a group of type definitions.
+ some package cleanup.
  • Loading branch information
mjambon committed Sep 3, 2009
1 parent 4eeb51a commit e5208d2
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 215 deletions.
2 changes: 0 additions & 2 deletions json-static/META.template
Expand Up @@ -3,5 +3,3 @@ description = "statically-typed JSON data"
requires = "camlp4 json-wheel"
archive(syntax,toploop) = "pa_json_static.cmo"
archive(syntax,preprocessor) = "pa_json_static.cmo"
archive(byte) = "run_json_static.cmo"
archive(native) = "run_json_static.cmx"
4 changes: 2 additions & 2 deletions json-static/Makefile
@@ -1,6 +1,6 @@
include Camlp4Version

VERSION = 0.9.7
VERSION = 0.9.8
export VERSION


Expand Down Expand Up @@ -39,7 +39,7 @@ check:
> check.mli.auto
ocamlfind ocamlopt -o check -package json-wheel -linkpkg \
-pp 'camlp4o -I . $(PARSER) pa_json_static.cmo' \
run_json_static.cmx check.ml
check.ml
./check
install: META
ocamlfind install json-static META \
Expand Down
72 changes: 0 additions & 72 deletions json-static/check.ml
Expand Up @@ -33,75 +33,3 @@ and b = int

type json c = (string * d * d) list
and d = [ `A ]

(******************* Main example with runtime test **********************)
(*
module Custom =
struct
type t = int
let of_json = Json_type.Browse.int
let to_json = Json_type.Build.int
let typedef = Run_json_static.Int
end
type json t = < x: int list list;
y: z;
assoc: (string * int) assoc;
?opt1: string option;
?opt2: string = "abc" >
and z = [ `A
| `B "b!" of bool
| `C of (Json_type.json_type * (string, number) Hashtbl.t)
| `Custom of (Custom.t * int array * z * z) ]
(* Another type that accepts exactly the same data *)
type json t2 = { x: int list list;
y: z2;
assoc: (string * int) assoc;
?opt1: string option;
?opt2: string = "abc" }
and z2 =
A
| B "b!" of bool
| C of (Json_type.json_type * (string, number) Hashtbl.t)
| Custom of (Custom.t * int array * z2 * z2)
let sample = "
{ \"x\" : [ [1], [2, 3] ],
\"y\" : [ \"Custom\",
[ 123,
[ 4, 5, 6 ],
[ \"b!\", true ],
[ \"C\", [ null, { \"a\" : 100,
\"b\" : 3.14 } ] ] ] ],
\"assoc\": { \"x1\": 1, \"x2\": 2, \"x3\": 3 }
}
"
let json = Json_io.json_of_string sample
let obj = t_of_json json
let json' = json_of_t obj
let sample' = Json_io.string_of_json json'
let json2 = Json_io.json_of_string sample
let obj2 = t2_of_json json
let json2' = json_of_t2 obj2
let sample2' = Json_io.string_of_json json2'
let _ =
print_endline sample';
assert (sample' = sample2');
assert (json' = json2');
(match obj#y with
`Custom (_, _, _, `C (_, tbl)) ->
(try assert (Hashtbl.find tbl "a" = 100.)
with Not_found -> assert false);
| _ -> assert false);
print_endline "Passed!"
*)
7 changes: 3 additions & 4 deletions json-static/pa_json_static.ml.310
Expand Up @@ -219,6 +219,7 @@ let make_typedef _loc names l =
| Raw -> <:ctyp< Json_type.t >>
| Custom s -> <:ctyp< $uid:s$ . t >> in

let l = List.filter (fun (_, x) -> not x.is_predefined) l in
match l with
[] -> <:str_item< >>
| ((_loc, name), x) :: l ->
Expand All @@ -227,10 +228,8 @@ let make_typedef _loc names l =
let dcl = Ast.TyDcl (_loc, name, [], convert x.def, []) in
List.fold_right (
fun ((_loc, name), x) acc ->
if x.is_predefined then acc
else
let dcl = Ast.TyDcl (_loc, name, [], convert x.def, []) in
<:ctyp< $dcl$ and $acc$ >>
let dcl = Ast.TyDcl (_loc, name, [], convert x.def, []) in
<:ctyp< $dcl$ and $acc$ >>
) l dcl in
<:str_item< type $tdl$ >>

Expand Down
82 changes: 0 additions & 82 deletions json-static/run_json_static.ml

This file was deleted.

53 changes: 0 additions & 53 deletions json-static/run_json_static.mli

This file was deleted.

0 comments on commit e5208d2

Please sign in to comment.