[Boost-bugs] [Boost C++ Libraries] #12085: (a - b) === (!b >> a) does not hold in X3

Subject: [Boost-bugs] [Boost C++ Libraries] #12085: (a - b) === (!b >> a) does not hold in X3
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-03-22 07:53:21


#12085: (a - b) === (!b >> a) does not hold in X3
----------------------------------+---------------------
 Reporter: mikhail.strelnikov@… | Owner: djowel
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: spirit
  Version: Boost 1.61.0 | Severity: Problem
 Keywords: |
----------------------------------+---------------------
 Following program checks that two grammars (GRAMMAR1 and GRAMMAR2) are
 giving the same result for x3 and qi. They don't.

 GRAMMAR1 is (!b >> a), GRAMMAR2 is (a - b).

 When x3 is used (USE_X3==1) output is:

 1 d[[BR]]
 1 abcd[[BR]]


 When qi is used (USE_X3==0) output is:

 1 abcd[[BR]]
 1 abcd[[BR]]

 {{{
 #define USE_X3 1

 #if USE_X3 == 1
 #include <boost/spirit/home/x3.hpp>
 #else
 #include <boost/spirit/include/qi.hpp>
 #endif

 #include <iostream>
 #include <string>
 #include <vector>

 #define GRAMMAR1 !lexeme[keywords >> !(alnum | '_')] >> lexeme[(alpha |
 '_') >> *(alnum | '_')]
 #define GRAMMAR2 lexeme[(alpha | '_') >> *(alnum | '_')] - lexeme[keywords
>> !(alnum | '_')]

 int main()
 {
     std::string str = "abcd";

     auto end = str.end();
 #if USE_X3 == 1
     {
         using namespace boost::spirit::x3;
         symbols<> keywords({"k1", "k2", "k3"});

         {
             std::string v;
             auto begin = str.begin();
             bool full = boost::spirit::x3::parse(begin, end, GRAMMAR1, v)
 && begin == end;
             std::cout << full << " " << v << std::endl;
         }

         {
             std::string v;
             auto begin = str.begin();
             bool full = boost::spirit::x3::parse(begin, end, GRAMMAR2, v)
 && begin == end;
             std::cout << full << " " << v << std::endl;
         }
     }
 #else
     {
         using namespace boost::spirit::qi;
         symbols<> keywords; keywords = "k1", "k2", "k3";

         {
             std::string v;
             auto begin = str.begin();
             bool full = boost::spirit::qi::parse(begin, end, GRAMMAR1, v)
 && begin == end;
             std::cout << full << " " << v << std::endl;
         }

         {
             std::string v;
             auto begin = str.begin();
             bool full = boost::spirit::qi::parse(begin, end, GRAMMAR2, v)
 && begin == end;
             std::cout << full << " " << v << std::endl;
         }
     }
 #endif
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12085>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC