I'm writing a boost::spirit::qi grammar for date parsing.
template < typename InputIterator >
struct date_rfc1123_grammar :
boost::spirit::qi::grammar< InputIterator, boost::gregorian::date()> {
typedef boost::gregorian::date value_type;
date_rfc1123_grammar() : date_rfc1123_grammar::base_type(date)
{
namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;
using qi::_pass;
using qi::_val;
using qi::_2;
using qi::_3;
using qi::_4;
_2digits = qi::uint_parser< std::uint32_t, 10, 2, 2 >();
_4digits = qi::uint_parser< std::uint32_t, 10, 4, 4 >();
date = (weekday >> ' ' >> _2digits >> ' ' >> month >> ' ' >> _4digits)
[
phx::try_[
_val = phx::construct< value_type >( _4, _3, _2 )
].catch_all[
_pass = false
]
];
}
boost::spirit::qi::rule< InputIterator, value_type()> date;
weekday_grammar weekday;
month_grammar month;
boost::spirit::qi::rule< InputIterator, std::int32_t() > _2digits;
boost::spirit::qi::rule< InputIterator, std::int32_t() > _4digits;
};
I rely upon the boost::gregorian::date
constructor for arguments checking and would like the parser to fail in case of an exception. But the boost::phoenix::try_[ ].catch_all[ ]
construct fails to compile with the following message:
/path_to_file/datetime_parse.hpp:102:8: required from ‘tip::http::grammar::parse::date_rfc1123_grammar<InputIterator>::date_rfc1123_grammar() [with InputIterator = boost::spirit::multi_pass<std::istreambuf_iterator<char, std::char_traits<char> > >]’
/path_to_file/grammar_parse_test.hpp:17:7: required from here
/usr/local/include/boost/proto/traits.hpp:341:13: error: static assertion failed: 0 == Expr::proto_arity_c
BOOST_STATIC_ASSERT(0 == Expr::proto_arity_c);
^
Without the try_.catch_all
construct the grammar compiles OK, but I would like the parser to catch the exception and set the _pass
flag to false to make the grammar to fail.
Aucun commentaire:
Enregistrer un commentaire