changed api of jsx_parser

This commit is contained in:
alisdair sullivan 2010-05-25 21:48:36 -07:00
parent 8e05d0c1a6
commit feaef7380c
7 changed files with 18 additions and 14 deletions

View file

@ -1,6 +1,6 @@
%% The MIT License %% The MIT License
%% Copyright (c) 2010 <alisdairsullivan@yahoo.ca> %% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
%% Permission is hereby granted, free of charge, to any person obtaining a copy %% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal %% of this software and associated documentation files (the "Software"), to deal
@ -25,19 +25,23 @@
-module(jsx_parser). -module(jsx_parser).
-export([decode/2, event/2]). -export([decode/1, event/2]).
-export([literal/1, string/1, number/1]). -export([literal/1, string/1, number/1]).
%% this is a strict parser, no comments, no naked values and only one key per object. it %% 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. %% also is not streaming, though it could be modified to parse partial objects/lists.
decode(JSON, Opts) -> decode(JSON) ->
P = jsx:decoder({{jsx_parser, event}, []}, Opts), P = jsx:decoder({{jsx_parser, event}, []}, []),
{Result, Rest} = P(JSON), try
case jsx:tail_clean(Rest) of {Result, Rest} = P(JSON),
true -> Result case jsx:tail_clean(Rest) of
; _ -> exit(badarg) true -> Result
; _ -> throw(badarg)
end
catch
_:_ -> throw(badarg)
end. end.
%% erlang representation is dicts for objects and lists for arrays. these are pushed %% erlang representation is dicts for objects and lists for arrays. these are pushed

View file

@ -1,6 +1,6 @@
%% The MIT License %% The MIT License
%% Copyright (c) 2010 <alisdairsullivan@yahoo.ca> %% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
%% Permission is hereby granted, free of charge, to any person obtaining a copy %% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal %% of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,6 @@
%% The MIT License %% The MIT License
%% Copyright (c) 2010 <alisdairsullivan@yahoo.ca> %% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
%% Permission is hereby granted, free of charge, to any person obtaining a copy %% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal %% of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,6 @@
%% The MIT License %% The MIT License
%% Copyright (c) 2010 <alisdairsullivan@yahoo.ca> %% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
%% Permission is hereby granted, free of charge, to any person obtaining a copy %% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal %% of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,6 @@
%% The MIT License %% The MIT License
%% Copyright (c) 2010 <alisdairsullivan@yahoo.ca> %% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
%% Permission is hereby granted, free of charge, to any person obtaining a copy %% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal %% of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,6 @@
%% The MIT License %% The MIT License
%% Copyright (c) 2010 <alisdairsullivan@yahoo.ca> %% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
%% Permission is hereby granted, free of charge, to any person obtaining a copy %% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal %% of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,6 @@
%% The MIT License %% The MIT License
%% Copyright (c) 2010 <alisdairsullivan@yahoo.ca> %% Copyright (c) 2010 Alisdair Sullivan <alisdairsullivan@yahoo.ca>
%% Permission is hereby granted, free of charge, to any person obtaining a copy %% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal %% of this software and associated documentation files (the "Software"), to deal