-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ppx: add the culprit json fragment in the error messages systematical…
…ly. (#47)
- Loading branch information
1 parent
bad3829
commit 10fae36
Showing
35 changed files
with
714 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(library | ||
(public_name melange-json.ppx-runtime) | ||
(name ppx_deriving_json_js_runtime) | ||
(libraries melange-json) | ||
(wrapped false) | ||
(modes melange)) | ||
|
||
|
||
(copy_files# | ||
(files ../common/ppx_deriving_json_errors.ml)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
type t = Js.Json.t | ||
|
||
let classify : | ||
t -> | ||
[ `Null | ||
| `String of string | ||
| `Float of float | ||
| `Int of int | ||
| `Bool of bool | ||
| `List of t list | ||
| `Assoc of (string * t) list ] = | ||
fun json -> | ||
if (Obj.magic json : 'a Js.null) == Js.null then `Null | ||
else | ||
match Js.typeof json with | ||
| "string" -> `String (Obj.magic json : string) | ||
| "number" -> | ||
let v = (Obj.magic json : float) in | ||
if Js.Float.isFinite v && Js.Math.floor_float v == v then | ||
`Int (Obj.magic v : int) | ||
else `Float v | ||
| "boolean" -> `Bool (Obj.magic json : bool) | ||
| "object" -> | ||
if Js.Array.isArray json then | ||
let xs = Array.to_list (Obj.magic json : t array) in | ||
`List xs | ||
else | ||
let xs = Js.Dict.entries (Obj.magic json : t Js.Dict.t) in | ||
`Assoc (Array.to_list xs) | ||
| typ -> failwith ("unknown JSON value type: " ^ typ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exception Of_json_error = Json.Decode.DecodeError |
Oops, something went wrong.