X3 problem

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

X3 problem

Mikael Asplund

Hi!

 

I really can't figure out what's wrong with this... Can anyone figure out what's wrong? Using boost 1.60.

 

It seem to be exactly as prescribed, and the error messages that X3 produce are less then helpful:

 

http://coliru.stacked-crooked.com/a/5c128d4f02379eb8

 

#include <iostream>

#include <string>

#include <vector>

#include <boost/spirit/home/x3.hpp>

#include <boost/optional.hpp>

#include <boost/fusion/include/adapt_struct.hpp>

 

using std::string;

using std::vector;

using std::pair;

 

namespace x3 = boost::spirit::x3;

 

int parse_input(vector<string> v);

 

int main(int argc, const char* argv[]) {

    if (argc > 1) {

      return parse_input(vector<string>(&argv[1], &argv[argc + !argc]));

    }

    return 1;

}

 

struct XXX {

  int a;

  boost::optional<pair<int, int>> b;

};

 

BOOST_FUSION_ADAPT_STRUCT(XXX, a, b)

 

int parse_input(vector<string> v) {

  std::stringstream ss;

  std::copy(v.begin(), v.end(), std::ostream_iterator<string>(ss, " "));

  string s = ss.str();

  auto iter = s.begin();

  auto end = s.end();

  XXX x;

  bool success = x3::phrase_parse(iter, end, x3::int_ >> -(x3::int_ >> x3::int_), x3::space, x);

  return !success;

}

 

 


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://makebettercode.com/inteldaal-eval
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3 problem

Joel de Guzman
On 08/03/2016 6:23 AM, Mikael Asplund wrote:

> Hi!
>
> I really can't figure out what's wrong with this... Can anyone figure out what's wrong?
> Using boost 1.60.
>
> It seem to be exactly as prescribed, and the error messages that X3 produce are less then
> helpful:
>
> http://coliru.stacked-crooked.com/a/5c128d4f02379eb8
>
[...]

Looks like a bug. I'll have to investigate deeper. For now, please use a separate
rule for the optional part.

Regards,
--
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://makebettercode.com/inteldaal-eval
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3 problem

Mikael Asplund
Hi!

Thanks for your answer! I made a new example with using a rule as you suggested, but that doesn't work either...

http://coliru.stacked-crooked.com/a/990cbbaf3551d072

( Doesn't work even if I make it non-optional:  http://coliru.stacked-crooked.com/a/8ded10bcf9d4db41 )

#include <iostream>
#include <string>
#include <vector>
#include <boost/spirit/home/x3.hpp>
#include <boost/optional.hpp>
#include <boost/fusion/include/adapt_struct.hpp>

using std::string;
using std::vector;
using std::pair;

namespace x3 = boost::spirit::x3;

int parse_input(vector<string> v);

int main(int argc, const char* argv[]) {
    if (argc > 1) {
      return parse_input(vector<string>(&argv[1], &argv[argc + !argc]));
    }
    return 1;
}

struct XXX {
  int a;
  boost::optional<pair<int, int>> b;
};

BOOST_FUSION_ADAPT_STRUCT(XXX, a, b)

class apair_class;
using apair_type = x3::rule<apair_class, std::pair<int, int>>;
const apair_type apair = "pair";
const auto apair_def = x3::int_ >> x3::int_;

int parse_input(vector<string> v) {
  std::stringstream ss;
  std::copy(v.begin(), v.end(), std::ostream_iterator<string>(ss, " "));
  string s = ss.str();
  auto iter = s.begin();
  auto end = s.end();
  XXX x;
  bool success = x3::phrase_parse(iter, end, x3::int_ >> -apair, x3::space, x);
  return !success;
}

BOOST_SPIRIT_DEFINE(apair)


-----Original Message-----
From: Joel de Guzman [mailto:[hidden email]]
Sent: Wednesday, March 9, 2016 00:47
To: [hidden email]
Subject: Re: [Spirit-general] X3 problem

On 08/03/2016 6:23 AM, Mikael Asplund wrote:

> Hi!
>
> I really can't figure out what's wrong with this... Can anyone figure out what's wrong?
> Using boost 1.60.
>
> It seem to be exactly as prescribed, and the error messages that X3
> produce are less then
> helpful:
>
> http://coliru.stacked-crooked.com/a/5c128d4f02379eb8
>
[...]

Looks like a bug. I'll have to investigate deeper. For now, please use a separate rule for the optional part.

Regards,
--
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://makebettercode.com/inteldaal-eval
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3 problem

Mike Gresens
Hi,

try to add an include:

#include <boost/fusion/include/std_pair.hpp>

Mike...
Reply | Threaded
Open this post in threaded view
|

Re: X3 problem

Mikael Asplund
Ah, that did indeed help! Thank you, Mike!

-----Original Message-----
From: Mike Gresens [mailto:[hidden email]]
Sent: Wednesday, March 9, 2016 12:52
To: [hidden email]
Subject: Re: [Spirit-general] X3 problem

Hi,

try to add an include:

#include <boost/fusion/include/std_pair.hpp>

Mike...



--
View this message in context: http://boost.2283326.n4.nabble.com/X3-problem-tp4684349p4684393.html
Sent from the spirit-general mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3 problem

Mikael Asplund
To be clear... adding the include helped when I had a special rule, but not in my original query:

http://coliru.stacked-crooked.com/a/190218125eefb34a

So it seems there is still a bug for Mr. Guzman to figure out :-)

Thanks again, both to Joel and Mike!

  /Mikael

-----Original Message-----
From: Mikael Asplund [mailto:[hidden email]]
Sent: Wednesday, March 9, 2016 13:42
To: Spirit General Mailing List <[hidden email]>
Subject: Re: [Spirit-general] X3 problem

Ah, that did indeed help! Thank you, Mike!

-----Original Message-----
From: Mike Gresens [mailto:[hidden email]]
Sent: Wednesday, March 9, 2016 12:52
To: [hidden email]
Subject: Re: [Spirit-general] X3 problem

Hi,

try to add an include:

#include <boost/fusion/include/std_pair.hpp>

Mike...



--
View this message in context: http://boost.2283326.n4.nabble.com/X3-problem-tp4684349p4684393.html
Sent from the spirit-general mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: X3 problem

sehe
On 09-03-16 13:48, Mikael Asplund wrote:
> So it seems there is still a bug for Mr. Guzman to figure out :-)
Or anyone else, of course!

------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785111&iu=/4140
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general