#ifndef TOML11_ACCEPTOR #define TOML11_ACCEPTOR #include #include #include #include "exception.hpp" namespace toml { template struct is_character { typedef charT value_type; constexpr static value_type target = c; template::value_type, value_type>::value>::type> constexpr static Iterator invoke(Iterator iter, Iterator end) { return iter == end ? iter : *iter == c ? std::next(iter) : iter; } }; template struct is_in_range { typedef charT value_type; constexpr static value_type upper = up; constexpr static value_type lower = lw; static_assert(lower <= upper, "lower <= upper"); template::value_type, value_type>::value>::type> constexpr static Iterator invoke(Iterator iter, Iterator end) { return iter == end ? iter : (lower <= *iter && *iter <= upper) ? std::next(iter) : iter; } }; template struct is_one_of { typedef typename headT::value_type value_type; static_assert( std::is_same::value_type>::value, "different value_type"); template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { const Iterator tmp = headT::invoke(iter, end); return (tmp != iter) ? tmp : is_one_of::invoke(iter, end); } }; template struct is_one_of { typedef typename tailT::value_type value_type; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { const Iterator tmp = tailT::invoke(iter, end); return (tmp != iter) ? tmp : iter; } }; // just a wrapper for maybe_ignored template struct is_ignorable { typedef typename condT::value_type value_type; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { const Iterator tmp = condT::invoke(iter, end); return (tmp != iter) ? tmp : iter; } }; template struct maybe_ignored : std::false_type{}; template struct maybe_ignored> : std::true_type{}; template struct is_chain_of_impl { typedef typename headT::value_type value_type; static_assert(std::is_same::value_type>::value, "different value_type"); constexpr static bool ignorable = maybe_ignored::value; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end, Iterator rollback) { const Iterator tmp = headT::invoke(iter, end); return (tmp == iter && !ignorable) ? rollback : is_chain_of_impl::invoke(tmp, end, rollback); } }; template struct is_chain_of_impl { typedef typename tailT::value_type value_type; constexpr static bool ignorable = maybe_ignored::value; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end, Iterator rollback) { const Iterator tmp = tailT::invoke(iter, end); return (tmp == iter) ? (ignorable ? iter : rollback) : tmp; } }; template struct is_chain_of { typedef typename is_chain_of_impl::value_type value_type; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { return is_chain_of_impl::invoke(iter, end, iter); } }; constexpr inline std::size_t repeat_infinite(){return 0ul;} template struct is_repeat_of { typedef typename condT::value_type value_type; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { const Iterator rollback = iter; Iterator tmp; for(auto i=0ul; i struct is_repeat_of { typedef typename condT::value_type value_type; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { Iterator tmp = condT::invoke(iter, end); while(tmp != iter) { iter = tmp; tmp = condT::invoke(iter, end); } return iter; } }; template struct is_none_of { typedef typename headT::value_type value_type; static_assert( std::is_same::value_type>::value, "different value_type"); template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { const Iterator tmp = headT::invoke(iter, end); return (tmp != iter) ? iter : is_none_of::invoke(iter, end); } }; template struct is_none_of { typedef typename tailT::value_type value_type; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { const Iterator tmp = tailT::invoke(iter, end); return (tmp != iter) ? iter : std::next(iter); } }; template struct is_not_but { typedef typename notT::value_type value_type; static_assert( std::is_same::value, "different value type"); template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { return (iter != notT::invoke(iter, end)) ? iter : butT::invoke(iter, end); } }; template using is_space = is_character; template using is_tab = is_character; template using is_number = is_in_range; template using is_lowercase = is_in_range; template using is_uppercase = is_in_range; template using is_alphabet = is_one_of, is_uppercase>; template using is_hex = is_one_of, is_in_range, is_in_range>; template using is_whitespace = is_one_of, is_tab>; template using is_any_num_of_ws = is_ignorable, repeat_infinite()>>; template using is_newline = is_one_of, is_chain_of, is_character>>; template using is_barekey_component = is_one_of, is_number, is_character, is_character>; template using is_barekey = is_repeat_of, repeat_infinite()>; template using is_comment = is_chain_of< is_character, is_repeat_of>, repeat_infinite()>, is_newline >; template using is_basic_inline_string_component = is_one_of< is_none_of< is_in_range, is_character, is_character, is_newline>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character, is_repeat_of, 4>>, is_chain_of, is_character, is_repeat_of, 8>> >; template using is_basic_inline_string = is_not_but< is_repeat_of, 3>, // not multiline is_chain_of< is_character, is_ignorable, repeat_infinite()>>, is_character > >; template using is_basic_multiline_string_component = is_one_of< is_none_of< is_in_range, is_repeat_of, 3>, is_character>, is_newline, is_chain_of, is_newline>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character>, is_chain_of, is_character, is_repeat_of, 4>>, is_chain_of, is_character, is_repeat_of, 8>> >; template using is_basic_multiline_string = is_chain_of< is_repeat_of, 3>, is_ignorable, repeat_infinite()>>, is_repeat_of, 3> >; template using is_literal_inline_string_component = is_none_of, is_character>; template using is_literal_inline_string = is_not_but< is_repeat_of, 3>, is_chain_of< is_character, is_ignorable, repeat_infinite()>>, is_character > >; template using is_literal_multiline_string_component = is_one_of< is_none_of, is_repeat_of, 3>>, is_newline >; template using is_literal_multiline_string = is_chain_of< is_repeat_of, 3>, is_ignorable, repeat_infinite()>>, is_repeat_of, 3> >; template using is_string = is_one_of< is_basic_inline_string, is_basic_multiline_string, is_literal_inline_string, is_literal_multiline_string >; template using is_sign = is_one_of, is_character>; template using is_nonzero_number = is_in_range; template using is_integer_component = is_not_but< is_repeat_of, 2>, is_one_of< is_character, is_number > >; template using is_integer = is_chain_of< is_ignorable>, is_one_of< is_character, is_chain_of< is_nonzero_number, is_ignorable, repeat_infinite()> > > > >; template using is_fractional_part = is_chain_of< is_character, is_repeat_of, repeat_infinite()> >; template using is_exponent_part = is_chain_of< is_one_of, is_character>, is_integer >; template using is_float = is_one_of< is_chain_of< is_integer, is_fractional_part, is_exponent_part >, is_chain_of< is_integer, is_fractional_part >, is_chain_of< is_integer, is_exponent_part > >; template using is_boolean = is_one_of< is_chain_of< is_character, is_character, is_character, is_character >, is_chain_of< is_character, is_character, is_character, is_character, is_character > >; template using is_local_time = is_chain_of< is_repeat_of, 2>, is_character, is_repeat_of, 2>, is_character, is_repeat_of, 2>, is_ignorable< is_chain_of< is_character, is_repeat_of, repeat_infinite()> > > >; template using is_local_date = is_chain_of< is_repeat_of, 4>, is_character, is_repeat_of, 2>, is_character, is_repeat_of, 2> >; template using is_local_date_time = is_chain_of< is_local_date, is_character, is_local_time >; template using is_offset = is_one_of< is_character, is_chain_of< is_sign, is_repeat_of, 2>, is_character, is_repeat_of, 2> > >; template using is_offset_date_time = is_chain_of< is_local_date_time, is_offset >; template using is_datetime = is_one_of< is_offset_date_time, is_local_date_time, is_local_date, is_local_time >; template using is_fundamental_type = is_one_of< is_basic_inline_string, is_basic_multiline_string, is_literal_inline_string, is_literal_multiline_string, is_offset_date_time, is_local_date_time, is_local_date, is_local_time, is_boolean, is_float, is_integer >; template using is_skippable_in_array = is_repeat_of< is_one_of, is_newline, is_comment>, repeat_infinite() >; template struct is_inline_table; template using is_key = is_one_of< is_barekey, is_string >; template using is_fixed_type_array = is_chain_of< is_character, is_ignorable< is_repeat_of< is_chain_of< is_ignorable>, is_array_component, is_ignorable>, is_character >, repeat_infinite() > >, is_ignorable< is_chain_of< is_ignorable>, is_array_component, is_ignorable>, is_ignorable> > >, is_ignorable>, is_character >; template struct is_array { typedef charT value_type; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { return is_one_of< is_fixed_type_array>, is_fixed_type_array>, is_fixed_type_array>, is_fixed_type_array>, is_fixed_type_array>, is_fixed_type_array>, is_fixed_type_array> >::invoke(iter, end); } }; template struct is_inline_table { typedef charT value_type; template::value_type, value_type>::value>::type> static Iterator invoke(Iterator iter, Iterator end) { typedef is_one_of, is_array, is_inline_table> is_component; typedef is_chain_of< is_any_num_of_ws, is_key, is_any_num_of_ws, is_character, is_ignorable< is_repeat_of< is_chain_of< is_any_num_of_ws, is_inline_key_value_pair, is_any_num_of_ws, is_character >, repeat_infinite() > >, is_ignorable< is_chain_of< is_any_num_of_ws, is_inline_key_value_pair, is_any_num_of_ws, is_ignorable> > >, is_any_num_of_ws, is_character > entity; return entity::invoke(iter, end); } }; template using is_value = is_one_of, is_array, is_inline_table>; // [] template using is_table_definition = is_chain_of< is_any_num_of_ws, is_character, is_any_num_of_ws, is_key, is_ignorable< is_repeat_of< is_chain_of< is_any_num_of_ws, is_character, is_any_num_of_ws, is_key, is_any_num_of_ws >, repeat_infinite()> >, is_character >; template using is_array_of_table_definition = is_chain_of< is_any_num_of_ws, is_repeat_of, 2>, is_any_num_of_ws, is_key, is_ignorable< is_repeat_of< is_chain_of< is_any_num_of_ws, is_character, is_any_num_of_ws, is_key, is_any_num_of_ws >, repeat_infinite()> >, is_repeat_of, 2> >; template using is_key_value_pair = is_chain_of< is_any_num_of_ws, is_key, is_any_num_of_ws, is_character