From fef001479f4c40bea27a1ac5e277e1d8a457f492 Mon Sep 17 00:00:00 2001 From: Led Date: Mon, 3 Aug 2015 00:24:58 +0300 Subject: [PATCH 1/3] fix build docs --- rebar.config | 3 ++- src/jsx.erl | 30 +++++++++++++++++++++--------- src/jsx_consult.erl | 4 ++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/rebar.config b/rebar.config index 38858b5..8152f4d 100644 --- a/rebar.config +++ b/rebar.config @@ -3,4 +3,5 @@ % {d, maps_always}, {platform_define, "R14|R15", 'no_binary_to_whatever'}, {platform_define, "^((?!R1[456]).)*$", 'maps_support'} -]}. \ No newline at end of file +]}. +{edoc_opts, [{preprocess, true}]}. \ No newline at end of file diff --git a/src/jsx.erl b/src/jsx.erl index 0401ce5..0b55b2e 100644 --- a/src/jsx.erl +++ b/src/jsx.erl @@ -67,23 +67,29 @@ -type config() :: jsx_config:config(). -spec encode(Source::json_term()) -> json_text(). --spec encode(Source::json_term(), Config::jsx_to_json:config()) -> json_text() | {incomplete, encoder()}. encode(Source) -> encode(Source, []). + +-spec encode(Source::json_term(), Config::jsx_to_json:config()) -> json_text() | {incomplete, encoder()}. + encode(Source, Config) -> jsx_to_json:to_json(Source, Config). -spec decode(Source::json_text()) -> json_term(). --spec decode(Source::json_text(), Config::jsx_to_term:config()) -> json_term() | {incomplete, decoder()}. decode(Source) -> decode(Source, []). + +-spec decode(Source::json_text(), Config::jsx_to_term:config()) -> json_term() | {incomplete, decoder()}. + decode(Source, Config) -> jsx_to_term:to_term(Source, Config). -spec format(Source::json_text()) -> json_text(). --spec format(Source::json_text(), Config::jsx_to_json:config()) -> json_text() | {incomplete, decoder()}. format(Source) -> format(Source, []). + +-spec format(Source::json_text(), Config::jsx_to_json:config()) -> json_text() | {incomplete, decoder()}. + format(Source, Config) -> jsx_to_json:format(Source, Config). @@ -97,24 +103,30 @@ minify(Source) -> format(Source, []). prettify(Source) -> format(Source, [space, {indent, 2}]). --spec is_json(Source::any()) -> true | false. --spec is_json(Source::any(), Config::jsx_verify:config()) -> true | false | {incomplete, decoder()}. +-spec is_json(Source::any()) -> boolean(). is_json(Source) -> is_json(Source, []). + +-spec is_json(Source::any(), Config::jsx_verify:config()) -> boolean() | {incomplete, decoder()}. + is_json(Source, Config) -> jsx_verify:is_json(Source, Config). --spec is_term(Source::any()) -> true | false. --spec is_term(Source::any(), Config::jsx_verify:config()) -> true | false | {incomplete, encoder()}. +-spec is_term(Source::any()) -> boolean(). is_term(Source) -> is_term(Source, []). + +-spec is_term(Source::any(), Config::jsx_verify:config()) -> boolean() | {incomplete, encoder()}. + is_term(Source, Config) -> jsx_verify:is_term(Source, Config). -spec consult(File::file:name_all()) -> list(json_term()). --spec consult(File::file:name_all(), Config::jsx_to_term:config()) -> list(json_term()). consult(File) -> consult(File, []). + +-spec consult(File::file:name_all(), Config::jsx_to_term:config()) -> list(json_term()). + consult(File, Config) -> jsx_consult:consult(File, Config). @@ -170,7 +182,7 @@ resume(Term, {parser, State, Handler, Stack}, Config) -> jsx_parser:resume(Term, State, Handler, Stack, jsx_config:parse_config(Config)). --spec maps_support() -> true | false. +-spec maps_support() -> boolean(). -ifndef(maps_support). maps_support() -> false. diff --git a/src/jsx_consult.erl b/src/jsx_consult.erl index 0c9284e..2b0f1da 100644 --- a/src/jsx_consult.erl +++ b/src/jsx_consult.erl @@ -58,8 +58,6 @@ -endif. --spec consult(File::file:name_all(), Config::config()) -> [json_value()]. - -ifdef(maps_always). opts(Opts) -> [return_maps, multi_term] ++ Opts. -endif. @@ -67,6 +65,8 @@ opts(Opts) -> [return_maps, multi_term] ++ Opts. opts(Opts) -> [multi_term] ++ Opts. -endif. +-spec consult(File::file:name_all(), Config::config()) -> [json_value()]. + consult(File, Config) when is_list(Config) -> case file:read_file(File) of {ok, Bin} -> From 446f674f27339ec92a98d78315cbd71e3b6d1151 Mon Sep 17 00:00:00 2001 From: Led Date: Mon, 3 Aug 2015 00:44:49 +0300 Subject: [PATCH 2/3] add rebar.config.script for checking support maps and binary_to_{integer,float}/1 --- rebar.config | 2 -- rebar.config.script | 11 +++++++++++ src/jsx_decoder.erl | 3 +-- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 rebar.config.script diff --git a/rebar.config b/rebar.config index 8152f4d..0dcef82 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,5 @@ {erl_opts, [ % uncomment to always decode to maps % {d, maps_always}, - {platform_define, "R14|R15", 'no_binary_to_whatever'}, - {platform_define, "^((?!R1[456]).)*$", 'maps_support'} ]}. {edoc_opts, [{preprocess, true}]}. \ No newline at end of file diff --git a/rebar.config.script b/rebar.config.script new file mode 100644 index 0000000..4510155 --- /dev/null +++ b/rebar.config.script @@ -0,0 +1,11 @@ +Def0 = case erlang:is_builtin(erlang, binary_to_integer, 1) andalso + erlang:is_builtin(erlang, binary_to_float, 1) of + true -> []; + false -> [{d, no_binary_to_whatever}] + end, +Defs = case erlang:is_builtin(erlang, is_map, 1) of + true -> [{d, maps_support}|Def0]; + false -> Def0 + end, +lists:keystore(erl_opts, 1, CONFIG, + {erl_opts, proplists:get_value(erl_opts, CONFIG, []) ++ Defs}). diff --git a/src/jsx_decoder.erl b/src/jsx_decoder.erl index 0f03975..5b6d300 100644 --- a/src/jsx_decoder.erl +++ b/src/jsx_decoder.erl @@ -1010,8 +1010,7 @@ finish_number(Rest, Handler, Acc, Stack, Config) -> -ifndef(no_binary_to_whatever). format_number({integer, Acc}) -> {integer, binary_to_integer(Acc)}; format_number({float, Acc}) -> {float, binary_to_float(Acc)}. --endif. --ifdef(no_binary_to_whatever). +-else. format_number({integer, Acc}) -> {integer, list_to_integer(unicode:characters_to_list(Acc))}; format_number({float, Acc}) -> {float, list_to_float(unicode:characters_to_list(Acc))}. -endif. From 7be3d9dc629d8e0b31355ec34d485b385c61c4ef Mon Sep 17 00:00:00 2001 From: Led Date: Mon, 3 Aug 2015 00:52:22 +0300 Subject: [PATCH 3/3] add .rebar and doc dirs to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4c14464..4a8eee6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ ebin *.plt erl_crash.dump .DS_Store +doc +.rebar