mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
add table definition acceptor
This commit is contained in:
@@ -408,7 +408,7 @@ BOOST_AUTO_TEST_CASE(test_array)
|
||||
{
|
||||
const std::string arr1("[1,\n2,#comment\n3]");
|
||||
BOOST_CHECK(is_valid::invoke(arr1.cbegin()) == arr1.cend());
|
||||
const std::string arr2("[1,\n2,#comment\r\n3]");
|
||||
const std::string arr2("[#c\n1,\n2,#comment\r\n3]");
|
||||
BOOST_CHECK(is_valid::invoke(arr2.cbegin()) == arr2.cend());
|
||||
}
|
||||
}
|
||||
@@ -446,7 +446,36 @@ BOOST_AUTO_TEST_CASE(test_inline_table)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_table_definition)
|
||||
{
|
||||
using is_valid = toml::is_table_definition<char>;
|
||||
{
|
||||
const std::string simple("[hoge]");
|
||||
BOOST_CHECK(is_valid::invoke(simple.cbegin()) == simple.cend());
|
||||
const std::string dotted("[hoge.piyo.fuga]");
|
||||
BOOST_CHECK(is_valid::invoke(dotted.cbegin()) == dotted.cend());
|
||||
const std::string spaced_dotted("[hoge . piyo .fuga. foo]");
|
||||
BOOST_CHECK(is_valid::invoke(spaced_dotted.cbegin()) == spaced_dotted.cend());
|
||||
const std::string quoted("[\"hoge\"]");
|
||||
BOOST_CHECK(is_valid::invoke(quoted.cbegin()) == quoted.cend());
|
||||
const std::string quoted_dot("[\"hoge\".'piyo'.fuga]");
|
||||
BOOST_CHECK(is_valid::invoke(quoted_dot.cbegin()) == quoted_dot.cend());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_array_of_table_definition)
|
||||
{
|
||||
using is_valid = toml::is_array_of_table_definition<char>;
|
||||
{
|
||||
const std::string simple("[[hoge]]");
|
||||
BOOST_CHECK(is_valid::invoke(simple.cbegin()) == simple.cend());
|
||||
const std::string dotted("[[hoge.piyo.fuga]]");
|
||||
BOOST_CHECK(is_valid::invoke(dotted.cbegin()) == dotted.cend());
|
||||
const std::string spaced_dotted("[[hoge . piyo .fuga. foo]]");
|
||||
BOOST_CHECK(is_valid::invoke(spaced_dotted.cbegin()) == spaced_dotted.cend());
|
||||
const std::string quoted("[[\"hoge\"]]");
|
||||
BOOST_CHECK(is_valid::invoke(quoted.cbegin()) == quoted.cend());
|
||||
const std::string quoted_dot("[[\"hoge\".'piyo'.fuga]]");
|
||||
BOOST_CHECK(is_valid::invoke(quoted_dot.cbegin()) == quoted_dot.cend());
|
||||
}
|
||||
}
|
||||
|
@@ -255,6 +255,10 @@ using is_hex = is_one_of<is_number<charT>, is_in_range<charT, 'a', 'f'>,
|
||||
is_in_range<charT, 'A', 'F'>>;
|
||||
template<typename charT>
|
||||
using is_whitespace = is_one_of<is_space<charT>, is_tab<charT>>;
|
||||
template<typename charT>
|
||||
using is_any_num_of_ws =
|
||||
is_ignorable<is_repeat_of<is_whitespace<charT>, repeat_infinite()>>;
|
||||
|
||||
template<typename charT>
|
||||
using is_newline = is_one_of<is_charactor<charT, '\n'>,
|
||||
is_chain_of<is_charactor<charT, '\r'>, is_charactor<charT, '\n'>>>;
|
||||
@@ -524,11 +528,6 @@ using is_key =
|
||||
is_literal_inline_string<charT>
|
||||
>;
|
||||
|
||||
template<typename charT>
|
||||
using is_skippable_in_inline_table =
|
||||
is_repeat_of<is_whitespace<charT>, repeat_infinite()>;
|
||||
|
||||
|
||||
template<typename charT>
|
||||
struct is_array
|
||||
{
|
||||
@@ -583,13 +582,13 @@ struct is_inline_table
|
||||
typedef is_one_of<is_fundamental_type<charT>,
|
||||
is_array<charT>, is_inline_table<charT>> is_component;
|
||||
typedef is_chain_of<
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_key<charT>,
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_charactor<charT, '='>,
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_component,
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>
|
||||
is_any_num_of_ws<charT>
|
||||
> is_inline_key_value_pair;
|
||||
|
||||
typedef is_chain_of<
|
||||
@@ -597,9 +596,9 @@ struct is_inline_table
|
||||
is_ignorable<
|
||||
is_repeat_of<
|
||||
is_chain_of<
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_inline_key_value_pair,
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_charactor<charT, ','>
|
||||
>,
|
||||
repeat_infinite()
|
||||
@@ -607,25 +606,79 @@ struct is_inline_table
|
||||
>,
|
||||
is_ignorable<
|
||||
is_chain_of<
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_inline_key_value_pair,
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_ignorable<is_charactor<charT, ','>>
|
||||
>
|
||||
>,
|
||||
is_ignorable<is_skippable_in_inline_table<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_charactor<charT, '}'>
|
||||
> entity;
|
||||
return entity::invoke(iter);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename charT>
|
||||
using is_value =
|
||||
is_one_of<is_fundamental_type<charT>, is_array<charT>, is_inline_table<charT>>;
|
||||
|
||||
// []
|
||||
template<typename charT>
|
||||
using is_table_definition =
|
||||
is_chain_of<
|
||||
is_any_num_of_ws<charT>,
|
||||
is_charactor<charT, '['>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_ignorable<
|
||||
is_repeat_of<
|
||||
is_chain_of<
|
||||
is_any_num_of_ws<charT>,
|
||||
is_key<charT>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_charactor<charT, '.'>,
|
||||
is_any_num_of_ws<charT>
|
||||
>,
|
||||
repeat_infinite()>
|
||||
>,
|
||||
is_key<charT>,
|
||||
is_charactor<charT, ']'>
|
||||
>;
|
||||
|
||||
template<typename charT>
|
||||
using is_array_of_table_definition =
|
||||
is_chain_of<
|
||||
is_any_num_of_ws<charT>,
|
||||
is_repeat_of<is_charactor<charT, '['>, 2>,
|
||||
is_ignorable<
|
||||
is_repeat_of<
|
||||
is_chain_of<
|
||||
is_any_num_of_ws<charT>,
|
||||
is_key<charT>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_charactor<charT, '.'>,
|
||||
is_any_num_of_ws<charT>
|
||||
>,
|
||||
repeat_infinite()>
|
||||
>,
|
||||
is_key<charT>,
|
||||
is_repeat_of<is_charactor<charT, ']'>, 2>
|
||||
>;
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename charT>
|
||||
using is_key_value_pair =
|
||||
is_chain_of<
|
||||
is_any_num_of_ws<charT>,
|
||||
is_key<charT>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_charactor<charT, '='>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_value<charT>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_ignorable<is_comment<charT>>,
|
||||
is_any_num_of_ws<charT>,
|
||||
is_newline<charT>
|
||||
>;
|
||||
|
||||
}//toml
|
||||
#endif// TOML11_ACCEPTOR
|
||||
|
Reference in New Issue
Block a user