diff options
Diffstat (limited to 'boost/spirit/home/qi')
-rw-r--r-- | boost/spirit/home/qi/detail/alternative_function.hpp | 5 | ||||
-rw-r--r-- | boost/spirit/home/qi/detail/construct.hpp | 8 | ||||
-rw-r--r-- | boost/spirit/home/qi/detail/expectation_failure.hpp | 34 | ||||
-rw-r--r-- | boost/spirit/home/qi/directive.hpp | 1 | ||||
-rw-r--r-- | boost/spirit/home/qi/directive/expect.hpp | 113 | ||||
-rw-r--r-- | boost/spirit/home/qi/nonterminal/debug_handler.hpp | 2 | ||||
-rw-r--r-- | boost/spirit/home/qi/numeric/detail/numeric_utils.hpp | 10 | ||||
-rw-r--r-- | boost/spirit/home/qi/numeric/detail/real_impl.hpp | 13 | ||||
-rw-r--r-- | boost/spirit/home/qi/operator/expect.hpp | 32 |
9 files changed, 182 insertions, 36 deletions
diff --git a/boost/spirit/home/qi/detail/alternative_function.hpp b/boost/spirit/home/qi/detail/alternative_function.hpp index 0c400a90d4..88f6dad9a0 100644 --- a/boost/spirit/home/qi/detail/alternative_function.hpp +++ b/boost/spirit/home/qi/detail/alternative_function.hpp @@ -23,7 +23,7 @@ namespace boost { namespace spirit { namespace qi { namespace detail template <typename Variant, typename Expected> struct find_substitute { - // Get the typr from the variant that can be a substitute for Expected. + // Get the type from the variant that can be a substitute for Expected. // If none is found, just return Expected typedef Variant variant_type; @@ -138,8 +138,9 @@ namespace boost { namespace spirit { namespace qi { namespace detail template <typename Component> bool call(Component const& component, mpl::false_) const { + // fix for alternative.cpp test case, FHE 2016-07-28 return call_optional_or_variant( - component, spirit::traits::not_is_variant<Attribute, qi::domain>()); + component, mpl::not_<spirit::traits::not_is_optional<Attribute, qi::domain> >()); } template <typename Component> diff --git a/boost/spirit/home/qi/detail/construct.hpp b/boost/spirit/home/qi/detail/construct.hpp index 5d8122f6a5..829190e98e 100644 --- a/boost/spirit/home/qi/detail/construct.hpp +++ b/boost/spirit/home/qi/detail/construct.hpp @@ -143,20 +143,20 @@ namespace boost { namespace spirit { namespace traits #ifdef BOOST_HAS_LONG_LONG template <typename Iterator> - struct assign_to_attribute_from_iterators<long_long_type, Iterator> + struct assign_to_attribute_from_iterators<boost::long_long_type, Iterator> { static void - call(Iterator const& first, Iterator const& last, long_long_type& attr) + call(Iterator const& first, Iterator const& last, boost::long_long_type& attr) { Iterator first_ = first; qi::parse(first_, last, long_long_type(), attr); } }; template <typename Iterator> - struct assign_to_attribute_from_iterators<ulong_long_type, Iterator> + struct assign_to_attribute_from_iterators<boost::ulong_long_type, Iterator> { static void - call(Iterator const& first, Iterator const& last, ulong_long_type& attr) + call(Iterator const& first, Iterator const& last, boost::ulong_long_type& attr) { Iterator first_ = first; qi::parse(first_, last, ulong_long_type(), attr); diff --git a/boost/spirit/home/qi/detail/expectation_failure.hpp b/boost/spirit/home/qi/detail/expectation_failure.hpp new file mode 100644 index 0000000000..3571e2f3f1 --- /dev/null +++ b/boost/spirit/home/qi/detail/expectation_failure.hpp @@ -0,0 +1,34 @@ +/*============================================================================= +Copyright (c) 2001-2011 Joel de Guzman + +Distributed under the Boost Software License, Version 1.0. (See accompanying +file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#if !defined(SPIRIT_EXPECTATION_FAILURE_JULY_19_2016) +#define SPIRIT_EXPECTATION_FAILURE_JULY_19_2016 + +#if defined(_MSC_VER) +#pragma once +#endif + +#include <boost/spirit/home/support/info.hpp> + +#include <stdexcept> + +namespace boost { namespace spirit { namespace qi { + template <typename Iterator> + struct expectation_failure : std::runtime_error + { + expectation_failure(Iterator first_, Iterator last_, info const& what) + : std::runtime_error("boost::spirit::qi::expectation_failure") + , first(first_), last(last_), what_(what) + {} + ~expectation_failure() throw() {} + + Iterator first; + Iterator last; + info what_; + }; +}}} + +#endif diff --git a/boost/spirit/home/qi/directive.hpp b/boost/spirit/home/qi/directive.hpp index 6d97ce491d..71e56f4efd 100644 --- a/boost/spirit/home/qi/directive.hpp +++ b/boost/spirit/home/qi/directive.hpp @@ -22,5 +22,6 @@ #include <boost/spirit/home/qi/directive/raw.hpp> #include <boost/spirit/home/qi/directive/repeat.hpp> #include <boost/spirit/home/qi/directive/skip.hpp> +#include <boost/spirit/home/qi/directive/expect.hpp> #endif diff --git a/boost/spirit/home/qi/directive/expect.hpp b/boost/spirit/home/qi/directive/expect.hpp new file mode 100644 index 0000000000..7892c9c32d --- /dev/null +++ b/boost/spirit/home/qi/directive/expect.hpp @@ -0,0 +1,113 @@ +/*============================================================================= +Copyright (c) 2016 Frank Hein, maxence business consulting gmbh + +Distributed under the Boost Software License, Version 1.0. (See accompanying +file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ +#if !defined (SPIRIT_EXPECT_JULY_13_2016) +#define SPIRIT_EXPECT_JULY_13_2016 + +#if defined(_MSC_VER) +#pragma once +#endif + +#include <boost/spirit/home/qi/meta_compiler.hpp> +#include <boost/spirit/home/support/has_semantic_action.hpp> +#include <boost/spirit/home/qi/detail/attributes.hpp> +#include <boost/spirit/home/qi/detail/expectation_failure.hpp> +#include <boost/spirit/home/support/common_terminals.hpp> +#include <boost/spirit/home/support/handles_container.hpp> +#include <boost/spirit/home/support/unused.hpp> +#include <boost/spirit/home/support/info.hpp> + +namespace boost { namespace spirit { + /////////////////////////////////////////////////////////////////////////// + // Enablers + /////////////////////////////////////////////////////////////////////////// + template <> + struct use_directive<qi::domain, tag::expect> // enables expect[p] + : mpl::true_ {}; +}} + +namespace boost { namespace spirit { namespace qi { + +#ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS + using spirit::expect; +#endif + using spirit::expect_type; + + template <typename Subject> + struct expect_directive : unary_parser<expect_directive<Subject> > + { + typedef result_of::compile<domain, Subject> subject_type; + + template <typename Context, typename Iterator> + struct attribute + { + typedef traits::attribute_of<subject_type, Context, Iterator> + type; + }; + + expect_directive(Subject const& subject_) : subject(subject_) {} + + template <typename Iterator, typename Context + , typename Skipper, typename Attribute> + bool parse(Iterator& first, Iterator const& last + , Context& context, Skipper const& skipper + , Attribute& attr_) const + { + typedef expectation_failure<Iterator> exception; + + if (!subject.parse(first, last, context, skipper, attr_)) + { + boost::throw_exception( + exception(first, last, subject.what(context))); +#if defined(BOOST_NO_EXCEPTIONS) + return false; // for systems not supporting exceptions +#endif + } + return true; + } + + template <typename Context> + info what(Context& context) const + { + return info("expect", subject.what(context)); + } + + Subject subject; + }; + + /////////////////////////////////////////////////////////////////////////// + // Parser generators: make_xxx function (objects) + /////////////////////////////////////////////////////////////////////////// + template <typename Subject, typename Modifiers> + struct make_directive<tag::expect, Subject, Modifiers> + { + typedef expect_directive<Subject> result_type; + + result_type operator() + (unused_type, Subject const& subject, unused_type) const + { + return result_type(subject); + } + }; + +}}} + +namespace boost { namespace spirit { namespace traits { + /////////////////////////////////////////////////////////////////////////// + template <typename Subject> + struct has_semantic_action<qi::expect_directive<Subject> > + : unary_has_semantic_action<Subject> {}; + + /////////////////////////////////////////////////////////////////////////// + template <typename Subject, typename Attribute + , typename Context, typename Iterator> + struct handles_container< + qi::expect_directive<Subject>, Attribute, Context, Iterator + > + : unary_handles_container<Subject, Attribute, Context, Iterator> {}; +}}} + +#endif diff --git a/boost/spirit/home/qi/nonterminal/debug_handler.hpp b/boost/spirit/home/qi/nonterminal/debug_handler.hpp index 6a9f536699..b7bab6fe6d 100644 --- a/boost/spirit/home/qi/nonterminal/debug_handler.hpp +++ b/boost/spirit/home/qi/nonterminal/debug_handler.hpp @@ -14,7 +14,7 @@ #include <boost/spirit/home/support/unused.hpp> #include <boost/spirit/home/qi/nonterminal/rule.hpp> #include <boost/spirit/home/qi/nonterminal/debug_handler_state.hpp> -#include <boost/spirit/home/qi/operator/expect.hpp> +#include <boost/spirit/home/qi/detail/expectation_failure.hpp> #include <boost/function.hpp> #include <boost/fusion/include/at.hpp> #include <boost/fusion/include/vector.hpp> diff --git a/boost/spirit/home/qi/numeric/detail/numeric_utils.hpp b/boost/spirit/home/qi/numeric/detail/numeric_utils.hpp index ce9ad0f953..7f466ee65b 100644 --- a/boost/spirit/home/qi/numeric/detail/numeric_utils.hpp +++ b/boost/spirit/home/qi/numeric/detail/numeric_utils.hpp @@ -278,14 +278,20 @@ namespace boost { namespace spirit { namespace qi { namespace detail #define SPIRIT_NUMERIC_INNER_LOOP(z, x, data) \ if (!check_max_digits<MaxDigits>::call(count + leading_zeros) \ || it == last) \ + { \ break; \ + } \ ch = *it; \ if (!radix_check::is_valid(ch)) \ + { \ break; \ + } \ if (!extractor::call(ch, count, val)) \ { \ if (IgnoreOverflowDigits) \ + { \ first = it; \ + } \ traits::assign_to(val, attr); \ return IgnoreOverflowDigits; \ } \ @@ -386,10 +392,14 @@ namespace boost { namespace spirit { namespace qi { namespace detail /////////////////////////////////////////////////////////////////////////// #define SPIRIT_NUMERIC_INNER_LOOP(z, x, data) \ if (it == last) \ + { \ break; \ + } \ ch = *it; \ if (!radix_check::is_valid(ch)) \ + { \ break; \ + } \ if (!extractor::call(ch, count, val)) \ { \ traits::assign_to(val, attr); \ diff --git a/boost/spirit/home/qi/numeric/detail/real_impl.hpp b/boost/spirit/home/qi/numeric/detail/real_impl.hpp index 485df2727f..9aa5bb8bbd 100644 --- a/boost/spirit/home/qi/numeric/detail/real_impl.hpp +++ b/boost/spirit/home/qi/numeric/detail/real_impl.hpp @@ -32,7 +32,7 @@ namespace boost { namespace spirit { namespace traits { using spirit::traits::pow10; - + namespace detail { template <typename T, typename AccT> @@ -44,14 +44,14 @@ namespace boost { namespace spirit { namespace traits n = T((acc_n / comp) * comp); n += T(acc_n % comp); } - + template <typename T, typename AccT> void compensate_roundoff(T& n, AccT acc_n, mpl::false_) { // no need to compensate n = acc_n; } - + template <typename T, typename AccT> void compensate_roundoff(T& n, AccT acc_n) { @@ -66,7 +66,7 @@ namespace boost { namespace spirit { namespace traits if (exp >= 0) { int max_exp = std::numeric_limits<T>::max_exponent10; - + // return false if exp exceeds the max_exp // do this check only for primitive types! if (is_floating_point<T>() && exp > max_exp) @@ -80,7 +80,7 @@ namespace boost { namespace spirit { namespace traits int min_exp = std::numeric_limits<T>::min_exponent10; detail::compensate_roundoff(n, acc_n); n /= pow10<T>(-min_exp); - + // return false if (-exp + min_exp) exceeds the -min_exp // do this check only for primitive types! if (is_floating_point<T>() && (-exp + min_exp) > -min_exp) @@ -284,7 +284,8 @@ namespace boost { namespace spirit { namespace qi { namespace detail // If there is no number, disregard the exponent altogether. // by resetting 'first' prior to the exponent prefix (e|E) first = e_pos; - n = static_cast<T>(acc_n); + // Scale the number by -frac_digits. + traits::scale(-frac_digits, n, acc_n); } } else if (frac_digits) diff --git a/boost/spirit/home/qi/operator/expect.hpp b/boost/spirit/home/qi/operator/expect.hpp index ff279fd5d1..540372c33f 100644 --- a/boost/spirit/home/qi/operator/expect.hpp +++ b/boost/spirit/home/qi/operator/expect.hpp @@ -14,11 +14,11 @@ #include <boost/spirit/home/qi/operator/sequence_base.hpp> #include <boost/spirit/home/qi/detail/expect_function.hpp> +#include <boost/spirit/home/qi/detail/expectation_failure.hpp> #include <boost/spirit/home/qi/meta_compiler.hpp> #include <boost/spirit/home/support/has_semantic_action.hpp> #include <boost/spirit/home/support/handles_container.hpp> #include <boost/spirit/home/support/info.hpp> -#include <stdexcept> namespace boost { namespace spirit { @@ -36,27 +36,13 @@ namespace boost { namespace spirit namespace boost { namespace spirit { namespace qi { - template <typename Iterator> - struct expectation_failure : std::runtime_error - { - expectation_failure(Iterator first_, Iterator last_, info const& what) - : std::runtime_error("boost::spirit::qi::expectation_failure") - , first(first_), last(last_), what_(what) - {} - ~expectation_failure() throw() {} - - Iterator first; - Iterator last; - info what_; - }; - template <typename Elements> - struct expect : sequence_base<expect<Elements>, Elements> + struct expect_operator : sequence_base<expect_operator<Elements>, Elements> { - friend struct sequence_base<expect<Elements>, Elements>; + friend struct sequence_base<expect_operator<Elements>, Elements>; - expect(Elements const& elements) - : sequence_base<expect<Elements>, Elements>(elements) {} + expect_operator(Elements const& elements) + : sequence_base<expect_operator<Elements>, Elements>(elements) {} private: @@ -73,7 +59,7 @@ namespace boost { namespace spirit { namespace qi (first, last, context, skipper); } - std::string id() const { return "expect"; } + std::string id() const { return "expect_operator"; } }; /////////////////////////////////////////////////////////////////////////// @@ -81,7 +67,7 @@ namespace boost { namespace spirit { namespace qi /////////////////////////////////////////////////////////////////////////// template <typename Elements, typename Modifiers> struct make_composite<proto::tag::greater, Elements, Modifiers> - : make_nary_composite<Elements, expect> + : make_nary_composite<Elements, expect_operator> {}; }}} @@ -89,13 +75,13 @@ namespace boost { namespace spirit { namespace traits { /////////////////////////////////////////////////////////////////////////// template <typename Elements> - struct has_semantic_action<qi::expect<Elements> > + struct has_semantic_action<qi::expect_operator<Elements> > : nary_has_semantic_action<Elements> {}; /////////////////////////////////////////////////////////////////////////// template <typename Elements, typename Attribute, typename Context , typename Iterator> - struct handles_container<qi::expect<Elements>, Attribute, Context + struct handles_container<qi::expect_operator<Elements>, Attribute, Context , Iterator> : mpl::true_ {}; }}} |