JSON null value?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

JSON null value?

Richard-45
Looking at the JSON grammar <http://www.json.org/>, one of the
acceptable values is the word "null".  There isn't any attribute type
for "null" (its not a Boolean, Number, String, Array or Object).  So I
was thinking that I would use my own valueless type as the attribute,
something like:

struct null_type
{
};

rule<Iter, null_type(), skipper> null;

null = lit("null");

However this gave me a bunch of compile errors about null_type not
having a value_type nested typedef.

What's the right way to have an attribute that just acts as 'tag' for
the presence of something in the input grammar?
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>

------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: JSON null value?

Jeroen Habraken
Hi,

On 9 November 2014 13:38, Richard <[hidden email]> wrote:
Looking at the JSON grammar <http://www.json.org/>, one of the
acceptable values is the word "null".  There isn't any attribute type
for "null" (its not a Boolean, Number, String, Array or Object).  So I
was thinking that I would use my own valueless type as the attribute,
something like:

struct null_type
{
};

rule<Iter, null_type(), skipper> null;

null = lit("null");

However this gave me a bunch of compile errors about null_type not
having a value_type nested typedef.

What's the right way to have an attribute that just acts as 'tag' for
the presence of something in the input grammar?

Use qi::attr as follows, qi::rule<I, null_type(), S> null = qi::lit("null") >> qi::attr(null_type()); See http://www.boost.org/doc/libs/1_57_0/libs/spirit/doc/html/spirit/qi/reference/auxiliary/attr.html for more on qi::attr.

Jeroen

------------------------------------------------------------------------------

_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: JSON null value?

Richard-45

In article <CAGCnmH3bM2vz1WM3VX+KwwyqE50Tjf=[hidden email]>,
    Jeroen Habraken <[hidden email]> writes:

> Use qi::attr as follows, [...]

Thanks for the example, that's what I had tried at first, but I was
using attr() incorrectly.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>

------------------------------------------------------------------------------
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general