modified error return value from {error, badjson} to {error, {badjson, Bin}} where Bin is the input from the point of the error
This commit is contained in:
parent
1a20e911a9
commit
a99644a926
5 changed files with 77 additions and 75 deletions
|
@ -13,7 +13,7 @@ it also includes an implementation of [eep0018][3], a pretty printer, a verifier
|
||||||
|
|
||||||
### usage ###
|
### usage ###
|
||||||
|
|
||||||
jsx provides an iterator based api that returns tuples of the form `{event, Event, Next}` where `Event` is an atom or tuple (see below) representing the json structure or value encountered. `Next` is a zero arity function that returns the next tuple in the sequence when called. it is stream based, and can also return the tuple `{incomplete, More}` to signify that input is exhausted. `More` is an arity one function that, when called with another binary, attempts to continue parsing treating the new binary as the tail of the preceding binary. errors in the json document are represented by the tuple `{error, badjson}`
|
jsx provides an iterator based api that returns tuples of the form `{event, Event, Next}` where `Event` is an atom or tuple (see below) representing the json structure or value encountered. `Next` is a zero arity function that returns the next tuple in the sequence when called. it is stream based, and can also return the tuple `{incomplete, More}` to signify that input is exhausted. `More` is an arity one function that, when called with another binary, attempts to continue parsing treating the new binary as the tail of the preceding binary. errors in the json document are represented by the tuple `{error, {badjson, Bin}}`
|
||||||
|
|
||||||
the following module
|
the following module
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,9 @@ the decoder can also return two other tuples:
|
||||||
the parser and resumes parsing as if never interrupted. the semantics
|
the parser and resumes parsing as if never interrupted. the semantics
|
||||||
are as if the new binary were appended to the already parsed binary
|
are as if the new binary were appended to the already parsed binary
|
||||||
|
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
|
Bin -- the remainder of the input at the point of the error. the first
|
||||||
|
byte of the binary is the byte that failed to match
|
||||||
'''
|
'''
|
||||||
|
|
||||||
`incomplete' is returned when input is exhausted. `error' is returned when invalid json input is detected. how obvious
|
`incomplete' is returned when input is exhausted. `error' is returned when invalid json input is detected. how obvious
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
-type jsx_parser_result() ::
|
-type jsx_parser_result() ::
|
||||||
{event, jsx_event(), fun(() -> jsx_parser_result())}
|
{event, jsx_event(), fun(() -> jsx_parser_result())}
|
||||||
| {incomplete, jsx_parser()}
|
| {incomplete, jsx_parser()}
|
||||||
| {error, badjson}.
|
| {error, {badjson, binary()}}.
|
||||||
|
|
||||||
|
|
||||||
-type supported_utf() :: utf8
|
-type supported_utf() :: utf8
|
||||||
|
|
|
@ -183,11 +183,11 @@ start(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
start(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
start(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -211,11 +211,11 @@ maybe_done(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
maybe_done(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
maybe_done(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ done(<<?solidus/?utfx, Rest/binary>>, #opts{comments=true}=Opts) ->
|
||||||
done(<<>>, Opts) ->
|
done(<<>>, Opts) ->
|
||||||
{event, end_json, fun() ->
|
{event, end_json, fun() ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, <<>>}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
done(Stream, Opts)
|
done(Stream, Opts)
|
||||||
end}
|
end}
|
||||||
|
@ -235,11 +235,11 @@ done(Bin, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
done(<<Bin/binary, Stream/binary>>, Opts)
|
done(<<Bin/binary, Stream/binary>>, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,11 +258,11 @@ object(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
object(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
object(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -294,11 +294,11 @@ array(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
array(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
array(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -328,11 +328,11 @@ value(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
value(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
value(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -346,11 +346,11 @@ colon(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
colon(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
colon(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -367,11 +367,11 @@ key(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
key(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
key(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ unquoted_key(Bin, Stack, Opts, Acc) ->
|
||||||
case partial_utf(Bin) of
|
case partial_utf(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
unquoted_key(<<Bin/binary, Stream/binary>>,
|
unquoted_key(<<Bin/binary, Stream/binary>>,
|
||||||
Stack,
|
Stack,
|
||||||
|
@ -398,7 +398,7 @@ unquoted_key(Bin, Stack, Opts, Acc) ->
|
||||||
Acc
|
Acc
|
||||||
)
|
)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -423,11 +423,11 @@ string(Bin, Stack, Opts, Acc) ->
|
||||||
case partial_utf(Bin) of
|
case partial_utf(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
string(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
string(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -506,11 +506,11 @@ escape(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
escape(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
escape(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -571,7 +571,7 @@ escaped_unicode(Bin, Stack, Opts, String, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
escaped_unicode(<<Bin/binary, Stream/binary>>,
|
escaped_unicode(<<Bin/binary, Stream/binary>>,
|
||||||
Stack,
|
Stack,
|
||||||
|
@ -580,7 +580,7 @@ escaped_unicode(Bin, Stack, Opts, String, Acc) ->
|
||||||
Acc
|
Acc
|
||||||
)
|
)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -613,11 +613,11 @@ negative(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
negative(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
negative(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -656,11 +656,11 @@ zero(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
zero(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
zero(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -711,11 +711,11 @@ integer(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
integer(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
integer(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -728,7 +728,7 @@ initial_decimal(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
initial_decimal(<<Bin/binary, Stream/binary>>,
|
initial_decimal(<<Bin/binary, Stream/binary>>,
|
||||||
Stack,
|
Stack,
|
||||||
|
@ -736,7 +736,7 @@ initial_decimal(Bin, Stack, Opts, Acc) ->
|
||||||
Acc
|
Acc
|
||||||
)
|
)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -785,11 +785,11 @@ decimal(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
decimal(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
decimal(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -803,11 +803,11 @@ e(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
e(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
e(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -818,11 +818,11 @@ ex(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
ex(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
ex(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -863,11 +863,11 @@ exp(Bin, Stack, Opts, Acc) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
exp(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
exp(<<Bin/binary, Stream/binary>>, Stack, Opts, Acc)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -877,11 +877,11 @@ tr(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
tr(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
tr(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -891,11 +891,11 @@ tru(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
tru(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
tru(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -905,11 +905,11 @@ true(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
true(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
true(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -919,11 +919,11 @@ fa(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
fa(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
fa(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -933,11 +933,11 @@ fal(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
fal(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
fal(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -947,11 +947,11 @@ fals(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
fals(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
fals(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -961,11 +961,11 @@ false(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
false(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
false(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -975,11 +975,11 @@ nu(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
nu(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
nu(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -989,11 +989,11 @@ nul(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
nul(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
nul(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1003,11 +1003,11 @@ null(Bin, Stack, Opts) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
null(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
null(<<Bin/binary, Stream/binary>>, Stack, Opts)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1022,11 +1022,11 @@ maybe_comment(Bin, Resume) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
maybe_comment(<<Bin/binary, Stream/binary>>, Resume)
|
maybe_comment(<<Bin/binary, Stream/binary>>, Resume)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1038,11 +1038,11 @@ comment(Bin, Resume) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
comment(<<Bin/binary, Stream/binary>>, Resume)
|
comment(<<Bin/binary, Stream/binary>>, Resume)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1054,9 +1054,9 @@ maybe_comment_done(Bin, Resume) ->
|
||||||
case ?partial_codepoint(Bin) of
|
case ?partial_codepoint(Bin) of
|
||||||
true ->
|
true ->
|
||||||
{incomplete, fun(end_stream) ->
|
{incomplete, fun(end_stream) ->
|
||||||
{error, badjson}
|
{error, {badjson, Bin}}
|
||||||
; (Stream) ->
|
; (Stream) ->
|
||||||
maybe_comment_done(<<Bin/binary, Stream/binary>>, Resume)
|
maybe_comment_done(<<Bin/binary, Stream/binary>>, Resume)
|
||||||
end}
|
end}
|
||||||
; false -> {error, badjson}
|
; false -> {error, {badjson, Bin}}
|
||||||
end.
|
end.
|
10
src/jsx.erl
10
src/jsx.erl
|
@ -50,7 +50,7 @@
|
||||||
|
|
||||||
%% @type jsx_parser_result() = {event, jsx_event(), (() -> jsx_parser_result())}
|
%% @type jsx_parser_result() = {event, jsx_event(), (() -> jsx_parser_result())}
|
||||||
%% | {incomplete, jsx_parser()}
|
%% | {incomplete, jsx_parser()}
|
||||||
%% | {error, badjson}
|
%% | {error, {badjson, binary()}}
|
||||||
%% | {error, badarg}.
|
%% | {error, badarg}.
|
||||||
|
|
||||||
%% @type jsx_event() = start_object
|
%% @type jsx_event() = start_object
|
||||||
|
@ -490,7 +490,7 @@ detect_encoding(<<X>>, Opts) when X =/= 0 ->
|
||||||
try
|
try
|
||||||
{incomplete, Next} = (jsx_utf8:parser(Opts))(<<X>>),
|
{incomplete, Next} = (jsx_utf8:parser(Opts))(<<X>>),
|
||||||
Next(end_stream)
|
Next(end_stream)
|
||||||
catch error:function_clause -> {error, badjson}
|
catch error:function_clause -> {error, {badjson, <<X>>}}
|
||||||
end
|
end
|
||||||
; (Stream) -> detect_encoding(<<X, Stream/binary>>, Opts)
|
; (Stream) -> detect_encoding(<<X, Stream/binary>>, Opts)
|
||||||
end
|
end
|
||||||
|
@ -501,7 +501,7 @@ detect_encoding(<<0, X>>, Opts) when X =/= 0 ->
|
||||||
try
|
try
|
||||||
{incomplete, Next} = (jsx_utf16:parser(Opts))(<<0, X>>),
|
{incomplete, Next} = (jsx_utf16:parser(Opts))(<<0, X>>),
|
||||||
Next(end_stream)
|
Next(end_stream)
|
||||||
catch error:function_clause -> {error, badjson}
|
catch error:function_clause -> {error, {badjson, <<0, X>>}}
|
||||||
end
|
end
|
||||||
; (Stream) -> detect_encoding(<<0, X, Stream/binary>>, Opts)
|
; (Stream) -> detect_encoding(<<0, X, Stream/binary>>, Opts)
|
||||||
end
|
end
|
||||||
|
@ -512,7 +512,7 @@ detect_encoding(<<X, 0>>, Opts) when X =/= 0 ->
|
||||||
try
|
try
|
||||||
{incomplete, Next} = (jsx_utf16le:parser(Opts))(<<X, 0>>),
|
{incomplete, Next} = (jsx_utf16le:parser(Opts))(<<X, 0>>),
|
||||||
Next(end_stream)
|
Next(end_stream)
|
||||||
catch error:function_clause -> {error, badjson}
|
catch error:function_clause -> {error, {badjson, <<X, 0>>}}
|
||||||
end
|
end
|
||||||
; (Stream) -> detect_encoding(<<X, 0, Stream/binary>>, Opts)
|
; (Stream) -> detect_encoding(<<X, 0, Stream/binary>>, Opts)
|
||||||
end
|
end
|
||||||
|
@ -521,7 +521,7 @@ detect_encoding(<<X, 0>>, Opts) when X =/= 0 ->
|
||||||
%% not enough input, request more
|
%% not enough input, request more
|
||||||
detect_encoding(Bin, Opts) ->
|
detect_encoding(Bin, Opts) ->
|
||||||
{incomplete,
|
{incomplete,
|
||||||
fun(end_stream) -> {error, badjson}
|
fun(end_stream) -> {error, {badjson, Bin}}
|
||||||
; (Stream) -> detect_encoding(<<Bin/binary, Stream/binary>>, Opts)
|
; (Stream) -> detect_encoding(<<Bin/binary, Stream/binary>>, Opts)
|
||||||
end
|
end
|
||||||
}.
|
}.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue