Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Tuple & Variant #158

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

### Removed

- Removed support for Tuple and Variant in JSON. It was a non-standard
extension that was rarely used, so this simplifies the Yojson types and the
parser more standard-conforming (#105, #158 @Leonidas-from-XIV)

### Security

## 2.2.0
Expand Down
1 change: 0 additions & 1 deletion lib/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ let json_error s = raise (Json_error s)

exception End_of_array
exception End_of_object
exception End_of_tuple
exception End_of_input

type lexer_state = {
Expand Down
1 change: 0 additions & 1 deletion lib/common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ val init_lexer :

exception End_of_array
exception End_of_object
exception End_of_tuple
exception End_of_input

(* end undocumented section *)
Expand Down
41 changes: 0 additions & 41 deletions lib/monomorphic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,6 @@ let rec pp fmt =
true) false xs);
Format.fprintf fmt "@,]@]";
Format.fprintf fmt "@])"
#ifdef TUPLE
| `Tuple tup ->
Format.fprintf fmt "`Tuple (@[<hov>";
Format.fprintf fmt "@[<2>[";
ignore (List.fold_left
(fun sep e ->
if sep then
Format.fprintf fmt ";@ ";
pp fmt e;
true) false tup);
Format.fprintf fmt "@,]@]";
Format.fprintf fmt "@])"
#endif
#ifdef VARIANT
| `Variant (name, value) ->
Format.fprintf fmt "`Variant (@[<hov>";
Format.fprintf fmt "(@[";
Format.fprintf fmt "%S" name;
Format.fprintf fmt ",@ ";
(match value with
| None -> Format.pp_print_string fmt "None"
| Some x ->
Format.pp_print_string fmt "(Some ";
pp fmt x;
Format.pp_print_string fmt ")");
Format.fprintf fmt "@])";
Format.fprintf fmt "@])"
#endif

let show x =
Format.asprintf "%a" pp x
Expand Down Expand Up @@ -133,23 +105,10 @@ let rec equal a b =
| exception Invalid_argument _ ->
(* the lists were of different lengths, thus unequal *)
false)
#ifdef TUPLE
| `Tuple xs, `Tuple ys
#endif
| `List xs, `List ys ->
(match List.for_all2 equal xs ys with
| result -> result
| exception Invalid_argument _ ->
(* the lists were of different lengths, thus unequal *)
false)
#ifdef VARIANT
| `Variant (name, value), `Variant (name', value') ->
(match name = name' with
| false -> false
| true ->
match value, value' with
| None, None -> true
| Some x, Some y -> equal x y
| _ -> false)
#endif
| _ -> false
37 changes: 0 additions & 37 deletions lib/prettyprint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,43 +115,6 @@ let rec format ~inside_box std (out:Format.formatter) (x:t) : unit =
if not inside_box then Format.fprintf out "@[<hv2>";
Format.fprintf out "{@;<1 0>%a@;<1 -2>}" (pp_list "," (format_field std)) l;
if not inside_box then Format.fprintf out "@]";
#ifdef TUPLE
| `Tuple l ->
if std then
format ~inside_box std out (`List l)
else
if l = [] then
Format.pp_print_string out "()"
else (
if not inside_box then Format.fprintf out "@[<hov2>";
Format.fprintf out "(@,%a@;<0 -2>)" (pp_list "," (format ~inside_box:false std)) l;
if not inside_box then Format.fprintf out "@]";
)
#endif
#ifdef VARIANT
| `Variant (s, None) ->
if std then
#ifdef STRING
let representation = `String s in
#elif defined STRINGLIT
let representation = `Stringlit s in
#endif
format ~inside_box std out representation
else
Format.fprintf out "<%s>" (json_string_of_string s)

| `Variant (s, Some x) ->
if std then
#ifdef STRING
let representation = `String s in
#elif defined STRINGLIT
let representation = `Stringlit s in
#endif
format ~inside_box std out (`List [ representation; x ])
else
let op = json_string_of_string s in
Format.fprintf out "<@[<hv2>%s: %a@]>" op (format ~inside_box:true std) x
#endif

and format_field std out (name, x) =
Format.fprintf out "@[<hv2>%s: %a@]" (json_string_of_string name) (format ~inside_box:true std) x
Expand Down
21 changes: 0 additions & 21 deletions lib/read.mli
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,10 @@ val finish_string : lexer_state -> Lexing.lexbuf -> string
val read_string : lexer_state -> Lexing.lexbuf -> string
val read_ident : lexer_state -> Lexing.lexbuf -> string

val map_string :
lexer_state -> (string -> int -> int -> 'a) -> Lexing.lexbuf -> 'a
(* equivalent to finish_string *)

val map_ident :
lexer_state -> (string -> int -> int -> 'a) -> Lexing.lexbuf -> 'a
(* equivalent to read_ident *)

type variant_kind = [ `Edgy_bracket | `Square_bracket | `Double_quote ]

val start_any_variant : lexer_state -> Lexing.lexbuf -> variant_kind
val finish_variant : lexer_state -> Lexing.lexbuf -> t option
val finish_skip_variant : lexer_state -> Lexing.lexbuf -> unit
val read_lt : lexer_state -> Lexing.lexbuf -> unit
val read_gt : lexer_state -> Lexing.lexbuf -> unit
val read_comma : lexer_state -> Lexing.lexbuf -> unit
Expand Down Expand Up @@ -195,20 +186,8 @@ val read_array :
Lexing.lexbuf ->
'a array

val read_tuple :
(int -> 'a -> lexer_state -> Lexing.lexbuf -> 'a) ->
'a ->
lexer_state ->
Lexing.lexbuf ->
'a

val start_any_tuple : lexer_state -> Lexing.lexbuf -> bool
val read_lpar : lexer_state -> Lexing.lexbuf -> unit
val read_rpar : lexer_state -> Lexing.lexbuf -> unit
val read_tuple_end : Lexing.lexbuf -> unit
val read_tuple_end2 : lexer_state -> bool -> Lexing.lexbuf -> unit
val read_tuple_sep : lexer_state -> Lexing.lexbuf -> unit
val read_tuple_sep2 : lexer_state -> bool -> Lexing.lexbuf -> unit
val read_lbr : lexer_state -> Lexing.lexbuf -> unit
val read_rbr : lexer_state -> Lexing.lexbuf -> unit

Expand Down
Loading
Loading