Re: Spirit-devel Digest, Vol 56, Issue 1

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Spirit-devel Digest, Vol 56, Issue 1

Nikita Kniazev
Reason of using [_1] is simplicity (I just want to enable semantic actions for showing bug while having minimal code). Replace _1 with whatever you want (_1 *= 2 for example), but it will not change type of underlying lazy parser attribute from unused_type (as semantic action disables attribute propagation for it). As for me all test cases should have same effect, but for now any directive with lazy arguments yields no result if semantic action presented.
Test case can be altered to show bug for any directive (if it uses use_lazy_directive enabler)

/******************************************************************************/
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/repository/include/qi_distinct.hpp>

namespace qi = boost::spirit::qi;

template <typename T>
void test(const T& rule)
{
  const std::string in = "str";
  boost::optional<std::string> out;

  std::string::const_iterator iter = in.begin();
  const std::string::const_iterator end = in.end();

  const bool r = qi::parse(iter, end, rule, out);
  BOOST_ASSERT(r && iter == end);

  std::cout << (out ? "OK" : "FAIL") << std::endl;
}

int main()
{
    using qi::_1;
    using boost::phoenix::val;
    using boost::spirit::repository::qi::distinct;
    using qi::alnum;
                                                        //       Lazy  Semantic
    test(distinct(alnum)     [qi::string("str")]);      // OK    No    No
    test(distinct(alnum)     [qi::string("str")[_1]]);  // OK    No    Yes
    test(distinct(val(alnum))[qi::string("str")]);      // OK    Yes   No
    test(distinct(val(alnum))[qi::string("str")[_1]]);  // FAIL  Yes   Yes

    return 0;
}
/******************************************************************************/

The expression int_[_1] creates an integer parser with an attached semantic
action that does nothing, so its not exactly clear to me what you are
trying to do. Did you mean to do a push_back(ref(vector), _1) or something?

Lee


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel