Boost logo

Boost Users :

Subject: [Boost-users] [phoenix][spirit] catch_all issues in V3
From: Igor R (boost.lists_at_[hidden])
Date: 2013-12-03 11:03:36


Hello,

The following code doesn't compile (MSVC10, Boost 1.55). If I modify
"catch_all" line like this:
query = id[phx::try_[qi::_val = phx::bind(&string2test,
qi::_1)].catch_all [ qi::_pass = false ], qi::_val = qi::_val ];
...it compiles, but doesn't seem to invoke the semantic action in runtime.
It there a workaround that would both compile and work?

Thanks!

#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <string>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/phoenix/bind/bind_function.hpp>
#include <boost/phoenix/statement/try_catch.hpp>

namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;

struct test
{
};

test string2test(const std::string &str)
{
  if (str == "throw")
    throw "exception!";
  return test();
}

template <typename Iterator = std::string::const_iterator>
struct test_parser : qi::grammar<Iterator, test(), qi::blank_type>
{
  test_parser() : test_parser::base_type(query)
  {
    query = id[phx::try_[qi::_val = phx::bind(&string2test,
qi::_1)].catch_all [ qi::_pass = false ] ];
    id = qi::lexeme[*qi::char_("a-zA-Z_0-9")];
  }
  qi::rule<Iterator, test(), qi::blank_type> query;
  qi::rule<Iterator, std::string(), qi::blank_type> id;
};

int main()
{
  const std::string input = "qwerty";
  test_parser<> p;
  test output;
  bool ok = phrase_parse(input.begin(), input.end(), p, qi::blank, output);
}

//

1> boost\boost\proto\traits.hpp(297): error C2338: 0 == Expr::proto_arity_c
1> boost\boost\mpl\eval_if.hpp(63) : see reference to class template
instantiation 'boost::proto::result_of::value<Expr>' being compiled
 1> with
 1> [
 1> Expr=boost::phoenix::try_catch_actor<boost::proto::exprns_::basic_expr<boost::phoenix::tag::try_catch,boost::proto::argsns_::list2<boost::phoenix::try_catch_actor<boost::proto::exprns_::basic_expr<boost::phoenix::tag::try_catch,boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tagns_::tag::assign,boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::spirit::attribute<0>>,0>,boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::phoenix::detail::tag::function_eval,boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::phoenix::detail::function_ptr<1,test,test
(__cdecl *)(const std::string
&)>>,0>,boost::phoenix::actor<boost::spirit::argument<0>>>,2>>>,2>>>,1>>,boost::proto::exprns_::basic_expr<boost::phoenix::tag::catch_all,boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tagns_::tag::assign,boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<boost::phoenix::argument<3>>,0>,boost::phoenix::actor<boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<bool>,0>>>,2>>>,1>>,2>>
1> ]


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