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
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