diff --git a/tests/test_acceptor.cpp b/tests/test_acceptor.cpp index e29bedf..f12801a 100644 --- a/tests/test_acceptor.cpp +++ b/tests/test_acceptor.cpp @@ -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; + { + 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; + { + 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()); + } +} diff --git a/toml/acceptor.hpp b/toml/acceptor.hpp index 3c2f0e2..d19a04b 100644 --- a/toml/acceptor.hpp +++ b/toml/acceptor.hpp @@ -255,6 +255,10 @@ 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_charactor>>; @@ -524,11 +528,6 @@ using is_key = is_literal_inline_string >; -template -using is_skippable_in_inline_table = - is_repeat_of, repeat_infinite()>; - - template struct is_array { @@ -583,13 +582,13 @@ struct is_inline_table typedef is_one_of, is_array, is_inline_table> is_component; typedef is_chain_of< - is_ignorable>, + is_any_num_of_ws, is_key, - is_ignorable>, + is_any_num_of_ws, is_charactor >, repeat_infinite() @@ -607,25 +606,79 @@ struct is_inline_table >, is_ignorable< is_chain_of< - is_ignorable>, + is_any_num_of_ws, is_inline_key_value_pair, - is_ignorable>, + is_any_num_of_ws, is_ignorable> > >, - is_ignorable>, + is_any_num_of_ws, is_charactor > entity; return entity::invoke(iter); } }; +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_charactor, + is_any_num_of_ws, + is_ignorable< + is_repeat_of< + is_chain_of< + is_any_num_of_ws, + is_key, + is_any_num_of_ws, + is_charactor, + is_any_num_of_ws + >, + repeat_infinite()> + >, + is_key, + is_charactor + >; +template +using is_array_of_table_definition = + is_chain_of< + is_any_num_of_ws, + is_repeat_of, 2>, + is_ignorable< + is_repeat_of< + is_chain_of< + is_any_num_of_ws, + is_key, + is_any_num_of_ws, + is_charactor, + is_any_num_of_ws + >, + repeat_infinite()> + >, + is_key, + 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_charactor