Hello everyone
Is it expected behavior, that code like this:
typedef uint_parser<double> uint_double_parser;
my_rule_t max_59_uint
= max_limit_d<double>(59.)
[
uint_double_parser()
] [max_59_uint.value = arg1]
;
causes assertion on input like "" or "aaa"?
Investigating problem, I found that in function
parse(ScannerT const& scan) const
hit.value() used directly, without checking if it valid (see original
code). If it is expected use, then what function
parser_result::has_valid_attribute() for ?
I've modified function
parse(ScannerT const& scan) const
(see my code)
and everything works fine, but I'm not sure if such modification is
"legitimate" and does not break anything else.
original code
(\boost\spirit\core\composite\directives.hpp):
///////////////////////////////////////////////////////////////////////////
//
// max_bounded class
//
///////////////////////////////////////////////////////////////////////////
template <typename BoundsT>
struct max_bounded_gen;
template
struct max_bounded
: public unary > >
{
typedef max_bounded self_t;
typedef unary_parser_category parser_category_t;
typedef max_bounded_gen<BoundsT> parser_generator_t;
typedef unary > base_t;
template <typename ScannerT>
struct result
{
typedef typename parser_result::type type;
};
max_bounded(ParserT const& p, BoundsT const& max__)
: base_t(p)
, max_(max__) {}
template <typename ScannerT>
typename parser_result::type
parse(ScannerT const& scan) const
{
typedef typename parser_result::type result_t;
result_t hit = this->subject().parse(scan);
if (hit.value() > max_)
// ^^^^^^^^^^^ no check for validity
return scan.no_match();
return hit;
}
BoundsT max_;
};
my code:
///////////////////////////////////////////////////////////////////////////
//
// max_bounded class
//
///////////////////////////////////////////////////////////////////////////
template <typename BoundsT>
struct max_bounded_gen;
template
struct max_bounded
: public unary > >
{
typedef max_bounded self_t;
typedef unary_parser_category parser_category_t;
typedef max_bounded_gen<BoundsT> parser_generator_t;
typedef unary > base_t;
template <typename ScannerT>
struct result
{
typedef typename parser_result::type type;
};
max_bounded(ParserT const& p, BoundsT const& max__)
: base_t(p)
, max_(max__) {}
template <typename ScannerT>
typename parser_result::type
parse(ScannerT const& scan) const
{
typedef typename parser_result::type result_t;
result_t hit = this->subject().parse(scan);
if (!hit.has_valid_attribute() || hit.value() > max_)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ is this right ?
return scan.no_match();
return hit;
}
BoundsT max_;
};
--
Best regards,
Vladimir mailto:vkrasovsky@yandex.ru