From feaef7380cb8a52db63582478d54c55c685defc3 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Tue, 25 May 2010 21:48:36 -0700 Subject: [PATCH] changed api of jsx_parser --- examples/jsx_parser.erl | 20 ++++++++++++-------- examples/jsx_prettify.erl | 2 +- examples/jsx_stream_parser.erl | 2 +- src/jsx.erl | 2 +- src/jsx_common.hrl | 2 +- src/jsx_decoder.erl | 2 +- test/jsx_test.erl | 2 +- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/jsx_parser.erl b/examples/jsx_parser.erl index 00ce6f8..e6d5b40 100644 --- a/examples/jsx_parser.erl +++ b/examples/jsx_parser.erl @@ -1,6 +1,6 @@ %% The MIT License -%% Copyright (c) 2010 +%% Copyright (c) 2010 Alisdair Sullivan %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -25,19 +25,23 @@ -module(jsx_parser). --export([decode/2, event/2]). +-export([decode/1, event/2]). -export([literal/1, string/1, number/1]). %% this is a strict parser, no comments, no naked values and only one key per object. it %% also is not streaming, though it could be modified to parse partial objects/lists. -decode(JSON, Opts) -> - P = jsx:decoder({{jsx_parser, event}, []}, Opts), - {Result, Rest} = P(JSON), - case jsx:tail_clean(Rest) of - true -> Result - ; _ -> exit(badarg) +decode(JSON) -> + P = jsx:decoder({{jsx_parser, event}, []}, []), + try + {Result, Rest} = P(JSON), + case jsx:tail_clean(Rest) of + true -> Result + ; _ -> throw(badarg) + end + catch + _:_ -> throw(badarg) end. %% erlang representation is dicts for objects and lists for arrays. these are pushed diff --git a/examples/jsx_prettify.erl b/examples/jsx_prettify.erl index 72668bf..35e4fc7 100644 --- a/examples/jsx_prettify.erl +++ b/examples/jsx_prettify.erl @@ -1,6 +1,6 @@ %% The MIT License -%% Copyright (c) 2010 +%% Copyright (c) 2010 Alisdair Sullivan %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/examples/jsx_stream_parser.erl b/examples/jsx_stream_parser.erl index 34f4d80..fb1aaf5 100644 --- a/examples/jsx_stream_parser.erl +++ b/examples/jsx_stream_parser.erl @@ -1,6 +1,6 @@ %% The MIT License -%% Copyright (c) 2010 +%% Copyright (c) 2010 Alisdair Sullivan %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/src/jsx.erl b/src/jsx.erl index b56ab89..cefc52a 100644 --- a/src/jsx.erl +++ b/src/jsx.erl @@ -1,6 +1,6 @@ %% The MIT License -%% Copyright (c) 2010 +%% Copyright (c) 2010 Alisdair Sullivan %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/src/jsx_common.hrl b/src/jsx_common.hrl index e61a53f..3700b03 100644 --- a/src/jsx_common.hrl +++ b/src/jsx_common.hrl @@ -1,6 +1,6 @@ %% The MIT License -%% Copyright (c) 2010 +%% Copyright (c) 2010 Alisdair Sullivan %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/src/jsx_decoder.erl b/src/jsx_decoder.erl index 251164d..9b7be53 100644 --- a/src/jsx_decoder.erl +++ b/src/jsx_decoder.erl @@ -1,6 +1,6 @@ %% The MIT License -%% Copyright (c) 2010 +%% Copyright (c) 2010 Alisdair Sullivan %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/test/jsx_test.erl b/test/jsx_test.erl index f89e8ea..266778a 100644 --- a/test/jsx_test.erl +++ b/test/jsx_test.erl @@ -1,6 +1,6 @@ %% The MIT License -%% Copyright (c) 2010 +%% Copyright (c) 2010 Alisdair Sullivan %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal