Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib/basic.cppo.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#define INT
#define FLOAT
#define STRING

#include "type.ml"

#include "write.ml"
Expand All @@ -19,7 +15,3 @@ end
module Util = struct
#include "util.ml"
end

#undef INT
#undef FLOAT
#undef STRING
8 changes: 0 additions & 8 deletions lib/basic.cppo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
The main advantage of this module is its simplicity.
*)

#define INT
#define FLOAT
#define STRING

#include "type.ml"

#include "write.mli"
Expand All @@ -24,7 +20,3 @@
module Util : sig
#include "util.mli"
end

#undef INT
#undef FLOAT
#undef STRING
29 changes: 1 addition & 28 deletions lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
30 changes: 0 additions & 30 deletions lib/monomorphic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,24 @@ let rec pp fmt =
Format.fprintf fmt "`Bool (@[<hov>";
Format.fprintf fmt "%B" x;
Format.fprintf fmt "@])"
#ifdef INT
| `Int x ->
Format.fprintf fmt "`Int (@[<hov>";
Format.fprintf fmt "%d" x;
Format.fprintf fmt "@])"
#endif
#ifdef INTLIT
| `Intlit x ->
Format.fprintf fmt "`Intlit (@[<hov>";
Format.fprintf fmt "%S" x;
Format.fprintf fmt "@])"
#endif
#ifdef FLOAT
| `Float x ->
Format.fprintf fmt "`Float (@[<hov>";
Format.fprintf fmt "%F" x;
Format.fprintf fmt "@])"
#endif
#ifdef FLOATLIT
| `Floatlit x ->
Format.fprintf fmt "`Floatlit (@[<hov>";
Format.fprintf fmt "%S" x;
Format.fprintf fmt "@])"
#endif
#ifdef STRING
| `String x ->
Format.fprintf fmt "`String (@[<hov>";
Format.fprintf fmt "%S" x;
Format.fprintf fmt "@])"
#endif
#ifdef STRINGLIT
| `Stringlit x ->
Format.fprintf fmt "`Stringlit (@[<hov>";
Format.fprintf fmt "%S" x;
Format.fprintf fmt "@])"
#endif
| `Assoc xs ->
Format.fprintf fmt "`Assoc (@[<hov>";
Format.fprintf fmt "@[<2>[";
Expand Down Expand Up @@ -75,24 +57,12 @@ 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
#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
let xs = List.stable_sort compare_keys xs in
Expand Down
12 changes: 0 additions & 12 deletions lib/prettyprint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,12 @@ 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)
#endif
#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
#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 ->
Expand Down
25 changes: 0 additions & 25 deletions lib/raw.cppo.ml

This file was deleted.

27 changes: 0 additions & 27 deletions lib/raw.cppo.mli

This file was deleted.

2 changes: 0 additions & 2 deletions lib/read.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 12 additions & 58 deletions lib/read.mll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -169,45 +165,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;
Expand Down Expand Up @@ -310,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 }
Expand Down Expand Up @@ -619,7 +573,7 @@ and skip_json v = parse
| "NaN" { () }
| "Infinity" { () }
| "-Infinity" { () }
| '"' { finish_skip_stringlit v lexbuf }
| '"' { finish_skip_string v lexbuf }
| '-'? positive_int { () }
| float { () }

Expand Down Expand Up @@ -669,15 +623,15 @@ 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)
| [^'"' '\\'] )* '"'
{ () }
| _ { long_error "Invalid string literal" v lexbuf }
| 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 }
Expand All @@ -695,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;
Expand Down Expand Up @@ -748,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 '"';
Expand All @@ -758,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 }
Expand Down
Loading
Loading