Skip to content

Commit

Permalink
Remove variant code
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonidas-from-XIV committed Jun 4, 2024
1 parent 8bbbc1f commit 1b7083f
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 37 deletions.
4 changes: 0 additions & 4 deletions lib/read.mli
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ val map_ident :
lexer_state -> (string -> int -> int -> 'a) -> Lexing.lexbuf -> 'a
(* equivalent to read_ident *)

type variant_kind = [ `Square_bracket | `Double_quote ]

val start_any_variant : lexer_state -> Lexing.lexbuf -> variant_kind
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 @@ -193,7 +190,6 @@ val read_array :
Lexing.lexbuf ->
'a array

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_lbr : lexer_state -> Lexing.lexbuf -> unit
Expand Down
14 changes: 0 additions & 14 deletions lib/read.mll
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@
let map_lexeme f (lexbuf : Lexing.lexbuf) =
let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos in
f (Bytes.sub_string lexbuf.lex_buffer lexbuf.lex_start_pos len) 0 len

type variant_kind = [ `Square_bracket | `Double_quote ]
}

let space = [' ' '\t' '\r']+
Expand Down Expand Up @@ -339,13 +337,6 @@ and read_comma v = parse
| _ { long_error "Expected ',' but found" v lexbuf }
| eof { custom_error "Unexpected end of input" v lexbuf }

and start_any_variant v = parse
| '"' { Buffer.clear v.buf;
`Double_quote }
| '[' { `Square_bracket }
| _ { long_error "Expected '<', '\"' or '[' but found" v lexbuf }
| eof { custom_error "Unexpected end of input" v lexbuf }

and finish_comment v = parse
| "*/" { () }
| eof { long_error "Unterminated comment" v lexbuf }
Expand Down Expand Up @@ -598,11 +589,6 @@ and read_colon v = parse
| _ { long_error "Expected ':' but found" v lexbuf }
| eof { custom_error "Unexpected end of input" v lexbuf }

and start_any_tuple v = parse
| '[' { true }
| _ { long_error "Expected '(' or '[' but found" v lexbuf }
| eof { custom_error "Unexpected end of input" v lexbuf }

and read_lpar v = parse
'(' { () }
| _ { long_error "Expected '(' but found" v lexbuf }
Expand Down
8 changes: 2 additions & 6 deletions test/test_read.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,13 @@ let map_ident_and_string () =
let skip_over f = f lexer_state lexbuf in
let map_f mapper f = mapper lexer_state f lexbuf in
let map_ident = map_f Yojson.Safe.map_ident in
let map_string = map_f Yojson.Safe.map_string in

skip_over Yojson.Safe.read_lcurl;
map_ident (ident_expected "foo");
skip_over Yojson.Safe.read_colon;

let variant = skip_over Yojson.Safe.start_any_variant in
Alcotest.(check Testable.variant_kind)
"String starts with double quote" `Double_quote variant;

map_string (ident_expected "hello");
let key = skip_over Yojson.Safe.read_string in
Alcotest.(check string) "String is as expected" "hello" key;

Alcotest.check_raises "Reading } raises End_of_object" Yojson.End_of_object
(fun () -> Yojson.Safe.read_object_end lexbuf)
Expand Down
12 changes: 0 additions & 12 deletions test/testable.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
let yojson = Alcotest.testable Yojson.Safe.pp Yojson.Safe.equal

let variant_kind_pp fmt = function
| `Square_bracket -> Format.fprintf fmt "`Square_bracket"
| `Double_quote -> Format.fprintf fmt "`Double_quote"

let variant_kind_equal a b =
match (a, b) with
| `Square_bracket, `Square_bracket -> true
| `Double_quote, `Double_quote -> true
| _ -> false

let variant_kind = Alcotest.testable variant_kind_pp variant_kind_equal
1 change: 0 additions & 1 deletion test/testable.mli
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
val yojson : Yojson.Safe.t Alcotest.testable
val variant_kind : Yojson.Safe.variant_kind Alcotest.testable

0 comments on commit 1b7083f

Please sign in to comment.