Auto attributes propagation in directives with lazy arguments

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

Auto attributes propagation in directives with lazy arguments

Nikita Kniazev
I hit problem with attributes propagation when using semantic actions, even with using enforcing operator %=.
Following test case shows inconsistent in behavior of directives with lazy parameters vs normal.

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

namespace qi = boost::spirit::qi;

template <typename T>
void test(const T& rule)
{
  const std::string in = "123";
  std::vector<int> 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);

  std::cout << out.size() << std::endl;

  BOOST_ASSERT(r && iter == end);
}

int main()
{
    using qi::int_;
    using qi::_1;
    using boost::phoenix::val;
                                         //       Lazy  Semantic
    test(qi::repeat(1)[int_]);           // OK    No    No
    test(qi::repeat(1)[int_[_1]]);       // OK    No    Yes
    test(qi::repeat(val(1))[int_]);      // OK    Yes   No
    test(qi::repeat(val(1))[int_[_1]]);  // FAIL  Yes   Yes

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

I'm not sure, but as for me this is a bug (which interfere me at using my own custom directive).

------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Auto attributes propagation in directives with lazy arguments

Lee Clagett-2
On Fri, Feb 13, 2015 at 7:05 AM, Nikita Kniazev <[hidden email]> wrote:
I hit problem with attributes propagation when using semantic actions, even with using enforcing operator %=.
Following test case shows inconsistent in behavior of directives with lazy parameters vs normal.

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

namespace qi = boost::spirit::qi;

template <typename T>
void test(const T& rule)
{
  const std::string in = "123";
  std::vector<int> 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);

  std::cout << out.size() << std::endl;

  BOOST_ASSERT(r && iter == end);
}

int main()
{
    using qi::int_;
    using qi::_1;
    using boost::phoenix::val;
                                         //       Lazy  Semantic
    test(qi::repeat(1)[int_]);           // OK    No    No
    test(qi::repeat(1)[int_[_1]]);       // OK    No    Yes
    test(qi::repeat(val(1))[int_]);      // OK    Yes   No
    test(qi::repeat(val(1))[int_[_1]]);  // FAIL  Yes   Yes

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

I'm not sure, but as for me this is a bug (which interfere me at using my own custom directive).

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