From 9f852597d9dee2295b9d8ededad777a39bcf234b Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Fri, 1 Aug 2025 10:35:28 +0200 Subject: [PATCH 1/6] Remove Raw and the variants used in it: StringLit & FloatLit --- lib/dune | 29 +---------------------------- lib/monomorphic.ml | 18 ------------------ lib/prettyprint.ml | 6 ------ lib/raw.cppo.ml | 25 ------------------------- lib/raw.cppo.mli | 27 --------------------------- lib/read.mll | 42 ++++++------------------------------------ lib/t.cppo.ml | 4 ---- lib/t.cppo.mli | 4 ---- lib/type.ml | 6 ------ lib/util.ml | 4 ---- lib/write.ml | 6 ------ lib/write.mli | 6 ------ lib/yojson.ml | 1 - lib/yojson.mli | 7 +------ 14 files changed, 8 insertions(+), 177 deletions(-) delete mode 100644 lib/raw.cppo.ml delete mode 100644 lib/raw.cppo.mli diff --git a/lib/dune b/lib/dune index 7e06004b..9f52c424 100644 --- a/lib/dune +++ b/lib/dune @@ -83,37 +83,10 @@ (action (run mucppo/mucppo.exe %{out} -o %{targets}))) -(rule - (targets raw.ml) - (deps - (:out raw.cppo.ml) - type.ml - write.ml - prettyprint.ml - monomorphic.ml - write2.ml - read.ml - util.ml) - (action - (run mucppo/mucppo.exe %{out} -o %{targets}))) - -(rule - (targets raw.mli) - (deps - (:out raw.cppo.mli) - type.ml - monomorphic.mli - write.mli - write2.mli - read.mli - util.mli) - (action - (run mucppo/mucppo.exe %{out} -o %{targets}))) - (library (name yojson) (public_name yojson) - (modules yojson t basic safe raw common codec lexer_utils) + (modules yojson t basic safe common codec lexer_utils) (synopsis "JSON parsing and printing") (flags (:standard -w -27-32))) diff --git a/lib/monomorphic.ml b/lib/monomorphic.ml index 912323b4..b5949540 100644 --- a/lib/monomorphic.ml +++ b/lib/monomorphic.ml @@ -23,23 +23,11 @@ let rec pp fmt = Format.fprintf fmt "%F" x; Format.fprintf fmt "@])" #endif -#ifdef FLOATLIT - | `Floatlit x -> - Format.fprintf fmt "`Floatlit (@["; - Format.fprintf fmt "%S" x; - Format.fprintf fmt "@])" -#endif #ifdef STRING | `String x -> Format.fprintf fmt "`String (@["; Format.fprintf fmt "%S" x; Format.fprintf fmt "@])" -#endif -#ifdef STRINGLIT - | `Stringlit x -> - Format.fprintf fmt "`Stringlit (@["; - Format.fprintf fmt "%S" x; - Format.fprintf fmt "@])" #endif | `Assoc xs -> Format.fprintf fmt "`Assoc (@["; @@ -84,14 +72,8 @@ let rec equal a b = #ifdef FLOAT | `Float a, `Float b -> a = b #endif -#ifdef FLOATLIT - | `Floatlit a, `Floatlit b -> a = b -#endif #ifdef STRING | `String a, `String b -> a = b -#endif -#ifdef STRINGLIT - | `Stringlit a, `Stringlit b -> a = b #endif | `Assoc xs, `Assoc ys -> let compare_keys = fun (key, _) (key', _) -> String.compare key key' in diff --git a/lib/prettyprint.ml b/lib/prettyprint.ml index e1c8c940..01bdef3a 100644 --- a/lib/prettyprint.ml +++ b/lib/prettyprint.ml @@ -82,12 +82,6 @@ let rec format ~inside_box (out : Format.formatter) (x : t) : unit = #endif #ifdef INTLIT | `Intlit s -> Format.pp_print_string out s -#endif -#ifdef FLOATLIT - | `Floatlit s -> Format.pp_print_string out s -#endif -#ifdef STRINGLIT - | `Stringlit s -> Format.pp_print_string out s #endif | `List [] -> Format.pp_print_string out "[]" | `List l -> diff --git a/lib/raw.cppo.ml b/lib/raw.cppo.ml deleted file mode 100644 index aa551547..00000000 --- a/lib/raw.cppo.ml +++ /dev/null @@ -1,25 +0,0 @@ -#define INTLIT -#define FLOATLIT -#define STRINGLIT - -#include "type.ml" - -#include "write.ml" - -module Pretty = struct - #include "prettyprint.ml" -end - -#include "monomorphic.ml" - -#include "write2.ml" - -#include "read.ml" - -module Util = struct - #include "util.ml" -end - -#undef INTLIT -#undef FLOATLIT -#undef STRINGLIT diff --git a/lib/raw.cppo.mli b/lib/raw.cppo.mli deleted file mode 100644 index da3bff43..00000000 --- a/lib/raw.cppo.mli +++ /dev/null @@ -1,27 +0,0 @@ -(** - Ints, floats and strings literals are systematically preserved using - [`Intlit], [`Floatlit] and [`Stringlit]. -*) - -#define INTLIT -#define FLOATLIT -#define STRINGLIT - -#include "type.ml" - -#include "monomorphic.mli" - -#include "write.mli" - -#include "write2.mli" - -#include "read.mli" - -(** This module provides combinators for extracting fields from JSON values. *) -module Util : sig - #include "util.mli" -end - -#undef INTLIT -#undef FLOATLIT -#undef STRINGLIT diff --git a/lib/read.mll b/lib/read.mll index e08b1243..9ef6681b 100644 --- a/lib/read.mll +++ b/lib/read.mll @@ -169,45 +169,15 @@ rule read_json v = parse | "true" { `Bool true } | "false" { `Bool false } | "null" { `Null } - | "NaN" { - #ifdef FLOAT - `Float nan - #elif defined FLOATLIT - `Floatlit "NaN" - #endif - } - | "Infinity" { - #ifdef FLOAT - `Float infinity - #elif defined FLOATLIT - `Floatlit "Infinity" - #endif - } - | "-Infinity" { - #ifdef FLOAT - `Float neg_infinity - #elif defined FLOATLIT - `Floatlit "-Infinity" - #endif - } - | '"' { - #ifdef STRING - Buffer.clear v.buf; - `String (finish_string v lexbuf) - #elif defined STRINGLIT - `Stringlit (finish_stringlit v lexbuf) - #endif + | "NaN" { `Float nan } + | "Infinity" { `Float infinity } + | "-Infinity" { `Float neg_infinity } + | '"' { Buffer.clear v.buf; + `String (finish_string v lexbuf) } | positive_int { make_positive_int v lexbuf } | '-' positive_int { make_negative_int v lexbuf } - | float { - #ifdef FLOAT - `Float (float_of_string (Lexing.lexeme lexbuf)) - #elif defined FLOATLIT - `Floatlit (Lexing.lexeme lexbuf) - #endif - } - + | float { `Float (float_of_string (Lexing.lexeme lexbuf)) } | '{' { let acc = ref [] in try read_space v lexbuf; diff --git a/lib/t.cppo.ml b/lib/t.cppo.ml index 8e8a1dff..96bbd8de 100644 --- a/lib/t.cppo.ml +++ b/lib/t.cppo.ml @@ -1,9 +1,7 @@ #define INT #define INTLIT #define FLOAT -#define FLOATLIT #define STRING -#define STRINGLIT #include "type.ml" @@ -20,6 +18,4 @@ end #undef INT #undef INTLIT #undef FLOAT -#undef FLOATLIT #undef STRING -#undef STRINGLIT diff --git a/lib/t.cppo.mli b/lib/t.cppo.mli index 865807c0..35e398e2 100644 --- a/lib/t.cppo.mli +++ b/lib/t.cppo.mli @@ -1,9 +1,7 @@ #define INT #define INTLIT #define FLOAT -#define FLOATLIT #define STRING -#define STRINGLIT #include "type.ml" @@ -16,6 +14,4 @@ #undef INT #undef INTLIT #undef FLOAT -#undef FLOATLIT #undef STRING -#undef STRINGLIT diff --git a/lib/type.ml b/lib/type.ml index b8505318..8b3fce56 100644 --- a/lib/type.ml +++ b/lib/type.ml @@ -13,14 +13,8 @@ type t = #ifdef FLOAT | `Float of float #endif -#ifdef FLOATLIT - | `Floatlit of string -#endif #ifdef STRING | `String of string -#endif -#ifdef STRINGLIT - | `Stringlit of string #endif | `Assoc of (string * t) list | `List of t list diff --git a/lib/util.ml b/lib/util.ml index eed1ff02..92f4c0ad 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -11,10 +11,6 @@ let typeof = function | `Null -> "null" | `String _ -> "string" | `Intlit _ -> "intlit" - | `Floatlit _ -> "floatlit" -#ifdef STRINGLIT - | `Stringlit _ -> "stringlit" -#endif let typerr msg js = raise (Type_error (msg ^ typeof js, js)) diff --git a/lib/write.ml b/lib/write.ml index c69bc63e..a6788eb9 100644 --- a/lib/write.ml +++ b/lib/write.ml @@ -221,14 +221,8 @@ let rec write_json ob (x : t) = #ifdef FLOAT | `Float f -> write_float ob f #endif -#ifdef FLOATLIT - | `Floatlit s -> Buffer.add_string ob s -#endif #ifdef STRING | `String s -> write_string ob s -#endif -#ifdef STRINGLIT - | `Stringlit s -> Buffer.add_string ob s #endif | `Assoc l -> write_assoc ob l | `List l -> write_list ob l diff --git a/lib/write.mli b/lib/write.mli index ebda5f22..a9b70ca1 100644 --- a/lib/write.mli +++ b/lib/write.mli @@ -133,12 +133,6 @@ val write_string : Buffer.t -> string -> unit #ifdef INTLIT val write_intlit : Buffer.t -> string -> unit #endif -#ifdef FLOATLIT -val write_floatlit : Buffer.t -> string -> unit -#endif -#ifdef STRINGLIT -val write_stringlit : Buffer.t -> string -> unit -#endif val write_assoc : Buffer.t -> (string * t) list -> unit val write_list : Buffer.t -> t list -> unit diff --git a/lib/yojson.ml b/lib/yojson.ml index fc1365ea..73ba2bd2 100644 --- a/lib/yojson.ml +++ b/lib/yojson.ml @@ -2,4 +2,3 @@ include Common include T module Basic = Basic module Safe = Safe -module Raw = Raw diff --git a/lib/yojson.mli b/lib/yojson.mli index 4460dd9e..96a1f2c8 100644 --- a/lib/yojson.mli +++ b/lib/yojson.mli @@ -2,8 +2,7 @@ The Yojson library provides several types for representing JSON values, with different use cases. - The {{!basic}Basic} JSON type, - - The {{!safe}Safe} JSON type, a superset of JSON with safer support for integers, - - The {{!raw}Raw} JSON type, a superset of JSON, safer but less integrated with OCaml types. + - The {{!safe}Safe} JSON type, a superset of JSON with safer support for integers. Each of these different types have their own module. @@ -23,7 +22,3 @@ module Basic = Basic module Safe = Safe (** {1 JSON tree type with literal int/float/string leaves} *) - -module Raw = Raw - -(** {1:raw Supertype of all JSON tree types} *) From 17b064cc299325b0ff8d8171a29f7268d7856c7a Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Fri, 1 Aug 2025 10:46:22 +0200 Subject: [PATCH 2/6] Remove INT as it is now always set --- lib/basic.cppo.ml | 2 -- lib/basic.cppo.mli | 2 -- lib/monomorphic.ml | 4 ---- lib/prettyprint.ml | 2 -- lib/read.mll | 4 ---- lib/safe.cppo.ml | 2 -- lib/safe.cppo.mli | 2 -- lib/t.cppo.ml | 2 -- lib/t.cppo.mli | 2 -- lib/type.ml | 2 -- lib/util.ml | 22 +++------------------- lib/write.ml | 2 -- lib/write.mli | 2 -- 13 files changed, 3 insertions(+), 47 deletions(-) diff --git a/lib/basic.cppo.ml b/lib/basic.cppo.ml index 59bc3fbd..4b655d10 100644 --- a/lib/basic.cppo.ml +++ b/lib/basic.cppo.ml @@ -1,4 +1,3 @@ -#define INT #define FLOAT #define STRING @@ -20,6 +19,5 @@ module Util = struct #include "util.ml" end -#undef INT #undef FLOAT #undef STRING diff --git a/lib/basic.cppo.mli b/lib/basic.cppo.mli index ed9b598d..c8c6e515 100644 --- a/lib/basic.cppo.mli +++ b/lib/basic.cppo.mli @@ -6,7 +6,6 @@ The main advantage of this module is its simplicity. *) -#define INT #define FLOAT #define STRING @@ -25,6 +24,5 @@ module Util : sig #include "util.mli" end -#undef INT #undef FLOAT #undef STRING diff --git a/lib/monomorphic.ml b/lib/monomorphic.ml index b5949540..bfa39dca 100644 --- a/lib/monomorphic.ml +++ b/lib/monomorphic.ml @@ -5,12 +5,10 @@ let rec pp fmt = Format.fprintf fmt "`Bool (@["; Format.fprintf fmt "%B" x; Format.fprintf fmt "@])" -#ifdef INT | `Int x -> Format.fprintf fmt "`Int (@["; Format.fprintf fmt "%d" x; Format.fprintf fmt "@])" -#endif #ifdef INTLIT | `Intlit x -> Format.fprintf fmt "`Intlit (@["; @@ -63,9 +61,7 @@ let rec equal a b = match a, b with | `Null, `Null -> true | `Bool a, `Bool b -> a = b -#ifdef INT | `Int a, `Int b -> a = b -#endif #ifdef INTLIT | `Intlit a, `Intlit b -> a = b #endif diff --git a/lib/prettyprint.ml b/lib/prettyprint.ml index 01bdef3a..75e98e31 100644 --- a/lib/prettyprint.ml +++ b/lib/prettyprint.ml @@ -70,9 +70,7 @@ let rec format ~inside_box (out : Format.formatter) (x : t) : unit = match x with | `Null -> Format.pp_print_string out "null" | `Bool x -> Format.pp_print_bool out x -#ifdef INT | `Int x -> Format.pp_print_string out (json_string_of_int x) -#endif #ifdef FLOAT | `Float x -> Format.pp_print_string out (json_string_of_float x) diff --git a/lib/read.mll b/lib/read.mll index 9ef6681b..ec880c97 100644 --- a/lib/read.mll +++ b/lib/read.mll @@ -98,10 +98,8 @@ !n let make_positive_int v lexbuf = - #ifdef INT try `Int (extract_positive_int lexbuf) with Int_overflow -> - #endif #ifdef INTLIT `Intlit (Lexing.lexeme lexbuf) #else @@ -125,10 +123,8 @@ !n let make_negative_int v lexbuf = - #ifdef INT try `Int (extract_negative_int lexbuf) with Int_overflow -> - #endif #ifdef INTLIT `Intlit (Lexing.lexeme lexbuf) #else diff --git a/lib/safe.cppo.ml b/lib/safe.cppo.ml index ef4ac18b..d3db5734 100644 --- a/lib/safe.cppo.ml +++ b/lib/safe.cppo.ml @@ -1,4 +1,3 @@ -#define INT #define INTLIT #define FLOAT #define STRING @@ -23,7 +22,6 @@ module Util = struct #include "util.ml" end -#undef INT #undef INTLIT #undef FLOAT #undef STRING diff --git a/lib/safe.cppo.mli b/lib/safe.cppo.mli index 32bf52d9..1ef00aeb 100644 --- a/lib/safe.cppo.mli +++ b/lib/safe.cppo.mli @@ -8,7 +8,6 @@ JSON. *) -#define INT #define INTLIT #define FLOAT #define STRING @@ -30,7 +29,6 @@ module Util : sig #include "util.mli" end -#undef INT #undef INTLIT #undef FLOAT #undef STRING diff --git a/lib/t.cppo.ml b/lib/t.cppo.ml index 96bbd8de..f332e41e 100644 --- a/lib/t.cppo.ml +++ b/lib/t.cppo.ml @@ -1,4 +1,3 @@ -#define INT #define INTLIT #define FLOAT #define STRING @@ -15,7 +14,6 @@ end #include "write2.ml" -#undef INT #undef INTLIT #undef FLOAT #undef STRING diff --git a/lib/t.cppo.mli b/lib/t.cppo.mli index 35e398e2..1bdf53ea 100644 --- a/lib/t.cppo.mli +++ b/lib/t.cppo.mli @@ -1,4 +1,3 @@ -#define INT #define INTLIT #define FLOAT #define STRING @@ -11,7 +10,6 @@ #include "write2.mli" -#undef INT #undef INTLIT #undef FLOAT #undef STRING diff --git a/lib/type.ml b/lib/type.ml index 8b3fce56..bc1bef2e 100644 --- a/lib/type.ml +++ b/lib/type.ml @@ -4,9 +4,7 @@ type t = [ | `Null | `Bool of bool -#ifdef INT | `Int of int -#endif #ifdef INTLIT | `Intlit of string #endif diff --git a/lib/util.ml b/lib/util.ml index 92f4c0ad..32a181e2 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -4,9 +4,7 @@ let typeof = function | `Assoc _ -> "object" | `Bool _ -> "bool" | `Float _ -> "float" -#ifdef INT | `Int _ -> "int" -#endif | `List _ -> "array" | `Null -> "null" | `String _ -> "string" @@ -60,18 +58,14 @@ let to_bool_option = function | js -> typerr "Expected bool or null, got " js let to_number = function -#ifdef INT | `Int i -> float i -#endif #ifdef FLOAT | `Float f -> f #endif | js -> typerr "Expected number, got " js let to_number_option = function -#ifdef INT | `Int i -> Some (float i) -#endif #ifdef FLOAT | `Float f -> Some f #endif @@ -92,15 +86,11 @@ let to_float_option = function | js -> typerr "Expected float or null, got " js let to_int = function -#ifdef INT | `Int i -> i -#endif | js -> typerr "Expected int, got " js let to_int_option = function -#ifdef INT | `Int i -> Some i -#endif | `Null -> None | js -> typerr "Expected int or null, got " js @@ -160,13 +150,9 @@ let filter_member k l = let filter_assoc l = filter_map (function `Assoc l -> Some l | _ -> None) l let filter_bool l = filter_map (function `Bool x -> Some x | _ -> None) l let filter_int l = - filter_map ( - function - #ifdef INT - | `Int x -> Some x - #endif - | _ -> None - ) l + filter_map (function + | `Int x -> Some x + | _ -> None) l let filter_float l = filter_map ( @@ -180,9 +166,7 @@ let filter_float l = let filter_number l = filter_map ( function -#ifdef INT `Int x -> Some (float x) -#endif #ifdef FLOAT | `Float x -> Some x #endif diff --git a/lib/write.ml b/lib/write.ml index a6788eb9..51609ff3 100644 --- a/lib/write.ml +++ b/lib/write.ml @@ -212,9 +212,7 @@ let rec write_json ob (x : t) = match x with `Null -> write_null ob () | `Bool b -> write_bool ob b -#ifdef INT | `Int i -> write_int ob i -#endif #ifdef INTLIT | `Intlit s -> Buffer.add_string ob s #endif diff --git a/lib/write.mli b/lib/write.mli index a9b70ca1..a72f4aca 100644 --- a/lib/write.mli +++ b/lib/write.mli @@ -117,9 +117,7 @@ val sort : t -> t val write_null : Buffer.t -> unit -> unit val write_bool : Buffer.t -> bool -> unit -#ifdef INT val write_int : Buffer.t -> int -> unit -#endif #ifdef FLOAT val write_float : Buffer.t -> float -> unit val write_std_float : Buffer.t -> float -> unit From 0d20915df7b6322221eaab68cdbbe8e43236e925 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Fri, 1 Aug 2025 10:52:12 +0200 Subject: [PATCH 3/6] Remove FLOAT, it is always defined --- lib/basic.cppo.ml | 2 -- lib/basic.cppo.mli | 2 -- lib/monomorphic.ml | 4 ---- lib/prettyprint.ml | 2 -- lib/safe.cppo.ml | 2 -- lib/safe.cppo.mli | 2 -- lib/t.cppo.ml | 2 -- lib/t.cppo.mli | 2 -- lib/type.ml | 2 -- lib/util.ml | 30 +++++++----------------------- lib/write.ml | 2 -- lib/write.mli | 2 -- 12 files changed, 7 insertions(+), 47 deletions(-) diff --git a/lib/basic.cppo.ml b/lib/basic.cppo.ml index 4b655d10..110742c1 100644 --- a/lib/basic.cppo.ml +++ b/lib/basic.cppo.ml @@ -1,4 +1,3 @@ -#define FLOAT #define STRING #include "type.ml" @@ -19,5 +18,4 @@ module Util = struct #include "util.ml" end -#undef FLOAT #undef STRING diff --git a/lib/basic.cppo.mli b/lib/basic.cppo.mli index c8c6e515..3ec19335 100644 --- a/lib/basic.cppo.mli +++ b/lib/basic.cppo.mli @@ -6,7 +6,6 @@ The main advantage of this module is its simplicity. *) -#define FLOAT #define STRING #include "type.ml" @@ -24,5 +23,4 @@ module Util : sig #include "util.mli" end -#undef FLOAT #undef STRING diff --git a/lib/monomorphic.ml b/lib/monomorphic.ml index bfa39dca..1df968c8 100644 --- a/lib/monomorphic.ml +++ b/lib/monomorphic.ml @@ -15,12 +15,10 @@ let rec pp fmt = Format.fprintf fmt "%S" x; Format.fprintf fmt "@])" #endif -#ifdef FLOAT | `Float x -> Format.fprintf fmt "`Float (@["; Format.fprintf fmt "%F" x; Format.fprintf fmt "@])" -#endif #ifdef STRING | `String x -> Format.fprintf fmt "`String (@["; @@ -65,9 +63,7 @@ let rec equal a b = #ifdef INTLIT | `Intlit a, `Intlit b -> a = b #endif -#ifdef FLOAT | `Float a, `Float b -> a = b -#endif #ifdef STRING | `String a, `String b -> a = b #endif diff --git a/lib/prettyprint.ml b/lib/prettyprint.ml index 75e98e31..e96ca6ab 100644 --- a/lib/prettyprint.ml +++ b/lib/prettyprint.ml @@ -71,10 +71,8 @@ let rec format ~inside_box (out : Format.formatter) (x : t) : unit = | `Null -> Format.pp_print_string out "null" | `Bool x -> Format.pp_print_bool out x | `Int x -> Format.pp_print_string out (json_string_of_int x) -#ifdef FLOAT | `Float x -> Format.pp_print_string out (json_string_of_float x) -#endif #ifdef STRING | `String s -> Format.pp_print_string out (json_string_of_string s) #endif diff --git a/lib/safe.cppo.ml b/lib/safe.cppo.ml index d3db5734..cf949c1e 100644 --- a/lib/safe.cppo.ml +++ b/lib/safe.cppo.ml @@ -1,5 +1,4 @@ #define INTLIT -#define FLOAT #define STRING #include "type.ml" @@ -23,5 +22,4 @@ module Util = struct end #undef INTLIT -#undef FLOAT #undef STRING diff --git a/lib/safe.cppo.mli b/lib/safe.cppo.mli index 1ef00aeb..4cabbc41 100644 --- a/lib/safe.cppo.mli +++ b/lib/safe.cppo.mli @@ -9,7 +9,6 @@ *) #define INTLIT -#define FLOAT #define STRING #include "type.ml" @@ -30,5 +29,4 @@ module Util : sig end #undef INTLIT -#undef FLOAT #undef STRING diff --git a/lib/t.cppo.ml b/lib/t.cppo.ml index f332e41e..9e2a26d8 100644 --- a/lib/t.cppo.ml +++ b/lib/t.cppo.ml @@ -1,5 +1,4 @@ #define INTLIT -#define FLOAT #define STRING #include "type.ml" @@ -15,5 +14,4 @@ end #include "write2.ml" #undef INTLIT -#undef FLOAT #undef STRING diff --git a/lib/t.cppo.mli b/lib/t.cppo.mli index 1bdf53ea..6195775e 100644 --- a/lib/t.cppo.mli +++ b/lib/t.cppo.mli @@ -1,5 +1,4 @@ #define INTLIT -#define FLOAT #define STRING #include "type.ml" @@ -11,5 +10,4 @@ #include "write2.mli" #undef INTLIT -#undef FLOAT #undef STRING diff --git a/lib/type.ml b/lib/type.ml index bc1bef2e..4254f320 100644 --- a/lib/type.ml +++ b/lib/type.ml @@ -8,9 +8,7 @@ type t = #ifdef INTLIT | `Intlit of string #endif -#ifdef FLOAT | `Float of float -#endif #ifdef STRING | `String of string #endif diff --git a/lib/util.ml b/lib/util.ml index 32a181e2..a83ca0d3 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -59,29 +59,21 @@ let to_bool_option = function let to_number = function | `Int i -> float i -#ifdef FLOAT | `Float f -> f -#endif | js -> typerr "Expected number, got " js let to_number_option = function | `Int i -> Some (float i) -#ifdef FLOAT | `Float f -> Some f -#endif | `Null -> None | js -> typerr "Expected number or null, got " js let to_float = function -#ifdef FLOAT | `Float f -> f -#endif | js -> typerr "Expected float, got " js let to_float_option = function -#ifdef FLOAT | `Float f -> Some f -#endif | `Null -> None | js -> typerr "Expected float or null, got " js @@ -155,23 +147,15 @@ let filter_int l = | _ -> None) l let filter_float l = - filter_map ( - function -#ifdef FLOAT - `Float x -> Some x -#endif - | _ -> None - ) l + filter_map (function + | `Float x -> Some x + | _ -> None) l let filter_number l = - filter_map ( - function - `Int x -> Some (float x) -#ifdef FLOAT - | `Float x -> Some x -#endif - | _ -> None - ) l + filter_map (function + | `Int x -> Some (float x) + | `Float x -> Some x + | _ -> None) l let filter_string l = filter_map ( diff --git a/lib/write.ml b/lib/write.ml index 51609ff3..6de03f00 100644 --- a/lib/write.ml +++ b/lib/write.ml @@ -216,9 +216,7 @@ let rec write_json ob (x : t) = #ifdef INTLIT | `Intlit s -> Buffer.add_string ob s #endif -#ifdef FLOAT | `Float f -> write_float ob f -#endif #ifdef STRING | `String s -> write_string ob s #endif diff --git a/lib/write.mli b/lib/write.mli index a72f4aca..946c0859 100644 --- a/lib/write.mli +++ b/lib/write.mli @@ -118,12 +118,10 @@ val sort : t -> t val write_null : Buffer.t -> unit -> unit val write_bool : Buffer.t -> bool -> unit val write_int : Buffer.t -> int -> unit -#ifdef FLOAT val write_float : Buffer.t -> float -> unit val write_std_float : Buffer.t -> float -> unit val write_float_prec : int -> Buffer.t -> float -> unit val write_std_float_prec : int -> Buffer.t -> float -> unit -#endif #ifdef STRING val write_string : Buffer.t -> string -> unit #endif From 5125df27e7429b184b82eded11cb670ce4eddebf Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Thu, 25 Jun 2026 14:40:03 +0200 Subject: [PATCH 4/6] Remove STRING, it is always defined --- lib/basic.cppo.ml | 4 ---- lib/basic.cppo.mli | 4 ---- lib/monomorphic.ml | 4 ---- lib/prettyprint.ml | 2 -- lib/safe.cppo.ml | 2 -- lib/safe.cppo.mli | 2 -- lib/t.cppo.ml | 2 -- lib/t.cppo.mli | 2 -- lib/type.ml | 2 -- lib/util.ml | 14 +++----------- lib/write.ml | 2 -- lib/write.mli | 2 -- 12 files changed, 3 insertions(+), 39 deletions(-) diff --git a/lib/basic.cppo.ml b/lib/basic.cppo.ml index 110742c1..59491940 100644 --- a/lib/basic.cppo.ml +++ b/lib/basic.cppo.ml @@ -1,5 +1,3 @@ -#define STRING - #include "type.ml" #include "write.ml" @@ -17,5 +15,3 @@ end module Util = struct #include "util.ml" end - -#undef STRING diff --git a/lib/basic.cppo.mli b/lib/basic.cppo.mli index 3ec19335..f7f6826c 100644 --- a/lib/basic.cppo.mli +++ b/lib/basic.cppo.mli @@ -6,8 +6,6 @@ The main advantage of this module is its simplicity. *) -#define STRING - #include "type.ml" #include "write.mli" @@ -22,5 +20,3 @@ module Util : sig #include "util.mli" end - -#undef STRING diff --git a/lib/monomorphic.ml b/lib/monomorphic.ml index 1df968c8..447c3d3d 100644 --- a/lib/monomorphic.ml +++ b/lib/monomorphic.ml @@ -19,12 +19,10 @@ let rec pp fmt = Format.fprintf fmt "`Float (@["; Format.fprintf fmt "%F" x; Format.fprintf fmt "@])" -#ifdef STRING | `String x -> Format.fprintf fmt "`String (@["; Format.fprintf fmt "%S" x; Format.fprintf fmt "@])" -#endif | `Assoc xs -> Format.fprintf fmt "`Assoc (@["; Format.fprintf fmt "@[<2>["; @@ -64,9 +62,7 @@ let rec equal a b = | `Intlit a, `Intlit b -> a = b #endif | `Float a, `Float b -> a = b -#ifdef STRING | `String a, `String b -> a = b -#endif | `Assoc xs, `Assoc ys -> let compare_keys = fun (key, _) (key', _) -> String.compare key key' in let xs = List.stable_sort compare_keys xs in diff --git a/lib/prettyprint.ml b/lib/prettyprint.ml index e96ca6ab..5382761f 100644 --- a/lib/prettyprint.ml +++ b/lib/prettyprint.ml @@ -73,9 +73,7 @@ let rec format ~inside_box (out : Format.formatter) (x : t) : unit = | `Int x -> Format.pp_print_string out (json_string_of_int x) | `Float x -> Format.pp_print_string out (json_string_of_float x) -#ifdef STRING | `String s -> Format.pp_print_string out (json_string_of_string s) -#endif #ifdef INTLIT | `Intlit s -> Format.pp_print_string out s #endif diff --git a/lib/safe.cppo.ml b/lib/safe.cppo.ml index cf949c1e..1fed18aa 100644 --- a/lib/safe.cppo.ml +++ b/lib/safe.cppo.ml @@ -1,5 +1,4 @@ #define INTLIT -#define STRING #include "type.ml" @@ -22,4 +21,3 @@ module Util = struct end #undef INTLIT -#undef STRING diff --git a/lib/safe.cppo.mli b/lib/safe.cppo.mli index 4cabbc41..766da25b 100644 --- a/lib/safe.cppo.mli +++ b/lib/safe.cppo.mli @@ -9,7 +9,6 @@ *) #define INTLIT -#define STRING #include "type.ml" @@ -29,4 +28,3 @@ module Util : sig end #undef INTLIT -#undef STRING diff --git a/lib/t.cppo.ml b/lib/t.cppo.ml index 9e2a26d8..cdb2df03 100644 --- a/lib/t.cppo.ml +++ b/lib/t.cppo.ml @@ -1,5 +1,4 @@ #define INTLIT -#define STRING #include "type.ml" @@ -14,4 +13,3 @@ end #include "write2.ml" #undef INTLIT -#undef STRING diff --git a/lib/t.cppo.mli b/lib/t.cppo.mli index 6195775e..a91150ea 100644 --- a/lib/t.cppo.mli +++ b/lib/t.cppo.mli @@ -1,5 +1,4 @@ #define INTLIT -#define STRING #include "type.ml" @@ -10,4 +9,3 @@ #include "write2.mli" #undef INTLIT -#undef STRING diff --git a/lib/type.ml b/lib/type.ml index 4254f320..909d9fec 100644 --- a/lib/type.ml +++ b/lib/type.ml @@ -9,9 +9,7 @@ type t = | `Intlit of string #endif | `Float of float -#ifdef STRING | `String of string -#endif | `Assoc of (string * t) list | `List of t list ] diff --git a/lib/util.ml b/lib/util.ml index a83ca0d3..bc44726d 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -89,15 +89,11 @@ let to_int_option = function let to_list = function `List l -> l | js -> typerr "Expected array, got " js let to_string = function -#ifdef STRING | `String s -> s -#endif | js -> typerr "Expected string, got " js let to_string_option = function -#ifdef STRING | `String s -> Some s -#endif | `Null -> None | js -> typerr "Expected string or null, got " js @@ -158,13 +154,9 @@ let filter_number l = | _ -> None) l let filter_string l = - filter_map ( - function -#ifdef STRING - `String x -> Some x -#endif - | _ -> None - ) l + filter_map (function + | `String x -> Some x + | _ -> None) l let keys o = to_assoc o |> List.map (fun (key, _) -> key) diff --git a/lib/write.ml b/lib/write.ml index 6de03f00..304d6c44 100644 --- a/lib/write.ml +++ b/lib/write.ml @@ -217,9 +217,7 @@ let rec write_json ob (x : t) = | `Intlit s -> Buffer.add_string ob s #endif | `Float f -> write_float ob f -#ifdef STRING | `String s -> write_string ob s -#endif | `Assoc l -> write_assoc ob l | `List l -> write_list ob l diff --git a/lib/write.mli b/lib/write.mli index 946c0859..eedd0277 100644 --- a/lib/write.mli +++ b/lib/write.mli @@ -122,9 +122,7 @@ val write_float : Buffer.t -> float -> unit val write_std_float : Buffer.t -> float -> unit val write_float_prec : int -> Buffer.t -> float -> unit val write_std_float_prec : int -> Buffer.t -> float -> unit -#ifdef STRING val write_string : Buffer.t -> string -> unit -#endif #ifdef INTLIT val write_intlit : Buffer.t -> string -> unit From 26e71e8d6f4949798ba0b1f8300dc3e14de5ebc6 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Thu, 25 Jun 2026 16:31:57 +0200 Subject: [PATCH 5/6] Add changelog entry --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 1d370970..5ac9200a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,9 @@ ### Removed +- `Yojson.Raw` was removed to cut down on parser variants; users are encouraged + to use `Yosjon.Safe`. (#206, @Leonidas-from-XIV) + ### Security ## 3.0.0 From 89169ca955912359743afd2969046a140af6cf3c Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Thu, 25 Jun 2026 16:50:30 +0200 Subject: [PATCH 6/6] Remove stringlit and floatlit references --- lib/read.mli | 2 -- lib/read.mll | 24 ++++++------------------ lib/write.ml | 2 -- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/lib/read.mli b/lib/read.mli index ff6d44bf..e022497e 100644 --- a/lib/read.mli +++ b/lib/read.mli @@ -143,8 +143,6 @@ val map_ident : val read_lt : lexer_state -> Lexing.lexbuf -> unit val read_gt : lexer_state -> Lexing.lexbuf -> unit val read_comma : lexer_state -> Lexing.lexbuf -> unit -val finish_stringlit : lexer_state -> Lexing.lexbuf -> string -val finish_skip_stringlit : lexer_state -> Lexing.lexbuf -> unit val finish_escaped_char : lexer_state -> Lexing.lexbuf -> unit val finish_comment : lexer_state -> Lexing.lexbuf -> unit val read_space : lexer_state -> Lexing.lexbuf -> unit diff --git a/lib/read.mll b/lib/read.mll index ec880c97..1e19d4a2 100644 --- a/lib/read.mll +++ b/lib/read.mll @@ -276,18 +276,6 @@ and finish_surrogate_pair v x = parse for code point beyond U+FFFF" v lexbuf } | eof { custom_error "Unexpected end of input" v lexbuf } -and finish_stringlit v = parse - ( '\\' (['"' '\\' '/' 'b' 'f' 'n' 'r' 't'] | 'u' hex hex hex hex) - | [^'"' '\\'] )* '"' - { let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos in - let s = Bytes.create (len+1) in - Bytes.set s 0 '"'; - Bytes.blit lexbuf.lex_buffer lexbuf.lex_start_pos s 1 len; - Bytes.to_string s - } - | _ { long_error "Invalid string literal" v lexbuf } - | eof { custom_error "Unexpected end of input" v lexbuf } - and read_lt v = parse '<' { () } | _ { long_error "Expected '<' but found" v lexbuf } @@ -585,7 +573,7 @@ and skip_json v = parse | "NaN" { () } | "Infinity" { () } | "-Infinity" { () } - | '"' { finish_skip_stringlit v lexbuf } + | '"' { finish_skip_string v lexbuf } | '-'? positive_int { () } | float { () } @@ -635,7 +623,7 @@ and skip_json v = parse | _ { long_error "Invalid token" v lexbuf } -and finish_skip_stringlit v = parse +and finish_skip_string v = parse ( '\\' (['"' '\\' '/' 'b' 'f' 'n' 'r' 't'] | 'u' hex hex hex hex) | [^'"' '\\'] )* '"' { () } @@ -643,7 +631,7 @@ and finish_skip_stringlit v = parse | eof { custom_error "Unexpected end of input" v lexbuf } and skip_ident v = parse - '"' { finish_skip_stringlit v lexbuf } + '"' { finish_skip_string v lexbuf } | ident { () } | _ { long_error "Expected string or identifier but found" v lexbuf } | eof { custom_error "Unexpected end of input" v lexbuf } @@ -661,7 +649,7 @@ and buffer_json v = parse | '-'? positive_int | float { add_lexeme v.buf lexbuf } - | '"' { finish_buffer_stringlit v lexbuf } + | '"' { finish_buffer_string v lexbuf } | '{' { try Buffer.add_char v.buf '{'; buffer_space v lexbuf; @@ -714,7 +702,7 @@ and buffer_json v = parse | _ { long_error "Invalid token" v lexbuf } -and finish_buffer_stringlit v = parse +and finish_buffer_string v = parse ( '\\' (['"' '\\' '/' 'b' 'f' 'n' 'r' 't'] | 'u' hex hex hex hex) | [^'"' '\\'] )* '"' { Buffer.add_char v.buf '"'; @@ -724,7 +712,7 @@ and finish_buffer_stringlit v = parse | eof { custom_error "Unexpected end of input" v lexbuf } and buffer_ident v = parse - '"' { finish_buffer_stringlit v lexbuf } + '"' { finish_buffer_string v lexbuf } | ident { add_lexeme v.buf lexbuf } | _ { long_error "Expected string or identifier but found" v lexbuf } | eof { custom_error "Unexpected end of input" v lexbuf } diff --git a/lib/write.ml b/lib/write.ml index 304d6c44..08493bca 100644 --- a/lib/write.ml +++ b/lib/write.ml @@ -189,8 +189,6 @@ let write_float_prec significant_figures ob x = let write_std_float_prec = write_float_prec let write_intlit = Buffer.add_string -let write_floatlit = Buffer.add_string -let write_stringlit = Buffer.add_string let rec iter2_aux f_elt f_sep x = function [] -> ()