Boost logo

Boost Users :

Subject: [Boost-users] Boost.Spirit Karma: debug() alters result
From: Matwey V. Kornilov (matwey.kornilov_at_[hidden])
Date: 2016-03-04 10:01:47


Hello,

I am using boost 1.58 and I see the following.

template <class Iterator>
struct test_generator:
        karma::grammar<Iterator, std::string()> {

        test_generator(): test_generator::base_type(start) {
                using karma::ascii::string;
                using boost::spirit::ascii::char_;
                using karma::lit;
                using karma::buffer;
                using karma::debug;

                value2 = +(~char_(' '));
                value1 = value2;
                value = lit('=') << value1;
                start = buffer[-value];
        }

        karma::rule<Iterator, std::string()> start;
        karma::rule<Iterator, std::string()> value;
        karma::rule<Iterator, std::string()> value1;
        karma::rule<Iterator, std::string()> value2;
};
template <class Iterator>
struct test_generator2:
        karma::grammar<Iterator, std::string()> {

        test_generator2(): test_generator2::base_type(start) {
                using karma::ascii::string;
                using boost::spirit::ascii::char_;
                using karma::lit;
                using karma::buffer;
                using karma::debug;

                value2 = +(~char_(' '));
                value1 = value2;
                value = lit('=') << value1;
                debug(value);
                start = buffer[-value];
        }

        karma::rule<Iterator, std::string()> start;
        karma::rule<Iterator, std::string()> value;
        karma::rule<Iterator, std::string()> value1;
        karma::rule<Iterator, std::string()> value2;
};

template<class It>
bool do_generate(It it, const std::string& x) {
        test_generator<It> g;
        return karma::generate(it, g, x);
}
template<class It>
bool do_generate2(It it, const std::string& x) {
        test_generator2<It> g;
        return karma::generate(it, g, x);
}

//...

        std::string x2,x3;
        do_generate(std::back_inserter(x2), std::string(""));
        do_generate2(std::back_inserter(x3), std::string(""));
        std::cerr << "|" << x2 << "|" << std::endl;
        std::cerr << "|" << x3 << "|" << std::endl;

//...

The code prints:

<unnamed-rule>
  <try>
    <attributes>[[]]</attributes>
  </try>
  <fail/>
</unnamed-rule>
|=|
||

I.e. introduction of debug() alters result of the generator. Could you
please explain me where I am wrong? I am stuck now.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net