diff options
Diffstat (limited to 'boost/spirit/home/x3/support')
40 files changed, 510 insertions, 421 deletions
diff --git a/boost/spirit/home/x3/support/ast/variant.hpp b/boost/spirit/home/x3/support/ast/variant.hpp index cf626e88be..52e565d1d4 100644 --- a/boost/spirit/home/x3/support/ast/variant.hpp +++ b/boost/spirit/home/x3/support/ast/variant.hpp @@ -7,13 +7,10 @@ #if !defined(BOOST_SPIRIT_X3_VARIANT_AUGUST_6_2011_0859AM) #define BOOST_SPIRIT_X3_VARIANT_AUGUST_6_2011_0859AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/variant.hpp> #include <boost/mpl/list.hpp> #include <boost/type_traits/is_base_of.hpp> +#include <type_traits> /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace x3 @@ -126,17 +123,25 @@ namespace boost { namespace spirit { namespace x3 // tell spirit that this is an adapted variant struct adapted_variant_tag; - typedef boost::variant<Types...> variant_type; - typedef mpl::list<typename detail::remove_forward<Types>::type...> types; - typedef variant<Types...> base_type; + using variant_type = boost::variant<Types...>; + using types = mpl::list<typename detail::remove_forward<Types>::type...>; + using base_type = variant; // The current instantiation + + template<typename T> + using non_self_t // used only for SFINAE checks below + = std::enable_if_t<!(std::is_base_of<base_type + ,std::remove_reference_t<T> + > + ::value) + >; variant() : var() {} - template <typename T, typename disable_if<is_base_of<base_type, T>>::type> + template <typename T, class = non_self_t<T>> explicit variant(T const& rhs) : var(rhs) {} - template <typename T, typename disable_if<is_base_of<base_type, T>>::type> + template <typename T, class = non_self_t<T>> explicit variant(T&& rhs) : var(std::forward<T>(rhs)) {} @@ -161,16 +166,14 @@ namespace boost { namespace spirit { namespace x3 return *this; } - template <typename T> - //typename disable_if<is_base_of<base_type, T>, variant&>::type + template <typename T, class = non_self_t<T>> variant& operator=(T const& rhs) { var = rhs; return *this; } - template <typename T> - //typename disable_if<is_base_of<base_type, T>, variant&>::type + template <typename T, class = non_self_t<T>> variant& operator=(T&& rhs) { var = std::forward<T>(rhs); diff --git a/boost/spirit/home/x3/support/context.hpp b/boost/spirit/home/x3/support/context.hpp index 93bcb24070..592ce3ff76 100644 --- a/boost/spirit/home/x3/support/context.hpp +++ b/boost/spirit/home/x3/support/context.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_CONTEXT_JAN_4_2012_1215PM) #define BOOST_SPIRIT_X3_CONTEXT_JAN_4_2012_1215PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/unused.hpp> #include <boost/mpl/identity.hpp> @@ -23,26 +19,13 @@ namespace boost { namespace spirit { namespace x3 context(T& val, Next const& next) : val(val), next(next) {} - template <typename ID_, typename Unused = void> - struct get_result - { - typedef typename Next::template get_result<ID_>::type type; - }; - - template <typename Unused> - struct get_result<mpl::identity<ID>, Unused> - { - typedef T& type; - }; - T& get(mpl::identity<ID>) const { return val; } template <typename ID_> - typename Next::template get_result<ID_>::type - get(ID_ id) const + decltype(auto) get(ID_ id) const { return next.get(id); } @@ -60,37 +43,22 @@ namespace boost { namespace spirit { namespace x3 context(T& val, unused_type) : val(val) {} - template <typename ID_, typename Unused = void> - struct get_result - { - typedef unused_type type; - }; - - template <typename Unused> - struct get_result<mpl::identity<ID>, Unused> - { - typedef T& type; - }; - T& get(mpl::identity<ID>) const { return val; } template <typename ID_> - unused_type - get(ID_) const + unused_type get(ID_) const { - return unused; + return {}; } T& val; }; template <typename Tag, typename Context> - inline auto - get(Context const& context) - -> decltype(context.get(mpl::identity<Tag>())) + inline decltype(auto) get(Context const& context) { return context.get(mpl::identity<Tag>()); } @@ -98,13 +66,13 @@ namespace boost { namespace spirit { namespace x3 template <typename ID, typename T, typename Next> inline context<ID, T, Next> make_context(T& val, Next const& next) { - return context<ID, T, Next>(val, next); + return { val, next }; } template <typename ID, typename T> inline context<ID, T> make_context(T& val) { - return context<ID, T>(val); + return { val }; } namespace detail @@ -120,7 +88,7 @@ namespace boost { namespace spirit { namespace x3 inline context<ID, T, Next> make_unique_context(T& val, Next const& next, unused_type) { - return context<ID, T, Next>(val, next); + return { val, next }; } } diff --git a/boost/spirit/home/x3/support/no_case.hpp b/boost/spirit/home/x3/support/no_case.hpp new file mode 100644 index 0000000000..2ad3f709c6 --- /dev/null +++ b/boost/spirit/home/x3/support/no_case.hpp @@ -0,0 +1,102 @@ +/*============================================================================= + Copyright (c) 2001-2014 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(BOOST_SPIRIT_X3_SUPPORT_NO_CASE_SEPT_24_2014_1125PM) +#define BOOST_SPIRIT_X3_SUPPORT_NO_CASE_SEPT_24_2014_1125PM + +#include <boost/spirit/home/x3/support/unused.hpp> +#include <boost/spirit/home/x3/support/context.hpp> +#include <boost/spirit/home/x3/char/char_class_tags.hpp> + +namespace boost { namespace spirit { namespace x3 +{ + struct no_case_tag {}; + + template <typename Encoding> + struct case_compare + { + template < template <typename> class basic_charset> + typename Encoding::char_type + in_set( typename Encoding::char_type const ch + , basic_charset<typename Encoding::char_type> const &set) + { + return set.test(ch); + } + + int32_t operator()( + typename Encoding::char_type const lc + , typename Encoding::char_type const rc) const + { + return lc - rc; + } + + + template <typename CharClassTag> + CharClassTag get_char_class_tag(CharClassTag tag) const + { + return tag; + } + }; + + template <typename Encoding> + struct no_case_compare + { + template < template <typename> class basic_charset> + typename Encoding::char_type + in_set( typename Encoding::char_type const ch + , basic_charset<typename Encoding::char_type> const &set) + { + return set.test(ch) + || set.test(Encoding::islower(ch) ? Encoding::toupper(ch) : Encoding::tolower(ch)); + } + + int32_t operator()( + typename Encoding::char_type const lc + , typename Encoding::char_type const rc) const + { + return Encoding::islower(rc) ? Encoding::tolower(lc) - rc : Encoding::toupper(lc) - rc; + } + + template <typename CharClassTag> + CharClassTag get_char_class_tag(CharClassTag tag) const + { + return tag; + } + + alpha_tag get_char_class_tag(lower_tag ) const + { + return {}; + } + + alpha_tag get_char_class_tag(upper_tag ) const + { + return {}; + } + + }; + + template <typename Encoding> + case_compare<Encoding> get_case_compare_impl(unused_type const&) + { + return {}; + } + + template <typename Encoding> + no_case_compare<Encoding> get_case_compare_impl(no_case_tag const&) + { + return {}; + } + + template <typename Encoding, typename Context> + inline decltype(auto) get_case_compare(Context const& context) + { + return get_case_compare_impl<Encoding>(x3::get<no_case_tag>(context)); + } + auto const no_case_compare_ = no_case_tag{}; + +}}} + +#endif diff --git a/boost/spirit/home/x3/support/numeric_utils/detail/extract_int.hpp b/boost/spirit/home/x3/support/numeric_utils/detail/extract_int.hpp index 73770c87d0..4ebd66f182 100644 --- a/boost/spirit/home/x3/support/numeric_utils/detail/extract_int.hpp +++ b/boost/spirit/home/x3/support/numeric_utils/detail/extract_int.hpp @@ -11,10 +11,6 @@ #if !defined(BOOST_SPIRIT_X3_DETAIL_EXTRACT_INT_APRIL_17_2006_0816AM) #define BOOST_SPIRIT_X3_DETAIL_EXTRACT_INT_APRIL_17_2006_0816AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/unused.hpp> #include <boost/spirit/home/x3/support/traits/attribute_type.hpp> #include <boost/spirit/home/x3/support/traits/move_to.hpp> diff --git a/boost/spirit/home/x3/support/numeric_utils/extract_int.hpp b/boost/spirit/home/x3/support/numeric_utils/extract_int.hpp index aa80cdd6ea..621275f4c8 100644 --- a/boost/spirit/home/x3/support/numeric_utils/extract_int.hpp +++ b/boost/spirit/home/x3/support/numeric_utils/extract_int.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_EXTRACT_INT_APRIL_17_2006_0830AM) #define BOOST_SPIRIT_X3_EXTRACT_INT_APRIL_17_2006_0830AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/traits/move_to.hpp> #include <boost/spirit/home/x3/support/numeric_utils/detail/extract_int.hpp> #include <boost/assert.hpp> diff --git a/boost/spirit/home/x3/support/numeric_utils/extract_real.hpp b/boost/spirit/home/x3/support/numeric_utils/extract_real.hpp index fb30f02306..ea1f0df949 100644 --- a/boost/spirit/home/x3/support/numeric_utils/extract_real.hpp +++ b/boost/spirit/home/x3/support/numeric_utils/extract_real.hpp @@ -9,10 +9,6 @@ #if !defined(SPIRIT_EXTRACT_REAL_APRIL_18_2006_0901AM) #define SPIRIT_EXTRACT_REAL_APRIL_18_2006_0901AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <cmath> #include <boost/limits.hpp> #include <boost/type_traits/is_same.hpp> diff --git a/boost/spirit/home/x3/support/numeric_utils/pow10.hpp b/boost/spirit/home/x3/support/numeric_utils/pow10.hpp index f51d29fba8..1ff3a077a1 100644 --- a/boost/spirit/home/x3/support/numeric_utils/pow10.hpp +++ b/boost/spirit/home/x3/support/numeric_utils/pow10.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_POW10_DECEMBER_26_2008_1118AM) #define BOOST_SPIRIT_X3_POW10_DECEMBER_26_2008_1118AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/config/no_tr1/cmath.hpp> #include <boost/limits.hpp> #include <boost/spirit/home/x3/support/unused.hpp> diff --git a/boost/spirit/home/x3/support/numeric_utils/sign.hpp b/boost/spirit/home/x3/support/numeric_utils/sign.hpp index fe2feceeed..2ee4142de6 100644 --- a/boost/spirit/home/x3/support/numeric_utils/sign.hpp +++ b/boost/spirit/home/x3/support/numeric_utils/sign.hpp @@ -9,10 +9,6 @@ #if !defined(SPIRIT_SIGN_MAR_11_2009_0734PM) #define SPIRIT_SIGN_MAR_11_2009_0734PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/config/no_tr1/cmath.hpp> #include <boost/math/special_functions/fpclassify.hpp> #include <boost/math/special_functions/sign.hpp> diff --git a/boost/spirit/home/x3/support/subcontext.hpp b/boost/spirit/home/x3/support/subcontext.hpp index 7614fcbcae..d4c60d084b 100644 --- a/boost/spirit/home/x3/support/subcontext.hpp +++ b/boost/spirit/home/x3/support/subcontext.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_SUBCONTEXT_APR_15_2013_0840AM) #define BOOST_SPIRIT_X3_SUBCONTEXT_APR_15_2013_0840AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/fusion/support/pair.hpp> #include <boost/spirit/home/x3/support/context.hpp> #include <boost/spirit/home/x3/support/unused.hpp> @@ -29,12 +25,6 @@ namespace boost { namespace spirit { namespace x3 subcontext(Context const& /*context*/) {} - template <typename ID_, typename Unused = void> - struct get_result - { - typedef unused_type type; - }; - template <typename ID_> unused_type get(ID_) const diff --git a/boost/spirit/home/x3/support/traits/attribute_category.hpp b/boost/spirit/home/x3/support/traits/attribute_category.hpp index a003327de2..53e806c613 100644 --- a/boost/spirit/home/x3/support/traits/attribute_category.hpp +++ b/boost/spirit/home/x3/support/traits/attribute_category.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_ATTRIBUTE_CATEGORY_JAN_4_2012_1150AM) #define BOOST_SPIRIT_X3_ATTRIBUTE_CATEGORY_JAN_4_2012_1150AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/mpl/identity.hpp> #include <boost/mpl/logical.hpp> #include <boost/mpl/eval_if.hpp> diff --git a/boost/spirit/home/x3/support/traits/attribute_of.hpp b/boost/spirit/home/x3/support/traits/attribute_of.hpp index 71f70b0273..93ee79b57b 100644 --- a/boost/spirit/home/x3/support/traits/attribute_of.hpp +++ b/boost/spirit/home/x3/support/traits/attribute_of.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_ATTRIBUTE_OF_JAN_7_2012_0914AM) #define BOOST_SPIRIT_X3_ATTRIBUTE_OF_JAN_7_2012_0914AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/utility/sfinae.hpp> #include <boost/mpl/identity.hpp> #include <boost/utility/enable_if.hpp> diff --git a/boost/spirit/home/x3/support/traits/attribute_type.hpp b/boost/spirit/home/x3/support/traits/attribute_type.hpp index 55e788b41c..f1b8d871a9 100644 --- a/boost/spirit/home/x3/support/traits/attribute_type.hpp +++ b/boost/spirit/home/x3/support/traits/attribute_type.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_ATTRIBUTE_TYPE_JAN_5_2012_0358PM) #define BOOST_SPIRIT_X3_ATTRIBUTE_TYPE_JAN_5_2012_0358PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/mpl/identity.hpp> namespace boost { namespace spirit { namespace x3 { namespace traits diff --git a/boost/spirit/home/x3/support/traits/container_traits.hpp b/boost/spirit/home/x3/support/traits/container_traits.hpp index c382b7bfaa..ed9213b68c 100644 --- a/boost/spirit/home/x3/support/traits/container_traits.hpp +++ b/boost/spirit/home/x3/support/traits/container_traits.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_CONTAINER_FEBRUARY_06_2007_1001AM) #define BOOST_SPIRIT_X3_CONTAINER_FEBRUARY_06_2007_1001AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/fusion/support/category_of.hpp> #include <boost/spirit/home/x3/support/unused.hpp> #include <boost/detail/iterator.hpp> @@ -20,8 +16,12 @@ #include <boost/mpl/has_xxx.hpp> #include <boost/mpl/bool.hpp> #include <boost/mpl/identity.hpp> + #include <vector> +#include <map> #include <string> +#include <iterator> +#include <algorithm> namespace boost { namespace spirit { namespace x3 { namespace traits { @@ -112,10 +112,22 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename Container, typename Enable = void> struct push_back_container { + template <typename Key, typename Value, typename Compare, typename Allocator, typename T> + static void push_back(std::map<Key, Value, Compare, Allocator>& c, T&& val) + { + c.insert(std::move(val)); + } + + template <typename Container_, typename T> + static void push_back(Container_& c, T&& val) + { + c.push_back(std::move(val)); + } + template <typename T> static bool call(Container& c, T&& val) { - c.insert(c.end(), std::move(val)); + push_back(c, std::move(val)); return true; } }; @@ -154,17 +166,23 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename Container_> static void reserve(Container_& c, std::size_t size) {} - template <typename T> - static void reserve(std::vector<T>& c, std::size_t size) + template <typename T, typename Allocator> + static void reserve(std::vector<T, Allocator>& c, std::size_t size) { c.reserve(size); } + + template <typename Container_, typename Iterator> + static void insert(Container_& c, Iterator first, Iterator last) + { + std::copy(first, last, std::inserter(c, c.end())); + } template <typename Iterator> static bool call(Container& c, Iterator first, Iterator last) { reserve(c, c.size() + std::distance(first, last)); - c.insert(c.end(), first, last); + insert(c, first, last); return true; } }; diff --git a/boost/spirit/home/x3/support/traits/handles_container.hpp b/boost/spirit/home/x3/support/traits/handles_container.hpp index 3fe05aef87..ad0d1f19ea 100644 --- a/boost/spirit/home/x3/support/traits/handles_container.hpp +++ b/boost/spirit/home/x3/support/traits/handles_container.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_HANDLES_CONTAINER_DEC_18_2010_0920AM) #define BOOST_SPIRIT_X3_HANDLES_CONTAINER_DEC_18_2010_0920AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/mpl/bool.hpp> namespace boost { namespace spirit { namespace x3 { namespace traits diff --git a/boost/spirit/home/x3/support/traits/has_attribute.hpp b/boost/spirit/home/x3/support/traits/has_attribute.hpp index c8b1f8a347..cf4ab00801 100644 --- a/boost/spirit/home/x3/support/traits/has_attribute.hpp +++ b/boost/spirit/home/x3/support/traits/has_attribute.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_HAS_ATTRIBUTE_JUN_6_2012_1714PM) #define BOOST_SPIRIT_X3_HAS_ATTRIBUTE_JUN_6_2012_1714PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/traits/attribute_of.hpp> #include <boost/spirit/home/x3/support/utility/sfinae.hpp> #include <boost/mpl/bool.hpp> diff --git a/boost/spirit/home/x3/support/traits/is_parser.hpp b/boost/spirit/home/x3/support/traits/is_parser.hpp index cfbe8f74b4..a65d984584 100644 --- a/boost/spirit/home/x3/support/traits/is_parser.hpp +++ b/boost/spirit/home/x3/support/traits/is_parser.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_IS_PARSER_MAY_20_2013_0235PM) #define BOOST_SPIRIT_X3_IS_PARSER_MAY_20_2013_0235PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/mpl/bool.hpp> #include <boost/spirit/home/x3/core/parser.hpp> #include <boost/spirit/home/x3/support/utility/sfinae.hpp> diff --git a/boost/spirit/home/x3/support/traits/is_substitute.hpp b/boost/spirit/home/x3/support/traits/is_substitute.hpp index 9e023371ce..ef1c472c7f 100644 --- a/boost/spirit/home/x3/support/traits/is_substitute.hpp +++ b/boost/spirit/home/x3/support/traits/is_substitute.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_IS_SUBSTITUTE_JAN_9_2012_1049PM) #define BOOST_SPIRIT_X3_IS_SUBSTITUTE_JAN_9_2012_1049PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/traits/container_traits.hpp> #include <boost/fusion/include/is_sequence.hpp> #include <boost/fusion/include/map.hpp> diff --git a/boost/spirit/home/x3/support/traits/is_variant.hpp b/boost/spirit/home/x3/support/traits/is_variant.hpp index 829a673c3f..a936044a81 100644 --- a/boost/spirit/home/x3/support/traits/is_variant.hpp +++ b/boost/spirit/home/x3/support/traits/is_variant.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_IS_VARIANT_JAN_10_2012_0823AM) #define BOOST_SPIRIT_X3_IS_VARIANT_JAN_10_2012_0823AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/variant.hpp> #include <boost/mpl/has_xxx.hpp> #include <boost/mpl/bool.hpp> diff --git a/boost/spirit/home/x3/support/traits/make_attribute.hpp b/boost/spirit/home/x3/support/traits/make_attribute.hpp index cf3baeedaf..9465228c1d 100644 --- a/boost/spirit/home/x3/support/traits/make_attribute.hpp +++ b/boost/spirit/home/x3/support/traits/make_attribute.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_MAKE_ATTRIBUTE_JAN_8_2012_0721PM) #define BOOST_SPIRIT_X3_MAKE_ATTRIBUTE_JAN_8_2012_0721PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/mpl/if.hpp> #include <boost/type_traits/remove_const.hpp> #include <boost/type_traits/add_reference.hpp> diff --git a/boost/spirit/home/x3/support/traits/move_to.hpp b/boost/spirit/home/x3/support/traits/move_to.hpp index ecd7c6f202..fd3d59d7e2 100644 --- a/boost/spirit/home/x3/support/traits/move_to.hpp +++ b/boost/spirit/home/x3/support/traits/move_to.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_MOVE_TO_JAN_17_2013_0859PM) #define BOOST_SPIRIT_X3_MOVE_TO_JAN_17_2013_0859PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/traits/attribute_category.hpp> #include <boost/spirit/home/x3/support/traits/tuple_traits.hpp> #include <boost/spirit/home/x3/support/traits/variant_has_substitute.hpp> @@ -181,14 +177,14 @@ namespace boost { namespace spirit { namespace x3 { namespace traits template <typename T> inline void move_to(T& src, T& dest) { - if (&src != &dest) + if (boost::addressof(src) != boost::addressof(dest)) dest = std::move(src); } template <typename T> inline void move_to(T const& src, T& dest) { - if (&src != &dest) + if (boost::addressof(src) != boost::addressof(dest)) dest = std::move(src); } diff --git a/boost/spirit/home/x3/support/traits/numeric_traits.hpp b/boost/spirit/home/x3/support/traits/numeric_traits.hpp index 3cdbdaec63..9f455cc627 100644 --- a/boost/spirit/home/x3/support/traits/numeric_traits.hpp +++ b/boost/spirit/home/x3/support/traits/numeric_traits.hpp @@ -7,10 +7,6 @@ #if !defined(BOOST_SPIRIT_X3_NUMERIC_TRAITS_JAN_07_2011_0722AM) #define BOOST_SPIRIT_X3_NUMERIC_TRAITS_JAN_07_2011_0722AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/config.hpp> #include <boost/integer_traits.hpp> #include <boost/mpl/bool.hpp> diff --git a/boost/spirit/home/x3/support/traits/optional_traits.hpp b/boost/spirit/home/x3/support/traits/optional_traits.hpp index 65568b0265..3c5e853797 100644 --- a/boost/spirit/home/x3/support/traits/optional_traits.hpp +++ b/boost/spirit/home/x3/support/traits/optional_traits.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_OPTIONAL_TRAITS_FEBRUARY_06_2007_1001AM) #define BOOST_SPIRIT_X3_OPTIONAL_TRAITS_FEBRUARY_06_2007_1001AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/unused.hpp> #include <boost/optional/optional.hpp> #include <boost/mpl/identity.hpp> diff --git a/boost/spirit/home/x3/support/traits/print_attribute.hpp b/boost/spirit/home/x3/support/traits/print_attribute.hpp index 47bffce1a1..cc76e02d30 100644 --- a/boost/spirit/home/x3/support/traits/print_attribute.hpp +++ b/boost/spirit/home/x3/support/traits/print_attribute.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_PRINT_ATTRIBUTE_JANUARY_20_2013_0814AM) #define BOOST_SPIRIT_X3_PRINT_ATTRIBUTE_JANUARY_20_2013_0814AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/variant.hpp> #include <boost/optional/optional.hpp> #include <boost/fusion/include/is_sequence.hpp> diff --git a/boost/spirit/home/x3/support/traits/print_token.hpp b/boost/spirit/home/x3/support/traits/print_token.hpp index f1429f4776..e8f4dea325 100644 --- a/boost/spirit/home/x3/support/traits/print_token.hpp +++ b/boost/spirit/home/x3/support/traits/print_token.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_PRINT_TOKEN_JANUARY_20_2013_0814AM) #define BOOST_SPIRIT_X3_PRINT_TOKEN_JANUARY_20_2013_0814AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/mpl/if.hpp> #include <boost/mpl/and.hpp> #include <boost/type_traits/is_convertible.hpp> diff --git a/boost/spirit/home/x3/support/traits/string_traits.hpp b/boost/spirit/home/x3/support/traits/string_traits.hpp index 46ee356cdc..44c8d144a8 100644 --- a/boost/spirit/home/x3/support/traits/string_traits.hpp +++ b/boost/spirit/home/x3/support/traits/string_traits.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_STRING_TRAITS_OCTOBER_2008_1252PM) #define BOOST_SPIRIT_X3_STRING_TRAITS_OCTOBER_2008_1252PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <string> #include <boost/mpl/bool.hpp> #include <boost/mpl/identity.hpp> diff --git a/boost/spirit/home/x3/support/traits/transform_attribute.hpp b/boost/spirit/home/x3/support/traits/transform_attribute.hpp index 24268520d7..98af3099e6 100644 --- a/boost/spirit/home/x3/support/traits/transform_attribute.hpp +++ b/boost/spirit/home/x3/support/traits/transform_attribute.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_ATTRIBUTE_TRANSFORM_JAN_8_2012_0721PM) #define BOOST_SPIRIT_X3_ATTRIBUTE_TRANSFORM_JAN_8_2012_0721PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/mpl/identity.hpp> namespace boost { namespace spirit { namespace x3 { namespace traits diff --git a/boost/spirit/home/x3/support/traits/tuple_traits.hpp b/boost/spirit/home/x3/support/traits/tuple_traits.hpp index 17bfd4e1cb..46e4246b74 100644 --- a/boost/spirit/home/x3/support/traits/tuple_traits.hpp +++ b/boost/spirit/home/x3/support/traits/tuple_traits.hpp @@ -7,10 +7,6 @@ #if !defined(BOOST_SPIRIT_X3_TUPLE_TRAITS_JANUARY_2012_1132PM) #define BOOST_SPIRIT_X3_TUPLE_TRAITS_JANUARY_2012_1132PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/fusion/include/is_sequence.hpp> #include <boost/fusion/include/size.hpp> #include <boost/mpl/bool.hpp> diff --git a/boost/spirit/home/x3/support/traits/value_traits.hpp b/boost/spirit/home/x3/support/traits/value_traits.hpp index 5f004c957c..d28af74d3f 100644 --- a/boost/spirit/home/x3/support/traits/value_traits.hpp +++ b/boost/spirit/home/x3/support/traits/value_traits.hpp @@ -9,10 +9,6 @@ #if !defined(BOOST_SPIRIT_X3_VALUE_TRAITS_MAY_07_2013_0203PM) #define BOOST_SPIRIT_X3_VALUE_TRAITS_MAY_07_2013_0203PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/utility/value_init.hpp> namespace boost { namespace spirit { namespace x3 { namespace traits diff --git a/boost/spirit/home/x3/support/traits/variant_find_substitute.hpp b/boost/spirit/home/x3/support/traits/variant_find_substitute.hpp index 4de7b7d5e3..d258d54dc5 100644 --- a/boost/spirit/home/x3/support/traits/variant_find_substitute.hpp +++ b/boost/spirit/home/x3/support/traits/variant_find_substitute.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_VARIANT_FIND_SUBSTITUTE_APR_18_2014_930AM) #define BOOST_SPIRIT_X3_VARIANT_FIND_SUBSTITUTE_APR_18_2014_930AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/traits/is_substitute.hpp> namespace boost { namespace spirit { namespace x3 { namespace traits diff --git a/boost/spirit/home/x3/support/traits/variant_has_substitute.hpp b/boost/spirit/home/x3/support/traits/variant_has_substitute.hpp index d0dfb49b8d..2f8b42a834 100644 --- a/boost/spirit/home/x3/support/traits/variant_has_substitute.hpp +++ b/boost/spirit/home/x3/support/traits/variant_has_substitute.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_VARIANT_HAS_SUBSTITUTE_APR_18_2014_925AM) #define BOOST_SPIRIT_X3_VARIANT_HAS_SUBSTITUTE_APR_18_2014_925AM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/spirit/home/x3/support/traits/is_substitute.hpp> namespace boost { namespace spirit { namespace x3 { namespace traits diff --git a/boost/spirit/home/x3/support/unused.hpp b/boost/spirit/home/x3/support/unused.hpp index cf42d13098..f7857e0dbd 100644 --- a/boost/spirit/home/x3/support/unused.hpp +++ b/boost/spirit/home/x3/support/unused.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_UNUSED_APRIL_16_2006_0616PM) #define BOOST_SPIRIT_X3_UNUSED_APRIL_16_2006_0616PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <ostream> #include <istream> #include <boost/mpl/identity.hpp> @@ -64,16 +60,13 @@ namespace boost { namespace spirit { namespace x3 // unused_type can also masquerade as an empty context (see context.hpp) template <typename ID> - struct get_result : mpl::identity<unused_type> {}; - - template <typename ID> unused_type get(ID) const { - return unused_type(); + return {}; } }; - unused_type const unused = unused_type(); + auto const unused = unused_type{}; inline std::ostream& operator<<(std::ostream& out, unused_type const&) { diff --git a/boost/spirit/home/x3/support/utility/annotate_on_success.hpp b/boost/spirit/home/x3/support/utility/annotate_on_success.hpp new file mode 100644 index 0000000000..8129675559 --- /dev/null +++ b/boost/spirit/home/x3/support/utility/annotate_on_success.hpp @@ -0,0 +1,51 @@ +/*============================================================================= + Copyright (c) 2001-2015 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(BOOST_SPIRIT_X3__ANNOTATE_ON_SUCCESS_HPP) +#define BOOST_SPIRIT_X3__ANNOTATE_ON_SUCCESS_HPP + +#include <boost/spirit/home/x3/support/ast/variant.hpp> +#include <boost/spirit/home/x3/support/context.hpp> +#include <boost/spirit/home/x3/support/utility/error_reporting.hpp> +#include <boost/spirit/home/x3/support/utility/lambda_visitor.hpp> + +namespace boost { namespace spirit { namespace x3 +{ + /////////////////////////////////////////////////////////////////////////// + // The on_success handler tags the AST with the iterator position + // for error handling. + // + // The on_success handler also ties the AST to a vector of iterator + // positions for the purpose of subsequent semantic error handling + // when the program is being compiled. See x3::position_cache in + // x3/support/ast. + // + // We'll ask the X3's error_handler utility to do these. + /////////////////////////////////////////////////////////////////////////// + + struct annotate_on_success + { + template <typename Iterator, typename Context, typename... Types> + inline void on_success(Iterator const& first, Iterator const& last + , variant<Types...>& ast, Context const& context) + { + ast.apply_visitor(x3::make_lambda_visitor<void>([&](auto& node) + { + this->on_success(first, last, node, context); + })); + } + + template <typename T, typename Iterator, typename Context> + inline void on_success(Iterator const& first, Iterator const& last + , T& ast, Context const& context) + { + auto& error_handler = get<error_handler_tag>(context).get(); + error_handler.tag(ast, first, last); + } + }; +}}} + +#endif diff --git a/boost/spirit/home/x3/support/utility/detail/testing.hpp b/boost/spirit/home/x3/support/utility/detail/testing.hpp deleted file mode 100644 index 1423d9fc7b..0000000000 --- a/boost/spirit/home/x3/support/utility/detail/testing.hpp +++ /dev/null @@ -1,16 +0,0 @@ -/*============================================================================= - Copyright (c) 2014 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(BOOST_SPIRIT_X3_DETAIL_TESTING_JUNE_05_2014_00422PM) -#define BOOST_SPIRIT_X3_DETAIL_TESTING_JUNE_05_2014_00422PM - -namespace boost { namespace spirit { namespace x3 { namespace testing -{ - - -}}}} - -#endif diff --git a/boost/spirit/home/x3/support/utility/error_reporting.hpp b/boost/spirit/home/x3/support/utility/error_reporting.hpp index 9e65f2149b..51ac403728 100644 --- a/boost/spirit/home/x3/support/utility/error_reporting.hpp +++ b/boost/spirit/home/x3/support/utility/error_reporting.hpp @@ -7,7 +7,11 @@ #if !defined(BOOST_SPIRIT_X3_ERROR_REPORTING_MAY_19_2014_00405PM) #define BOOST_SPIRIT_X3_ERROR_REPORTING_MAY_19_2014_00405PM +#ifndef BOOST_SPIRIT_X3_NO_FILESYSTEM #include <boost/filesystem/path.hpp> +#endif + +#include <boost/locale/encoding_utf.hpp> #include <boost/spirit/home/x3/support/ast/position_tagged.hpp> #include <ostream> @@ -15,6 +19,9 @@ namespace boost { namespace spirit { namespace x3 { + // tag used to get our error handler from the context + struct error_handler_tag; + template <typename Iterator> class error_handler { @@ -37,11 +44,7 @@ namespace boost { namespace spirit { namespace x3 void operator()(position_tagged pos, std::string const& message) const { auto where = pos_cache.position_of(pos); - (*this)( - where.begin() - , where.end() - , message - ); + (*this)(where.begin(), where.end(), message); } template <typename AST> @@ -49,20 +52,16 @@ namespace boost { namespace spirit { namespace x3 { return pos_cache.annotate(ast, first, last); } -// -// void operator()( -// Iterator first -// , Iterator last -// , Iterator err_op -// , Iterator err_first -// , Iterator err_last -// , std::string const& error_message -// ) const; + + boost::iterator_range<Iterator> position_of(position_tagged pos) const + { + return pos_cache.position_of(pos); + } private: void print_file_line(std::size_t line) const; - void print_line(Iterator& line_start, Iterator last) const; + void print_line(Iterator line_start, Iterator last) const; void print_indicator(Iterator& line_start, Iterator last, char ind) const; void skip_whitespace(Iterator& err_pos, Iterator last) const; void skip_non_whitespace(Iterator& err_pos, Iterator last) const; @@ -78,29 +77,39 @@ namespace boost { namespace spirit { namespace x3 template <typename Iterator> void error_handler<Iterator>::print_file_line(std::size_t line) const { - namespace fs = boost::filesystem; - if (file != "") + { +#ifdef BOOST_SPIRIT_X3_NO_FILESYSTEM + err_out << "In file " << file << ", "; +#else + namespace fs = boost::filesystem; err_out << "In file " << fs::path(file).generic_string() << ", "; +#endif + } else + { err_out << "In "; + } err_out << "line " << line << ':' << std::endl; } template <typename Iterator> - void error_handler<Iterator>::print_line(Iterator& start, Iterator last) const + void error_handler<Iterator>::print_line(Iterator start, Iterator last) const { - for (; start != last; ++start) + auto end = start; + while (end != last) { - auto c = *start; + auto c = *end; if (c == '\r' || c == '\n') break; else - err_out << c; + ++end; } - err_out << std::endl; - } + typedef typename std::iterator_traits<Iterator>::value_type char_type; + std::basic_string<char_type> line{start, end}; + err_out << locale::conv::utf_to_utf<char>(line) << std::endl; + } template <typename Iterator> void error_handler<Iterator>::print_indicator(Iterator& start, Iterator last, char ind) const @@ -159,8 +168,25 @@ namespace boost { namespace spirit { namespace x3 template <typename Iterator> std::size_t error_handler<Iterator>::position(Iterator i) const { - // $$$ asumes iterator is similar to line_pos_iterator $$$ - return i.position(); + std::size_t line { 1 }; + typename std::iterator_traits<Iterator>::value_type prev { 0 }; + + for (Iterator pos = pos_cache.first(); pos != i; ++pos) { + auto c = *pos; + switch (c) { + case '\n': + if (prev != '\r') ++line; + break; + case '\r': + if (prev != '\n') ++line; + break; + default: + break; + } + prev = c; + } + + return line; } template <typename Iterator> @@ -179,8 +205,7 @@ namespace boost { namespace spirit { namespace x3 Iterator start = get_line_start(first, err_pos); if (start != first) ++start; - Iterator i = start; - print_line(i, last); + print_line(start, last); print_indicator(start, err_pos, '_'); err_out << "^_" << std::endl; } @@ -201,40 +226,11 @@ namespace boost { namespace spirit { namespace x3 Iterator start = get_line_start(first, err_first); if (start != first) ++start; - Iterator i = start; - print_line(i, last); + print_line(start, last); print_indicator(start, err_first, ' '); print_indicator(start, err_last, '~'); err_out << " <<-- Here" << std::endl; } -// -// template <typename Iterator> -// void error_handler<Iterator>::operator()( -// Iterator first -// , Iterator last -// , Iterator err_op -// , Iterator err_first -// , Iterator err_last -// , std::string const& error_message -// ) const -// { -// // make sure err_pos does not point to white space -// skip_whitespace(err_first, last); -// -// print_file_line(position(err_pos)); -// err_out << error_message << std::endl; -// -// Iterator start = get_line_start(first, err_first); -// if (start != first) -// ++start; -// Iterator i = start; -// print_line(i, last); -// print_indicator(start, err_first, ' '); -// print_indicator(start, err_op, '~'); -// err_out << '^'; -// print_indicator(++start, err_last, '~'); -// err_out << " <<-- Here" << std::endl; -// } }}} diff --git a/boost/spirit/home/x3/support/utility/integer_sequence.hpp b/boost/spirit/home/x3/support/utility/integer_sequence.hpp deleted file mode 100644 index 1f0bace72b..0000000000 --- a/boost/spirit/home/x3/support/utility/integer_sequence.hpp +++ /dev/null @@ -1,94 +0,0 @@ -/*////////////////////////////////////////////////////////////////////////////// - Copyright (c) 2014 Jamboree - - 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) -//////////////////////////////////////////////////////////////////////////////*/ -#ifndef BOOST_SPIRIT_X3_INTEGER_SEQUENCE_HPP_INCLUDED -#define BOOST_SPIRIT_X3_INTEGER_SEQUENCE_HPP_INCLUDED - -#if defined(_MSC_VER) -#pragma once -#endif - -#include <cstddef> -#include <boost/type_traits/integral_constant.hpp> - -// This is a standard (c++1y) compatible integer_sequence implementation, -// it's needed for now, and it could be replaced with std::integer_sequence -// once the new standard is available everywhere. - -namespace boost { namespace spirit { namespace x3 -{ - template <typename T, T... Ns> - struct integer_sequence - { - typedef T value_type; - - static constexpr std::size_t size() noexcept - { - return sizeof...(Ns); - } - }; -}}} - -namespace boost { namespace spirit { namespace x3 { namespace detail -{ - template <typename T, typename S1, typename S2, T N> - struct accum_integer_sequence; - - template <typename T, T... N1, T... N2, T N> - struct accum_integer_sequence<T, integer_sequence<T, N1...>, integer_sequence<T, N2...>, N> - { - typedef integer_sequence<T, N1..., (N + N2)...> type; - }; - - template <typename N> - struct make_integer_sequence_impl - { - typedef typename N::value_type T; - static T const n = N::value; - static T const m = n / 2; - typedef typename - make_integer_sequence_impl<integral_constant<T, m>>::type - part1; - typedef typename - make_integer_sequence_impl<integral_constant<T, n - m>>::type - part2; - typedef typename - accum_integer_sequence<T, part1, part2, m>::type - type; - }; - - template <typename T> - struct make_integer_sequence_impl<integral_constant<T, 0>> - { - typedef integer_sequence<T> type; - }; - - template <typename T> - struct make_integer_sequence_impl<integral_constant<T, 1>> - { - typedef integer_sequence<T, 0> type; - }; -}}}} - -namespace boost { namespace spirit { namespace x3 -{ - template <std::size_t... Ns> - using index_sequence = integer_sequence<std::size_t, Ns...>; - - template <typename T, T N> - using make_integer_sequence = typename detail::make_integer_sequence_impl< - integral_constant<T, N>>::type; - - template <std::size_t N> - using make_index_sequence = make_integer_sequence<std::size_t, N>; - - template <typename... T> - using index_sequence_for = make_index_sequence<sizeof...(T)>; -}}} - - -#endif - diff --git a/boost/spirit/home/x3/support/utility/is_callable.hpp b/boost/spirit/home/x3/support/utility/is_callable.hpp index 17f86822b8..5e116de410 100644 --- a/boost/spirit/home/x3/support/utility/is_callable.hpp +++ b/boost/spirit/home/x3/support/utility/is_callable.hpp @@ -7,25 +7,17 @@ #ifndef BOOST_SPIRIT_X3_IS_CALLABLE_HPP_INCLUDED #define BOOST_SPIRIT_X3_IS_CALLABLE_HPP_INCLUDED -#if defined(_MSC_VER) -#pragma once -#endif - -#include <boost/utility/result_of.hpp> #include <boost/mpl/bool.hpp> #include <boost/spirit/home/x3/support/utility/sfinae.hpp> - namespace boost { namespace spirit { namespace x3 { namespace detail { template <typename Sig, typename Enable = void> - struct is_callable_impl - : mpl::false_ - {}; + struct is_callable_impl : mpl::false_ {}; template <typename F, typename... A> struct is_callable_impl<F(A...), typename disable_if_substitution_failure< - typename result_of<F(A...)>::type>::type> + decltype(std::declval<F>()(std::declval<A>()...))>::type> : mpl::true_ {}; }}}} @@ -36,9 +28,7 @@ namespace boost { namespace spirit { namespace x3 struct is_callable; template <typename F, typename... A> - struct is_callable<F(A...)> - : detail::is_callable_impl<F(A...)> - {}; + struct is_callable<F(A...)> : detail::is_callable_impl<F(A...)> {}; }}} diff --git a/boost/spirit/home/x3/support/utility/sfinae.hpp b/boost/spirit/home/x3/support/utility/sfinae.hpp index 6cefa95961..532ae5c54d 100644 --- a/boost/spirit/home/x3/support/utility/sfinae.hpp +++ b/boost/spirit/home/x3/support/utility/sfinae.hpp @@ -8,10 +8,6 @@ #if !defined(BOOST_SPIRIT_X3_SFINAE_MAY_20_2013_0840AM) #define BOOST_SPIRIT_X3_SFINAE_MAY_20_2013_0840AM -#if defined(_MSC_VER) -#pragma once -#endif - namespace boost { namespace spirit { namespace x3 { template <typename Expr, typename T = void> @@ -19,6 +15,7 @@ namespace boost { namespace spirit { namespace x3 { typedef T type; }; + template <typename Expr, typename T> struct lazy_disable_if_substitution_failure { diff --git a/boost/spirit/home/x3/support/utility/testing.hpp b/boost/spirit/home/x3/support/utility/testing.hpp index fced46bef8..6d38ccfed7 100644 --- a/boost/spirit/home/x3/support/utility/testing.hpp +++ b/boost/spirit/home/x3/support/utility/testing.hpp @@ -1,68 +1,268 @@ /*============================================================================= - Copyright (c) 2014 Joel de Guzman + Copyright (c) 2001-2015 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(BOOST_SPIRIT_X3_TESTING_JUNE_05_2014_00422PM) -#define BOOST_SPIRIT_X3_TESTING_JUNE_05_2014_00422PM +=============================================================================*/ +#if !defined(BOOST_SPIRIT_X3_TEST_UTILITIES) +#define BOOST_SPIRIT_X3_TEST_UTILITIES + +#include <boost/regex.hpp> +#include <boost/filesystem.hpp> +#include <boost/filesystem/fstream.hpp> namespace boost { namespace spirit { namespace x3 { namespace testing { + namespace fs = boost::filesystem; + //////////////////////////////////////////////////////////////////////////// + // compare // - // Test utility - // - // The test function accepts a file loaded in memory. The 'test_file' - // range param points to the data contained in the file. This file - // contains two parts. - // - // 1) The source input for testing - // 2) The expected result. - // - // The first part of the file is sent to the generator function - // 'gen' which returns a string. This generated string is then compared - // to the contents of the second (expected result) part. - // - // The second part is demarcated by the string parameter 'demarcation' - // which defaults to "<**expected**>". The expected template may include - // embedded regular expressions marked-up within re_prefix and re_suffix - // parameter tags. For example, given the default RE markup ("<%" and - // "%>"), this template: - // - // <%[0-9]+%> - // - // will match any integer in the source input being tested. The function - // will return the first non-matching position. The flag full_match - // indicates a full match. It is possible for returned pos to be - // at the end of in (in.end()) while still returning full_match == - // false. In that case, we have a partial match. - // - // Here's an example of a test file: - // - // Hello World, I am Joel. This is a test. - // - // <**expected**> - // Hello World, I am <%[a-zA-Z]+%>. This is a test. - // + // Compares the contents of in with the template tem. The template + // may include embedded regular expressions marked up within re_prefix + // and re_suffix tags. For example, given the default RE markup, this + // template <%[0-9]+%> will match any integer in in. The function + // will return the first non-matching position. The flag full_match + // indicates a full match. It is possible for returned pos to be + // at the end of in (in.end()) while still returning full_match == + // false. In that case, we have a partial match. //////////////////////////////////////////////////////////////////////////// template <typename Iterator> - struct test_result + struct compare_result { + compare_result( + Iterator pos + , bool full_match + ) : pos(pos), full_match(full_match) {} + Iterator pos; bool full_match; }; - template <typename Range, typename F> - test_result<typename Range::const_iterator> - test( - Range test_file - , F gen - , char const* demarcation = "<**expected**>" + template <typename Range> + compare_result<typename Range::const_iterator> + compare( + Range const& in + , Range const& tem + , char const* re_prefix = "<%" + , char const* re_suffix = "%>" + ); + + //////////////////////////////////////////////////////////////////////////// + // compare + // + // 1) Call f, given the contents of input_path loaded in a string. + // The result of calling f is the output string. + // 2) Compare the result of calling f with expected template + // file (expect_path) using the low-level compare utility + // abive + //////////////////////////////////////////////////////////////////////////// + template <typename F> + bool compare( + fs::path input_path, fs::path expect_path + , F f , char const* re_prefix = "<%" , char const* re_suffix = "%>" - ); + ); + + //////////////////////////////////////////////////////////////////////////// + // for_each_file + // + // For each *.input and *.expect file in a given directory, + // call the function f, passing in the *.input and *.expect paths. + //////////////////////////////////////////////////////////////////////////// + template <typename F> + int for_each_file(fs::path p, F f); + + //////////////////////////////////////////////////////////////////////////// + // load_file + // + // Load file into a string. + //////////////////////////////////////////////////////////////////////////// + std::string load(fs::path p); + + //////////////////////////////////////////////////////////////////////////// + // Implementation + //////////////////////////////////////////////////////////////////////////// + + template <typename Iterator> + inline bool is_regex( + Iterator& first + , Iterator last + , std::string& re + , char const* re_prefix + , char const* re_suffix + ) + { + boost::regex e(re_prefix + std::string("(.*?)") + re_suffix); + boost::match_results<Iterator> what; + if (boost::regex_search( + first, last, what, e + , boost::match_default | boost::match_continuous)) + { + re = what[1].str(); + first = what[0].second; + return true; + } + return false; + } + + template <typename Range> + inline compare_result<typename Range::const_iterator> + compare( + Range const& in + , Range const& tem + , char const* re_prefix + , char const* re_suffix + ) + { + typedef typename Range::const_iterator iter_t; + typedef compare_result<iter_t> compare_result_t; + + iter_t in_first = in.begin(); + iter_t in_last = in.end(); + iter_t tem_first = tem.begin(); + iter_t tem_last = tem.end(); + std::string re; + + while (in_first != in_last && tem_first != tem_last) + { + if (is_regex(tem_first, tem_last, re, re_prefix, re_suffix)) + { + boost::match_results<iter_t> what; + boost::regex e(re); + if (!boost::regex_search( + in_first, in_last, what, e + , boost::match_default | boost::match_continuous)) + { + // RE mismatch: exit now. + return compare_result_t(in_first, false); + } + else + { + // RE match: gobble the matching string. + in_first = what[0].second; + } + } + else + { + // Char by char comparison. Exit if we have a mismatch. + if (*in_first++ != *tem_first++) + return compare_result_t(in_first, false); + } + } + + // Ignore trailing spaces in template + bool has_trailing_nonspaces = false; + while (tem_first != tem_last) + { + if (!std::isspace(*tem_first++)) + { + has_trailing_nonspaces = true; + break; + } + } + while (in_first != in_last) + { + if (!std::isspace(*in_first++)) + { + has_trailing_nonspaces = true; + break; + } + } + // return a full match only if the template is fully matched and if there + // are no more characters to match in the source + return compare_result_t(in_first, !has_trailing_nonspaces); + } + + template <typename F> + inline int for_each_file(fs::path p, F f) + { + try + { + if (fs::exists(p) && fs::is_directory(p)) + { + for (auto i = fs::directory_iterator(p); i != fs::directory_iterator(); ++i) + { + auto ext = fs::extension(i->path()); + if (ext == ".input") + { + auto input_path = i->path(); + auto expect_path = input_path; + expect_path.replace_extension(".expect"); + f(input_path, expect_path); + } + } + } + else + { + std::cerr << "Directory: " << fs::absolute(p) << " does not exist." << std::endl; + return 1; + } + } + + catch (const fs::filesystem_error& ex) + { + std::cerr << ex.what() << '\n'; + return 1; + } + return 0; + } + + inline std::string load(fs::path p) + { + boost::filesystem::ifstream file(p); + if (!file) + return ""; + std::string contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); + return contents; + } + + template <typename F> + inline bool compare( + fs::path input_path, fs::path expect_path + , F f + , char const* re_prefix + , char const* re_suffix + ) + { + std::string output = f(load(input_path), input_path); + std::string expected = load(expect_path); + + auto result = compare(output, expected); + if (!result.full_match) + { + std::cout << "=============================================" << std::endl; + std::cout << "==== Mismatch Found:" << std::endl; + int line = 1; + int col = 1; + for (auto i = output.begin(); i != result.pos; ++i) + { + if (*i == '\n') + { + line++; + col = 0; + } + ++col; + } + + std::cerr + << "==== File: " << expect_path + << ", Line: " << line + << ", Column: " << col + << std::endl; + std::cerr << "=============================================" << std::endl; + + // Print output + std::cerr << output; + std::cerr << "=============================================" << std::endl; + std::cerr << "==== End" << std::endl; + std::cerr << "=============================================" << std::endl; + return false; + } + return true; + } }}}} diff --git a/boost/spirit/home/x3/support/utility/unrefcv.hpp b/boost/spirit/home/x3/support/utility/unrefcv.hpp index fa4d448178..b12620b591 100644 --- a/boost/spirit/home/x3/support/utility/unrefcv.hpp +++ b/boost/spirit/home/x3/support/utility/unrefcv.hpp @@ -7,10 +7,6 @@ #ifndef BOOST_SPIRIT_X3_UNREFCV_HPP_INCLUDED #define BOOST_SPIRIT_X3_UNREFCV_HPP_INCLUDED -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/type_traits/remove_cv.hpp> #include <boost/type_traits/remove_reference.hpp> diff --git a/boost/spirit/home/x3/support/utility/utf8.hpp b/boost/spirit/home/x3/support/utility/utf8.hpp index 93b5a22077..b141cce6d2 100644 --- a/boost/spirit/home/x3/support/utility/utf8.hpp +++ b/boost/spirit/home/x3/support/utility/utf8.hpp @@ -7,12 +7,7 @@ #if !defined(BOOST_SPIRIT_X3_UC_TYPES_NOVEMBER_23_2008_0840PM) #define BOOST_SPIRIT_X3_UC_TYPES_NOVEMBER_23_2008_0840PM -#if defined(_MSC_VER) -#pragma once -#endif - #include <boost/cstdint.hpp> -#include <boost/foreach.hpp> #include <boost/regex/pending/unicode_iterator.hpp> #include <boost/type_traits/make_unsigned.hpp> #include <string> @@ -61,7 +56,7 @@ namespace boost { namespace spirit { namespace x3 insert_iter out_iter(result); utf8_output_iterator<insert_iter> utf8_iter(out_iter); typedef typename make_unsigned<Char>::type UChar; - BOOST_FOREACH(Char ch, str) + for (Char ch : str) { *utf8_iter++ = (UChar)ch; } |