[systemd-devel] [PATCH 2/5] shared/json: JSON parser + number tokenizer bugfix

Pavel Odvody podvody at redhat.com
Fri May 15 07:03:46 PDT 2015


On Fri, 2015-05-15 at 15:23 +0200, Lennart Poettering wrote:
> On Thu, 07.05.15 17:47, Pavel Odvody (podvody at redhat.com) wrote:
> 
> Hmm, so if I grok this right, then this at's a DOM-like ("object
> model") parser for json, where we previously hat a SAX-like ("stream")
> parser only. What's the rationale for this? Why doesn't the stream
> parser suffice?
> 
> I intentionally opted for a stream parser when I wrote the code, and
> that#s actually the primary reason why i roleld my own parser here,
> instead of using some existing library....
> 

Hmm, I'd call it lexer/tokenizer, since the burden of syntactic analysis
is on the user. The parser is actually rather thin wrapper around
json_tokenize.

Rationale: the v2 manifest (also) contains embedded JSON documents and
is itself versioned, so it will change sooner or later.
I believe that parsing the manifest, or any "decently" complex JSON
document, using the stream parser would yield equal or bigger chunk of
code than generic DOM parser + few lines that consume it's API.

So to sum it up:

1) Syntactic analysis
2) Maintainability
3) Easier consumption


> > Signed-off-by: Pavel Odvody <podvody at redhat.com>
> > ---
> >  src/shared/json.c | 437 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
> >  src/shared/json.h |  36 +++++
> >  2 files changed, 463 insertions(+), 10 deletions(-)
> > 
> > diff --git a/src/shared/json.c b/src/shared/json.c
> > index 45c8ece..00d5fce 100644
> > --- a/src/shared/json.c
> > +++ b/src/shared/json.c
> > @@ -21,17 +21,173 @@
> 
> Lennart
> 


-- 
Pavel Odvody <podvody at redhat.com>
Software Engineer - EMEA ENG Developer Experience
5EC1 95C1 8E08 5BD9 9BBF 9241 3AFA 3A66 024F F68D
Red Hat Czech s.r.o., Purky┼łova 99/71, 612 45, Brno

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150515/d7b35728/attachment.sig>


More information about the systemd-devel mailing list