Boost logo

Boost Users :

Subject: [Boost-users] [Spirit/Qi] Malformed JSON parser
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2013-08-05 18:54:25


Hi,

I am trying to add a support for degenerate / corner cases for my JSON
parser.

First I needed support for malformed null values for object members like
that:

obj :
{
  "bad_member: ,
  "correct_member: null
}

I would like the parser to generate same result for both members in that
case (null value). I eventually came up with custom semantic action that
does the job:

  struct MakeMember
  {
    typedef void result_type;

    template <class Arg1, class Ctx>
    result_type operator()(Arg1& arg1, Ctx& ctx, bool& b) const
    {
      using namespace boost::fusion;
      auto m0 = boost::fusion::at_c<0>(arg1);
      auto m1 = boost::fusion::at_c<1>(arg1);
      ctx.attributes.car.first = m0;
      ctx.attributes.car.second = m1 ? *m1 : NullT();
    }
  };

but I have a feeling that is not the best way to do it. I would rally
appreciate an advice on that.

Secondly I want to add support for empty array members:

obj :
{
  "empty_array" : []
}

but this time I am totally lost. My array parser looks like this:

array = '[' >> value % ',' >> ']';

which is only god for 1 or more element list. I tried

array = '[' >> -(value % ',') >> ']';

and altho it compiled it still didn't reckognize "[]' as Array object.

Full source code of parser / grammar attched.

Regards,
Szymon







Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net