This is an automated email from the git hooks/post-receive script. glondu pushed a commit to branch master in repository yojson.
commit 7bbe465a4bf88152debba55f9257eef950e6ebc1 Author: Stephane Glondu <st...@glondu.net> Date: Thu Sep 10 11:56:42 2015 +0200 Imported Upstream version 1.2.1 --- Changes | 2 ++ Makefile | 10 +++++----- read.mli | 13 ++++++++++--- read.mll | 18 ++++++++++++------ util.ml | 4 ++++ util.mli | 15 +++++++++------ 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/Changes b/Changes index 7419d87..83be090 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,8 @@ bug = bug or security fix doc = major changes in the documentation pkg = changes in the structure of the package or in the installation procedure +trunk: [bug] fix off-by-2 error in column error start location + 2014-12-26 1.2.0: [+ui] new function Yojson.Safe.buffer_json for saving a raw JSON string while parsing in order to parse later diff --git a/Makefile b/Makefile index 681f893..7e63f83 100755 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ -VERSION = 1.2.0 +VERSION = 1.2.1 -ifeq "$(shell ocamlc -config |grep os_type)" "os_type: Win32" +ifeq "$(shell ocamlfind ocamlc -config |grep os_type)" "os_type: Win32" EXE=.exe else EXE= endif -NATDYNLINK := $(shell if [ -f `ocamlc -where`/dynlink.cmxa ]; then echo YES; else echo NO; fi) +NATDYNLINK := $(shell if [ -f `ocamlfind ocamlc -where`/dynlink.cmxa ]; then echo YES; else echo NO; fi) FLAGS = -dtypes -g CMO = yojson.cmo yojson_biniou.cmo @@ -76,7 +76,7 @@ yojson.cmx: yojson.cmi yojson.ml ocamlfind ocamlopt -c $(FLAGS) -package $(PACKS) yojson.ml yojson.cmxs: yojson.cmx - ocamlopt -shared -linkall -I . -o yojson.cmxs yojson.cmx + ocamlfind ocamlopt -shared -linkall -I . -o yojson.cmxs yojson.cmx yojson_biniou.cmi: yojson_biniou.mli ocamlfind ocamlc -c $(FLAGS) -package $(PACKS) yojson_biniou.mli @@ -88,7 +88,7 @@ yojson_biniou.cmx: yojson_biniou.cmi yojson_biniou.ml ocamlfind ocamlopt -c $(FLAGS) -package $(PACKS) yojson_biniou.ml yojson_biniou.cmxs: yojson_biniou.cmx - ocamlopt -shared -linkall -I . -o yojson_biniou.cmxs yojson_biniou.cmx + ocamlfind ocamlopt -shared -linkall -I . -o yojson_biniou.cmxs yojson_biniou.cmx ydump$(EXE): yojson.cmx yojson_biniou.cmx ydump.ml ocamlfind ocamlopt -o ydump$(EXE) $(FLAGS) -package $(PACKS) -linkpkg \ diff --git a/read.mli b/read.mli index 8f9502a..182f587 100644 --- a/read.mli +++ b/read.mli @@ -229,10 +229,17 @@ val read_lbr : lexer_state -> Lexing.lexbuf -> unit val read_rbr : lexer_state -> Lexing.lexbuf -> unit val read_fields : - ('a -> string -> lexer_state -> Lexing.lexbuf -> 'a) -> - 'a -> + ('acc -> string -> lexer_state -> Lexing.lexbuf -> 'acc) -> + 'acc -> lexer_state -> - Lexing.lexbuf -> 'a + Lexing.lexbuf -> 'acc + +val read_abstract_fields : + (lexer_state -> Lexing.lexbuf -> 'key) -> + ('acc -> 'key -> lexer_state -> Lexing.lexbuf -> 'acc) -> + 'acc -> + lexer_state -> + Lexing.lexbuf -> 'acc val read_lcurl : lexer_state -> Lexing.lexbuf -> unit val read_object_end : Lexing.lexbuf -> unit diff --git a/read.mll b/read.mll index 09c0ed1..6a7f129 100644 --- a/read.mll +++ b/read.mll @@ -44,10 +44,10 @@ | _ -> assert false let custom_error descr v lexbuf = - let offs = lexbuf.lex_abs_pos in + let offs = lexbuf.lex_abs_pos - 1 in let bol = v.bol in - let pos1 = offs + lexbuf.lex_start_pos - bol in - let pos2 = max pos1 (offs + lexbuf.lex_curr_pos - bol - 1) in + let pos1 = offs + lexbuf.lex_start_pos - bol - 1 in + let pos2 = max pos1 (offs + lexbuf.lex_curr_pos - bol) in let file_line = match v.fname with None -> "Line" @@ -670,12 +670,13 @@ and read_tuple_sep2 v std = parse | _ { long_error "Expected ',' or ')' but found" v lexbuf } | eof { custom_error "Unexpected end of input" v lexbuf } -and read_fields read_field init_acc v = parse +(* Read a JSON object, reading the keys using a custom parser *) +and read_abstract_fields read_key read_field init_acc v = parse '{' { let acc = ref init_acc in try read_space v lexbuf; read_object_end lexbuf; - let field_name = read_ident v lexbuf in + let field_name = read_key v lexbuf in read_space v lexbuf; read_colon v lexbuf; read_space v lexbuf; @@ -684,7 +685,7 @@ and read_fields read_field init_acc v = parse read_space v lexbuf; read_object_sep v lexbuf; read_space v lexbuf; - let field_name = read_ident v lexbuf in + let field_name = read_key v lexbuf in read_space v lexbuf; read_colon v lexbuf; read_space v lexbuf; @@ -1084,6 +1085,11 @@ and junk = parse let l = read_list_rev read_cell v lexbuf in array_of_rev_list l + (* Read a JSON object, reading the keys into OCaml strings + (provided for backward compatibility) *) + let read_fields read_field init_acc v = + read_abstract_fields read_ident read_field init_acc v + let finish v lexbuf = read_space v lexbuf; if not (read_eof lexbuf) then diff --git a/util.ml b/util.ml index 958b999..943ba69 100644 --- a/util.ml +++ b/util.ml @@ -190,3 +190,7 @@ let filter_string l = `String x -> Some x | _ -> None ) l + +let keys o = + let names = to_assoc o in + List.map (fun (key, _) -> key) names diff --git a/util.mli b/util.mli index dfcec47..aa777aa 100644 --- a/util.mli +++ b/util.mli @@ -1,7 +1,7 @@ (** This module provides combinators for extracting fields from JSON values. This approach is recommended for reading a few fields - from data returned by public APIs. However for more complex applications + from data returned by public APIs. However for more complex applications we recommend {{:https://github.com/MyLifeLabs/atdgen}Atdgen}. Here is some sample JSON data: @@ -72,6 +72,9 @@ val ( |> ) : 'a -> ('a -> 'b) -> 'b (** Forward pipe operator; useful for composing JSON access functions without too many parentheses *) +val keys: json -> string list + (** Returns all the key names in the given JSON object *) + val member : string -> json -> json (** [member k obj] returns the value associated with the key [k] in the JSON object [obj], or [`Null] if [k] is not present in [obj]. *) @@ -96,7 +99,7 @@ val to_bool : json -> bool (** Extract a boolean value or raise [Type_error]. *) val to_bool_option : json -> bool option - (** Extract [Some] boolean value, + (** Extract [Some] boolean value, return [None] if the value is null, or raise [Type_error] otherwise. *) @@ -104,7 +107,7 @@ val to_number : json -> float (** Extract a number or raise [Type_error]. *) val to_number_option : json -> float option - (** Extract [Some] number, + (** Extract [Some] number, return [None] if the value is null, or raise [Type_error] otherwise. *) @@ -113,7 +116,7 @@ val to_float : json -> float [to_number] is generally preferred as it also works with int literals. *) val to_float_option : json -> float option - (** Extract [Some] float value, + (** Extract [Some] float value, return [None] if the value is null, or raise [Type_error] otherwise. [to_number_option] is generally preferred as it also works @@ -123,7 +126,7 @@ val to_int : json -> int (** Extract an int from a JSON int or raise [Type_error]. *) val to_int_option : json -> int option - (** Extract [Some] int from a JSON int, + (** Extract [Some] int from a JSON int, return [None] if the value is null, or raise [Type_error] otherwise. *) @@ -134,7 +137,7 @@ val to_string : json -> string (** Extract a string from a JSON string or raise [Type_error]. *) val to_string_option : json -> string option - (** Extract [Some] string from a JSON string, + (** Extract [Some] string from a JSON string, return [None] if the value is null, or raise [Type_error] otherwise. *) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/yojson.git _______________________________________________ Pkg-ocaml-maint-commits mailing list Pkg-ocaml-maint-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-ocaml-maint-commits