Fix dialyzer errors.
This commit is contained in:
parent
4d7c1c5c18
commit
30b136ce72
6 changed files with 38 additions and 25 deletions
|
@ -34,13 +34,15 @@
|
||||||
-export([to_term/1, to_term/2]).
|
-export([to_term/1, to_term/2]).
|
||||||
|
|
||||||
-export_type([json_term/0, json_text/0, token/0]).
|
-export_type([json_term/0, json_text/0, token/0]).
|
||||||
-export_type([encoder/0, decoder/0, parser/0, internal_state/0]).
|
-export_type([config/0, encoder/0, decoder/0, parser/0, internal_state/0]).
|
||||||
|
|
||||||
|
|
||||||
|
-include("jsx_config.hrl").
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include("jsx_tests.hrl").
|
-include("jsx_tests.hrl").
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
-type config() :: #config{}.
|
||||||
|
|
||||||
-type json_term()
|
-type json_term()
|
||||||
:: [{binary() | atom(), json_term()}]
|
:: [{binary() | atom(), json_term()}]
|
||||||
|
@ -54,7 +56,6 @@
|
||||||
|
|
||||||
-type json_text() :: binary().
|
-type json_text() :: binary().
|
||||||
|
|
||||||
|
|
||||||
-spec encode(Source::json_term()) -> json_text() | {incomplete, encoder()}.
|
-spec encode(Source::json_term()) -> json_text() | {incomplete, encoder()}.
|
||||||
-spec encode(Source::json_term(), Config::jsx_to_json:config()) -> json_text() | {incomplete, encoder()}.
|
-spec encode(Source::json_term(), Config::jsx_to_json:config()) -> json_text() | {incomplete, encoder()}.
|
||||||
|
|
||||||
|
@ -178,3 +179,4 @@ resume(Term, {decoder, State, Handler, Acc, Stack}, Config) ->
|
||||||
jsx_decoder:resume(Term, State, Handler, Acc, Stack, jsx_config:parse_config(Config));
|
jsx_decoder:resume(Term, State, Handler, Acc, Stack, jsx_config:parse_config(Config));
|
||||||
resume(Term, {parser, State, Handler, Stack}, Config) ->
|
resume(Term, {parser, State, Handler, Stack}, Config) ->
|
||||||
jsx_parser:resume(Term, State, Handler, Stack, jsx_config:parse_config(Config)).
|
jsx_parser:resume(Term, State, Handler, Stack, jsx_config:parse_config(Config)).
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,21 @@
|
||||||
|
|
||||||
-include("jsx_config.hrl").
|
-include("jsx_config.hrl").
|
||||||
|
|
||||||
|
-type handler_type(Handler) ::
|
||||||
|
fun((jsx:json_text() | end_stream |
|
||||||
|
jsx:json_term(),
|
||||||
|
{decoder, any(), module(), null | list(), list()} |
|
||||||
|
{parser, any(), module(), list()} |
|
||||||
|
{encoder, any(), module()},
|
||||||
|
list({pre_encode, fun((any()) -> any())} |
|
||||||
|
{error_handler, Handler} |
|
||||||
|
{incomplete_handler, Handler} |
|
||||||
|
atom())) -> any()).
|
||||||
|
-type handler() :: handler_type(handler()).
|
||||||
|
-export_type([handler/0]).
|
||||||
|
|
||||||
%% parsing of jsx config
|
%% parsing of jsx config
|
||||||
-spec parse_config(Config::proplists:proplist()) -> config().
|
-spec parse_config(Config::proplists:proplist()) -> jsx:config().
|
||||||
|
|
||||||
parse_config(Config) ->
|
parse_config(Config) ->
|
||||||
parse_config(Config, #config{}).
|
parse_config(Config, #config{}).
|
||||||
|
@ -104,7 +116,7 @@ parse_config(Options, Config) ->
|
||||||
erlang:error(badarg, [Options, Config]).
|
erlang:error(badarg, [Options, Config]).
|
||||||
|
|
||||||
|
|
||||||
-spec config_to_list(Config::config()) -> proplists:proplist().
|
-spec config_to_list(Config::jsx:config()) -> proplists:proplist().
|
||||||
|
|
||||||
config_to_list(Config) ->
|
config_to_list(Config) ->
|
||||||
lists:map(
|
lists:map(
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
-record(config, {
|
-record(config, {
|
||||||
replaced_bad_utf8 = false,
|
replaced_bad_utf8 = false :: boolean(),
|
||||||
escaped_forward_slashes = false,
|
escaped_forward_slashes = false :: boolean(),
|
||||||
single_quoted_strings = false,
|
single_quoted_strings = false :: boolean(),
|
||||||
unescaped_jsonp = false,
|
unescaped_jsonp = false :: boolean(),
|
||||||
comments = false,
|
comments = false :: boolean(),
|
||||||
escaped_strings = false,
|
escaped_strings = false :: boolean(),
|
||||||
dirty_strings = false,
|
dirty_strings = false :: boolean(),
|
||||||
ignored_bad_escapes = false,
|
ignored_bad_escapes = false :: boolean(),
|
||||||
explicit_end = false,
|
explicit_end = false :: boolean(),
|
||||||
pre_encode = false,
|
pre_encode = false :: false | fun((any()) -> any()),
|
||||||
error_handler = false,
|
error_handler = false :: false | jsx_config:handler(),
|
||||||
incomplete_handler = false
|
incomplete_handler = false :: false | jsx_config:handler()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-type config() :: #config{}.
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
-export([decoder/3, resume/6]).
|
-export([decoder/3, resume/6]).
|
||||||
|
|
||||||
|
|
||||||
-spec decoder(Handler::module(), State::any(), Config::jsx:config()) -> jsx:decoder().
|
-spec decoder(Handler::module(), State::any(), Config::list()) -> jsx:decoder().
|
||||||
|
|
||||||
decoder(Handler, State, Config) ->
|
decoder(Handler, State, Config) ->
|
||||||
fun(JSON) -> start(JSON, {Handler, Handler:init(State)}, [], jsx_config:parse_config(Config)) end.
|
fun(JSON) -> start(JSON, {Handler, Handler:init(State)}, [], jsx_config:parse_config(Config)) end.
|
||||||
|
@ -48,7 +48,7 @@ decoder(Handler, State, Config) ->
|
||||||
Acc::any(),
|
Acc::any(),
|
||||||
Stack::list(atom()),
|
Stack::list(atom()),
|
||||||
Config::jsx:config()
|
Config::jsx:config()
|
||||||
) -> jsx:decoder() | {incomplete, _}.
|
) -> jsx:decoder() | {incomplete, jsx:decoder()}.
|
||||||
|
|
||||||
resume(Rest, State, Handler, Acc, Stack, Config) ->
|
resume(Rest, State, Handler, Acc, Stack, Config) ->
|
||||||
case State of
|
case State of
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
-export([encoder/3]).
|
-export([encoder/3]).
|
||||||
|
|
||||||
-spec encoder(Handler::module(), State::any(), Config::jsx:config()) -> jsx:encoder().
|
-spec encoder(Handler::module(), State::any(), Config::list()) -> jsx:encoder().
|
||||||
|
|
||||||
encoder(Handler, State, Config) ->
|
encoder(Handler, State, Config) ->
|
||||||
fun(JSON) ->
|
fun(JSON) ->
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
-export([init/1, handle_event/2]).
|
-export([init/1, handle_event/2]).
|
||||||
|
|
||||||
|
|
||||||
-spec parser(Handler::module(), State::any(), Config::jsx:config()) -> jsx:parser().
|
-spec parser(Handler::module(), State::any(), Config::list()) -> jsx:parser().
|
||||||
|
|
||||||
parser(Handler, State, Config) ->
|
parser(Handler, State, Config) ->
|
||||||
fun(Tokens) -> value(Tokens, {Handler, Handler:init(State)}, [], jsx_config:parse_config(Config)) end.
|
fun(Tokens) -> value(Tokens, {Handler, Handler:init(State)}, [], jsx_config:parse_config(Config)) end.
|
||||||
|
@ -36,12 +36,12 @@ parser(Handler, State, Config) ->
|
||||||
%% resume allows continuation from interrupted decoding without having to explicitly export
|
%% resume allows continuation from interrupted decoding without having to explicitly export
|
||||||
%% all states
|
%% all states
|
||||||
-spec resume(
|
-spec resume(
|
||||||
Rest::list(), %% was binary(),
|
Rest::jsx:token(),
|
||||||
State::atom(),
|
State::atom(),
|
||||||
Handler::{atom(), any()},
|
Handler::{atom(), any()},
|
||||||
Stack::list(atom()),
|
Stack::list(atom()),
|
||||||
Config::jsx:config()
|
Config::jsx:config()
|
||||||
) -> jsx:parser() | {incomplete, _}.
|
) -> jsx:parser() | {incomplete, jsx:parser()}.
|
||||||
|
|
||||||
resume(Rest, State, Handler, Stack, Config) ->
|
resume(Rest, State, Handler, Stack, Config) ->
|
||||||
case State of
|
case State of
|
||||||
|
@ -82,8 +82,8 @@ incomplete(State, Handler, Stack, Config=#config{incomplete_handler=F}) ->
|
||||||
F([], {parser, State, Handler, Stack}, jsx_config:config_to_list(Config)).
|
F([], {parser, State, Handler, Stack}, jsx_config:config_to_list(Config)).
|
||||||
|
|
||||||
|
|
||||||
handle_event([], Handler, _Config) -> Handler;
|
%handle_event([], Handler, _Config) -> Handler;
|
||||||
handle_event([Event|Rest], Handler, Config) -> handle_event(Rest, handle_event(Event, Handler, Config), Config);
|
%handle_event([Event|Rest], Handler, Config) -> handle_event(Rest, handle_event(Event, Handler, Config), Config);
|
||||||
handle_event(Event, {Handler, State}, _Config) -> {Handler, Handler:handle_event(Event, State)}.
|
handle_event(Event, {Handler, State}, _Config) -> {Handler, Handler:handle_event(Event, State)}.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue