[Spirit & Karma] #19: Need to decide on a possible syntax for the use of qi::stream

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

[Spirit & Karma] #19: Need to decide on a possible syntax for the use of qi::stream

Hartmut Kaiser
#19: Need to decide on a possible syntax for the use of qi::stream
------------------------+---------------------------------------------------
 Reporter:  hkaiser     |       Owner:  hkaiser  
     Type:  to discuss  |      Status:  new      
 Priority:  major       |   Milestone:  Spirit V2
Component:  Spirit      |     Version:  Spirit V2
 Keywords:              |  
------------------------+---------------------------------------------------
 Currently in Karma we have the `stream` primitive implemented as a
 placeholder usable in the output grammar to output the corresponding data
 using the native or specialized `operator<<()` for this data.

 I.e.

 {{{
     // output a vector:
     std::vector<int> v;
     generate(sink, *stream, v);

     // output another vector:
     std::vector<double> v1;
     generate(sink, *stream, v1);

     // output a list:
     std::list<my_data> l;
     generate(sink, *stream, l);
 }}}

 all use the same output grammar regardless of the data type to generate
 output from. This works because we use the `operator<<()` for the embedded
 datatypes (int, double and my_data) and we always know the datatype of the
 instances to generate output from.

 '''Now the problem''': it would be nice to have  a similar functionality
 available in Qi as well, i.e. using something like the `stream`
 placeholder to __input__ from the iterators using the `operator>>()`
 defined for the data to parse. For this to work we need to know the
 __datatype__ of the data we want to input. If the attribute is provided
 explicitly, this datatype is deducible. The following:

 {{{
     std::vector<int> v;
     parse(it, last, *stream, v);
 }}}

 just works because we know, we have to extract `int`'s from the input
 stream. More problematic is the following:

 {{{
     std::vector<int> v;
     parse(it, last, (*stream)[ref(v) = _1]);
 }}}

 which should work as well, but does not. Here we need to explicitly
 provide the expected type of the data items to extract from the input.

 '''The question is''': what syntax is best for this?

--
Ticket URL: <http://fortytwo.cct.lsu.edu:8000/SpiritKarma/ticket/19>
Spirit &amp; Karma <http://spirit.sourceforge.net>
Development of the Boost::Spirit V2 libraries
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [Spirit & Karma] #19: Need to decide on a possible syntax for the use of qi::stream

Hartmut Kaiser
#19: Need to decide on a possible syntax for the use of qi::stream
-------------------------+--------------------------------------------------
  Reporter:  hkaiser     |       Owner:  hkaiser  
      Type:  to discuss  |      Status:  closed  
  Priority:  major       |   Milestone:  Spirit V2
 Component:  Spirit      |     Version:  Spirit V2
Resolution:  fixed       |    Keywords:          
-------------------------+--------------------------------------------------
Changes (by hkaiser):

  * status:  new => closed
  * resolution:  => fixed

Comment:

 Joel and I had a lengthy discussion on that during BoostCon in Aspen and
 we decided to go for:

  * '''Karma''': we can use always use stream directly, since we always
 know the required type of the parameter
  * '''Qi''': when using with a directly passed attribute, stream works as
 is, when using with a attached semantic action, or just as a plain parser,
 we will use type_stream<T>, where T is the type to use when it comes to
 interpreting the input stream.

 In fact this is implemented in r558 with some subsequent fixes for gcc in
 r561.

--
Ticket URL: <http://fortytwo.cct.lsu.edu:8000/SpiritKarma/ticket/19#comment:1>
Spirit &amp; Karma <http://spirit.sourceforge.net>
Development of the Boost::Spirit V2 libraries
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel