mirror of
https://github.com/boostorg/spirit.git
synced 2026-01-19 04:42:11 +00:00
Modernize char/string, use X3's own char_encoding
This commit is contained in:
@@ -91,8 +91,7 @@ run extract_int.cpp ;
|
||||
run int1.cpp ;
|
||||
run kleene.cpp ;
|
||||
run lexeme.cpp ;
|
||||
run lit1.cpp ;
|
||||
run lit2.cpp ;
|
||||
run lit.cpp ;
|
||||
run list.cpp ;
|
||||
run matches.cpp ;
|
||||
run no_case.cpp ;
|
||||
|
||||
@@ -1,11 +1,38 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
Copyright (c) 2011 Bryce Lelbach
|
||||
Copyright (c) 2011 Bryce Lelbach
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
#include "bool.hpp"
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
|
||||
#include <string_view>
|
||||
#include <iterator>
|
||||
|
||||
struct backwards_bool_policies : boost::spirit::x3::bool_policies<>
|
||||
{
|
||||
// we want to interpret a 'true' spelled backwards as 'false'
|
||||
template <std::forward_iterator It, std::sentinel_for<It> Se, typename Attribute, typename CaseCompare>
|
||||
[[nodiscard]] static constexpr bool
|
||||
parse_false(
|
||||
It& first, Se const& last, Attribute& attr, CaseCompare const& case_compare
|
||||
)
|
||||
{
|
||||
using namespace std::string_view_literals;
|
||||
namespace x3 = boost::spirit::x3;
|
||||
if (x3::detail::string_parse("eurt"sv, first, last, x3::unused, case_compare))
|
||||
{
|
||||
x3::traits::move_to(false, attr); // result is false
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -27,61 +54,65 @@ int main()
|
||||
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(true_);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(false_);
|
||||
|
||||
|
||||
BOOST_TEST(test("true", true_));
|
||||
BOOST_TEST(!test("true", false_));
|
||||
BOOST_TEST(test("false", false_));
|
||||
BOOST_TEST(!test("false", true_));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
using boost::spirit::x3::true_;
|
||||
using boost::spirit::x3::false_;
|
||||
using boost::spirit::x3::no_case;
|
||||
|
||||
|
||||
BOOST_TEST(test("True", no_case[bool_]));
|
||||
BOOST_TEST(test("False", no_case[bool_]));
|
||||
BOOST_TEST(test("True", no_case[true_]));
|
||||
BOOST_TEST(test("False", no_case[false_]));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
bool b = false;
|
||||
BOOST_TEST(test_attr("true", bool_, b) && b);
|
||||
BOOST_TEST(test_attr("false", bool_, b) && !b);
|
||||
BOOST_TEST(!test_attr("fasle", bool_, b));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
typedef boost::spirit::x3::bool_parser<bool, boost::spirit::char_encoding::standard, backwards_bool_policies>
|
||||
backwards_bool_type;
|
||||
using backwards_bool_type = boost::spirit::x3::bool_parser<bool, boost::spirit::x3::char_encoding::standard, backwards_bool_policies>;
|
||||
constexpr backwards_bool_type backwards_bool{};
|
||||
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(backwards_bool);
|
||||
|
||||
|
||||
BOOST_TEST(test("true", backwards_bool));
|
||||
BOOST_TEST(test("eurt", backwards_bool));
|
||||
BOOST_TEST(!test("false", backwards_bool));
|
||||
BOOST_TEST(!test("fasle", backwards_bool));
|
||||
|
||||
|
||||
bool b = false;
|
||||
BOOST_TEST(test_attr("true", backwards_bool, b) && b);
|
||||
BOOST_TEST(test_attr("eurt", backwards_bool, b) && !b);
|
||||
BOOST_TEST(!test_attr("false", backwards_bool, b));
|
||||
BOOST_TEST(!test_attr("fasle", backwards_bool, b));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
typedef boost::spirit::x3::bool_parser<test_bool_type, boost::spirit::char_encoding::standard>
|
||||
bool_test_type;
|
||||
struct test_bool_type
|
||||
{
|
||||
test_bool_type(bool b = false) : b(b) {} // provide conversion
|
||||
bool b;
|
||||
};
|
||||
|
||||
using bool_test_type = boost::spirit::x3::bool_parser<test_bool_type, boost::spirit::x3::char_encoding::standard>;
|
||||
constexpr bool_test_type test_bool{};
|
||||
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(test_bool);
|
||||
|
||||
|
||||
BOOST_TEST(test("true", test_bool));
|
||||
BOOST_TEST(test("false", test_bool));
|
||||
BOOST_TEST(!test("fasle", test_bool));
|
||||
|
||||
|
||||
test_bool_type b = false;
|
||||
BOOST_TEST(test_attr("true", test_bool, b) && b.b);
|
||||
BOOST_TEST(test_attr("false", test_bool, b) && !b.b);
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
Copyright (c) 2011 Bryce Lelbach
|
||||
|
||||
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_TEST_QI_BOOL)
|
||||
#define BOOST_SPIRIT_TEST_QI_BOOL
|
||||
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#include "test.hpp"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
struct backwards_bool_policies : boost::spirit::x3::bool_policies<>
|
||||
{
|
||||
// we want to interpret a 'true' spelled backwards as 'false'
|
||||
template <typename Iterator, typename Attribute, typename CaseCompare>
|
||||
static bool
|
||||
parse_false(Iterator& first, Iterator const& last, Attribute& attr, CaseCompare const& case_compare)
|
||||
{
|
||||
namespace spirit = boost::spirit;
|
||||
namespace x3 = boost::spirit::x3;
|
||||
if (x3::detail::string_parse("eurt", first, last, x3::unused, case_compare))
|
||||
{
|
||||
x3::traits::move_to(false, attr); // result is false
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
struct test_bool_type
|
||||
{
|
||||
test_bool_type(bool b = false) : b(b) {} // provide conversion
|
||||
bool b;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,31 +1,32 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
Copyright (c) 2019 Christian Mazakas
|
||||
Copyright (c) 2019 Christian Mazakas
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
=============================================================================*/
|
||||
|
||||
#define BOOST_SPIRIT_UNICODE
|
||||
#define BOOST_SPIRIT_X3_UNICODE
|
||||
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
using spirit_test::test;
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(char_);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(char_('x'));
|
||||
@@ -69,7 +70,7 @@ main()
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
|
||||
BOOST_TEST(test(" x", 'x', space));
|
||||
BOOST_TEST(test(L" x", L'x', space));
|
||||
@@ -125,11 +126,11 @@ main()
|
||||
auto const sub_delims = char_(U"!$&'()*+,;=");
|
||||
|
||||
auto const delims =
|
||||
std::vector<boost::u32string_view>{U"!", U"$", U"&", U"'", U"(", U")", U"*", U"+",
|
||||
std::vector<std::u32string_view>{U"!", U"$", U"&", U"'", U"(", U")", U"*", U"+",
|
||||
U",", U";", U"="};
|
||||
|
||||
auto const matched_all_sub_delims =
|
||||
std::all_of(delims.begin(), delims.end(), [&](auto const delim) -> bool {
|
||||
std::ranges::all_of(delims, [&](auto const delim) -> bool {
|
||||
return test(delim, sub_delims);
|
||||
});
|
||||
|
||||
@@ -143,18 +144,18 @@ main()
|
||||
auto const chars = char_(U"\u0024\u00a2\u0939\u20ac\U00010348");
|
||||
|
||||
auto const test_strings =
|
||||
std::vector<boost::u32string_view>{U"\u0024", U"\u00a2", U"\u0939", U"\u20ac",
|
||||
std::vector<std::u32string_view>{U"\u0024", U"\u00a2", U"\u0939", U"\u20ac",
|
||||
U"\U00010348"};
|
||||
|
||||
auto const bad_test_strings = std::vector<boost::u32string_view>{U"a", U"B", U"c", U"\u0409"};
|
||||
auto const bad_test_strings = std::vector<std::u32string_view>{U"a", U"B", U"c", U"\u0409"};
|
||||
|
||||
auto const all_matched =
|
||||
std::all_of(test_strings.begin(), test_strings.end(), [&](auto const test_str) -> bool {
|
||||
std::ranges::all_of(test_strings, [&](auto const test_str) -> bool {
|
||||
return test(test_str, chars);
|
||||
});
|
||||
|
||||
auto const none_matched =
|
||||
std::all_of(bad_test_strings.begin(), bad_test_strings.end(), [&](auto const bad_test_str) -> bool {
|
||||
std::ranges::all_of(bad_test_strings, [&](auto const bad_test_str) -> bool {
|
||||
return !test(bad_test_str, chars);
|
||||
});
|
||||
|
||||
@@ -164,50 +165,38 @@ main()
|
||||
|
||||
|
||||
{ // single char strings!
|
||||
namespace ascii = boost::spirit::x3::ascii;
|
||||
namespace wide = boost::spirit::x3::standard_wide;
|
||||
namespace standard = boost::spirit::x3::standard;
|
||||
namespace wide = boost::spirit::x3::standard_wide;
|
||||
|
||||
BOOST_TEST(test("x", "x"));
|
||||
BOOST_TEST(test(L"x", L"x"));
|
||||
BOOST_TEST(test("x", ascii::char_("x")));
|
||||
BOOST_TEST(test("x", standard::char_("x")));
|
||||
BOOST_TEST(test(L"x", wide::char_(L"x")));
|
||||
|
||||
BOOST_TEST(test("x", ascii::char_("a", "z")));
|
||||
BOOST_TEST(test("x", standard::char_("a", "z")));
|
||||
BOOST_TEST(test(L"x", wide::char_(L"a", L"z")));
|
||||
}
|
||||
|
||||
{
|
||||
// chsets
|
||||
namespace ascii = boost::spirit::x3::ascii;
|
||||
namespace standard = boost::spirit::x3::standard;
|
||||
namespace wide = boost::spirit::x3::standard_wide;
|
||||
|
||||
BOOST_TEST(test("x", ascii::char_("a-z")));
|
||||
BOOST_TEST(!test("1", ascii::char_("a-z")));
|
||||
BOOST_TEST(test("1", ascii::char_("a-z0-9")));
|
||||
BOOST_TEST(test("x", standard::char_("a-z")));
|
||||
BOOST_TEST(!test("1", standard::char_("a-z")));
|
||||
BOOST_TEST(test("1", standard::char_("a-z0-9")));
|
||||
|
||||
BOOST_TEST(test("x", wide::char_(L"a-z")));
|
||||
BOOST_TEST(!test("1", wide::char_(L"a-z")));
|
||||
BOOST_TEST(test("1", wide::char_(L"a-z0-9")));
|
||||
|
||||
std::string set = "a-z0-9";
|
||||
BOOST_TEST(test("x", ascii::char_(set)));
|
||||
BOOST_TEST(test("x", standard::char_(set)));
|
||||
|
||||
#ifdef SPIRIT_NO_COMPILE_CHECK
|
||||
test("", ascii::char_(L"a-z0-9"));
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
namespace ascii = boost::spirit::x3::ascii;
|
||||
char const* input = "\x80";
|
||||
|
||||
// ascii > 7 bits (this should fail, not assert!)
|
||||
BOOST_TEST(!test(input, ascii::char_));
|
||||
BOOST_TEST(!test(input, ascii::char_('a')));
|
||||
BOOST_TEST(!test(input, ascii::alnum));
|
||||
BOOST_TEST(!test(input, ascii::char_("a-z")));
|
||||
BOOST_TEST(!test(input, ascii::char_('0', '9')));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
Copyright (c) 2001-2010 Hartmut Kaiser
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
=============================================================================*/
|
||||
|
||||
#define BOOST_SPIRIT_UNICODE
|
||||
#define BOOST_SPIRIT_X3_UNICODE
|
||||
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include "test.hpp"
|
||||
|
||||
int
|
||||
main()
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
using spirit_test::test;
|
||||
using spirit_test::test_failure;
|
||||
@@ -23,113 +25,6 @@ main()
|
||||
|
||||
using boost::spirit::x3::unused_type;
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(alnum);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(alpha);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(digit);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(xdigit);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(cntrl);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(graph);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(lower);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(print);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(punct);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(space);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(blank);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(upper);
|
||||
BOOST_TEST(test("1", alnum));
|
||||
BOOST_TEST(!test(" ", alnum));
|
||||
BOOST_TEST(!test("1", alpha));
|
||||
BOOST_TEST(test("x", alpha));
|
||||
BOOST_TEST(test(" ", blank));
|
||||
BOOST_TEST(!test("x", blank));
|
||||
BOOST_TEST(test("1", digit));
|
||||
BOOST_TEST(!test("x", digit));
|
||||
BOOST_TEST(test("a", lower));
|
||||
BOOST_TEST(!test("A", lower));
|
||||
BOOST_TEST(test("!", punct));
|
||||
BOOST_TEST(!test("x", punct));
|
||||
BOOST_TEST(test(" ", space));
|
||||
BOOST_TEST(test("\n", space));
|
||||
BOOST_TEST(test("\r", space));
|
||||
BOOST_TEST(test("\t", space));
|
||||
BOOST_TEST(test("A", upper));
|
||||
BOOST_TEST(!test("a", upper));
|
||||
BOOST_TEST(test("A", xdigit));
|
||||
BOOST_TEST(test("0", xdigit));
|
||||
BOOST_TEST(test("f", xdigit));
|
||||
BOOST_TEST(!test("g", xdigit));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
BOOST_TEST(!test("1", ~alnum));
|
||||
BOOST_TEST(test(" ", ~alnum));
|
||||
BOOST_TEST(test("1", ~alpha));
|
||||
BOOST_TEST(!test("x", ~alpha));
|
||||
BOOST_TEST(!test(" ", ~blank));
|
||||
BOOST_TEST(test("x", ~blank));
|
||||
BOOST_TEST(!test("1", ~digit));
|
||||
BOOST_TEST(test("x", ~digit));
|
||||
BOOST_TEST(!test("a", ~lower));
|
||||
BOOST_TEST(test("A", ~lower));
|
||||
BOOST_TEST(!test("!", ~punct));
|
||||
BOOST_TEST(test("x", ~punct));
|
||||
BOOST_TEST(!test(" ", ~space));
|
||||
BOOST_TEST(!test("\n", ~space));
|
||||
BOOST_TEST(!test("\r", ~space));
|
||||
BOOST_TEST(!test("\t", ~space));
|
||||
BOOST_TEST(!test("A", ~upper));
|
||||
BOOST_TEST(test("a", ~upper));
|
||||
BOOST_TEST(!test("A", ~xdigit));
|
||||
BOOST_TEST(!test("0", ~xdigit));
|
||||
BOOST_TEST(!test("f", ~xdigit));
|
||||
BOOST_TEST(test("g", ~xdigit));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::iso8859_1;
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(alnum);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(alpha);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(digit);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(xdigit);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(cntrl);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(graph);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(lower);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(print);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(punct);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(space);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(blank);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(upper);
|
||||
BOOST_TEST(test("1", alnum));
|
||||
BOOST_TEST(!test(" ", alnum));
|
||||
BOOST_TEST(!test("1", alpha));
|
||||
BOOST_TEST(test("x", alpha));
|
||||
BOOST_TEST(test(" ", blank));
|
||||
BOOST_TEST(!test("x", blank));
|
||||
BOOST_TEST(test("1", digit));
|
||||
BOOST_TEST(!test("x", digit));
|
||||
BOOST_TEST(test("a", lower));
|
||||
BOOST_TEST(!test("A", lower));
|
||||
BOOST_TEST(test("!", punct));
|
||||
BOOST_TEST(!test("x", punct));
|
||||
BOOST_TEST(test(" ", space));
|
||||
BOOST_TEST(test("\n", space));
|
||||
BOOST_TEST(test("\r", space));
|
||||
BOOST_TEST(test("\t", space));
|
||||
BOOST_TEST(test("A", upper));
|
||||
BOOST_TEST(!test("a", upper));
|
||||
BOOST_TEST(test("A", xdigit));
|
||||
BOOST_TEST(test("0", xdigit));
|
||||
BOOST_TEST(test("f", xdigit));
|
||||
BOOST_TEST(!test("g", xdigit));
|
||||
|
||||
// test extended ASCII characters
|
||||
BOOST_TEST(test("\xE9", alpha));
|
||||
BOOST_TEST(test("\xE9", lower));
|
||||
BOOST_TEST(!test("\xE9", upper));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::standard;
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(alnum);
|
||||
@@ -221,42 +116,42 @@ main()
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(space);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(blank);
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(upper);
|
||||
BOOST_TEST(test(L"1", alnum));
|
||||
BOOST_TEST(!test(L" ", alnum));
|
||||
BOOST_TEST(!test(L"1", alpha));
|
||||
BOOST_TEST(test(L"x", alpha));
|
||||
BOOST_TEST(test(L" ", blank));
|
||||
BOOST_TEST(!test(L"x", blank));
|
||||
BOOST_TEST(test(L"1", digit));
|
||||
BOOST_TEST(!test(L"x", digit));
|
||||
BOOST_TEST(test(L"a", lower));
|
||||
BOOST_TEST(!test(L"A", lower));
|
||||
BOOST_TEST(test(L"!", punct));
|
||||
BOOST_TEST(!test(L"x", punct));
|
||||
BOOST_TEST(test(L" ", space));
|
||||
BOOST_TEST(test(L"\n", space));
|
||||
BOOST_TEST(test(L"\r", space));
|
||||
BOOST_TEST(test(L"\t", space));
|
||||
BOOST_TEST(test(L"A", upper));
|
||||
BOOST_TEST(!test(L"a", upper));
|
||||
BOOST_TEST(test(L"A", xdigit));
|
||||
BOOST_TEST(test(L"0", xdigit));
|
||||
BOOST_TEST(test(L"f", xdigit));
|
||||
BOOST_TEST(!test(L"g", xdigit));
|
||||
BOOST_TEST(test(U"1", alnum));
|
||||
BOOST_TEST(!test(U" ", alnum));
|
||||
BOOST_TEST(!test(U"1", alpha));
|
||||
BOOST_TEST(test(U"x", alpha));
|
||||
BOOST_TEST(test(U" ", blank));
|
||||
BOOST_TEST(!test(U"x", blank));
|
||||
BOOST_TEST(test(U"1", digit));
|
||||
BOOST_TEST(!test(U"x", digit));
|
||||
BOOST_TEST(test(U"a", lower));
|
||||
BOOST_TEST(!test(U"A", lower));
|
||||
BOOST_TEST(test(U"!", punct));
|
||||
BOOST_TEST(!test(U"x", punct));
|
||||
BOOST_TEST(test(U" ", space));
|
||||
BOOST_TEST(test(U"\n", space));
|
||||
BOOST_TEST(test(U"\r", space));
|
||||
BOOST_TEST(test(U"\t", space));
|
||||
BOOST_TEST(test(U"A", upper));
|
||||
BOOST_TEST(!test(U"a", upper));
|
||||
BOOST_TEST(test(U"A", xdigit));
|
||||
BOOST_TEST(test(U"0", xdigit));
|
||||
BOOST_TEST(test(U"f", xdigit));
|
||||
BOOST_TEST(!test(U"g", xdigit));
|
||||
|
||||
BOOST_TEST(test(L"A", alphabetic));
|
||||
BOOST_TEST(test(L"9", decimal_number));
|
||||
BOOST_TEST(test(L"\u2800", braille));
|
||||
BOOST_TEST(!test(L" ", braille));
|
||||
BOOST_TEST(test(L" ", ~braille));
|
||||
// $$$ TODO $$$ Add more unicode tests
|
||||
BOOST_TEST(test(U"A", alphabetic));
|
||||
BOOST_TEST(test(U"9", decimal_number));
|
||||
BOOST_TEST(test(U"\u2800", braille));
|
||||
BOOST_TEST(!test(U" ", braille));
|
||||
BOOST_TEST(test(U" ", ~braille));
|
||||
// TODO: Add more unicode tests
|
||||
}
|
||||
|
||||
{ // test invalid unicode literals
|
||||
using namespace boost::spirit::x3::unicode;
|
||||
|
||||
auto const invalid_unicode = char32_t{0x7FFFFFFF};
|
||||
auto const input = boost::u32string_view(&invalid_unicode, 1);
|
||||
auto const input = std::u32string_view(&invalid_unicode, 1);
|
||||
|
||||
BOOST_TEST(test_failure(input, char_));
|
||||
|
||||
@@ -268,16 +163,11 @@ main()
|
||||
}
|
||||
|
||||
{ // test attribute extraction
|
||||
using boost::spirit::x3::traits::attribute_of;
|
||||
using boost::spirit::x3::iso8859_1::alpha;
|
||||
using boost::spirit::x3::iso8859_1::alpha_type;
|
||||
using boost::spirit::x3::traits::attribute_of_t;
|
||||
using boost::spirit::x3::standard::alpha;
|
||||
using boost::spirit::x3::standard::alpha_type;
|
||||
|
||||
static_assert(
|
||||
boost::is_same<
|
||||
attribute_of<alpha_type, unused_type>::type
|
||||
, unsigned char>::value
|
||||
, "Wrong attribute type!"
|
||||
);
|
||||
static_assert(std::is_same_v<attribute_of_t<alpha_type, unused_type>, char>);
|
||||
|
||||
int attr = 0;
|
||||
BOOST_TEST(test_attr("a", alpha, attr));
|
||||
@@ -285,15 +175,15 @@ main()
|
||||
}
|
||||
|
||||
{ // test attribute extraction
|
||||
using boost::spirit::x3::iso8859_1::alpha;
|
||||
using boost::spirit::x3::iso8859_1::space;
|
||||
using boost::spirit::x3::standard::alpha;
|
||||
using boost::spirit::x3::standard::space;
|
||||
char attr = 0;
|
||||
BOOST_TEST(test_attr(" a", alpha, attr, space));
|
||||
BOOST_TEST(attr == 'a');
|
||||
}
|
||||
|
||||
{ // test action
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
using boost::spirit::x3::_attr;
|
||||
char ch;
|
||||
auto f = [&](auto& ctx){ ch = _attr(ctx); };
|
||||
|
||||
162
test/x3/lit.cpp
162
test/x3/lit.cpp
@@ -1,54 +1,164 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
=============================================================================*/
|
||||
|
||||
#undef BOOST_SPIRIT_NO_STANDARD_WIDE
|
||||
|
||||
#ifndef BOOST_SPIRIT_UNICODE
|
||||
# define BOOST_SPIRIT_UNICODE
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_SPIRIT_X3_UNICODE
|
||||
# define BOOST_SPIRIT_X3_UNICODE
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#include <boost/fusion/include/vector.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
namespace x3 = boost::spirit::x3;
|
||||
using spirit_test::test;
|
||||
using spirit_test::test_attr;
|
||||
using boost::spirit::x3::lit;
|
||||
using boost::spirit::x3::char_;
|
||||
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(lit("x"));
|
||||
// standard
|
||||
{
|
||||
(void)x3::lit('f'); // deprecated
|
||||
(void)x3::lit("f"); // deprecated
|
||||
(void)x3::lit("foo"); // deprecated
|
||||
(void)x3::standard::lit('f');
|
||||
(void)x3::standard::lit("f");
|
||||
(void)x3::standard::lit("foo");
|
||||
|
||||
(void)x3::char_('f'); // deprecated
|
||||
(void)x3::char_("f"); // deprecated
|
||||
(void)x3::char_("foo"); // deprecated
|
||||
(void)x3::standard::char_('f');
|
||||
(void)x3::standard::char_("f");
|
||||
(void)x3::standard::char_("foo");
|
||||
|
||||
(void)x3::string('f'); // deprecated
|
||||
(void)x3::string("f"); // deprecated
|
||||
(void)x3::string("foo"); // deprecated
|
||||
(void)x3::standard::string('f');
|
||||
(void)x3::standard::string("f");
|
||||
(void)x3::standard::string("foo");
|
||||
}
|
||||
|
||||
// standard_wide
|
||||
{
|
||||
(void)x3::lit(L'f'); // deprecated
|
||||
(void)x3::lit(L"f"); // deprecated
|
||||
(void)x3::lit(L"foo"); // deprecated
|
||||
(void)x3::standard_wide::lit(L'f');
|
||||
(void)x3::standard_wide::lit(L"f");
|
||||
(void)x3::standard_wide::lit(L"foo");
|
||||
|
||||
(void)x3::standard_wide::char_(L'f');
|
||||
(void)x3::standard_wide::char_(L"f");
|
||||
(void)x3::standard_wide::char_(L"foo");
|
||||
|
||||
(void)x3::string(L'f'); // deprecated
|
||||
(void)x3::string(L"f"); // deprecated
|
||||
(void)x3::string(L"foo"); // deprecated
|
||||
(void)x3::standard_wide::string(L'f');
|
||||
(void)x3::standard_wide::string(L"f");
|
||||
(void)x3::standard_wide::string(L"foo");
|
||||
}
|
||||
|
||||
// unicode
|
||||
{
|
||||
(void)x3::unicode::lit(U'f');
|
||||
(void)x3::unicode::lit(U"f");
|
||||
(void)x3::unicode::lit(U"foo");
|
||||
|
||||
(void)x3::unicode::char_(U'f');
|
||||
(void)x3::unicode::char_(U"f");
|
||||
(void)x3::unicode::char_(U"foo");
|
||||
|
||||
(void)x3::unicode::string(U'f');
|
||||
(void)x3::unicode::string(U"f");
|
||||
(void)x3::unicode::string(U"foo");
|
||||
}
|
||||
|
||||
{
|
||||
std::string attr;
|
||||
auto p = char_ >> lit("\n");
|
||||
auto p = x3::standard::char_ >> x3::standard::lit("\n");
|
||||
BOOST_TEST(test_attr("A\n", p, attr));
|
||||
BOOST_TEST(attr == "A");
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
std::string attr;
|
||||
auto p = char_ >> lit("\n");
|
||||
BOOST_TEST(test_attr("A\n", p, attr));
|
||||
BOOST_TEST(attr == "A");
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::iso8859_1;
|
||||
std::string attr;
|
||||
auto p = char_ >> lit("\n");
|
||||
BOOST_TEST(test_attr("É\n", p, attr));
|
||||
BOOST_TEST(attr == "É");
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::standard_wide;
|
||||
std::wstring attr;
|
||||
auto p = char_ >> lit("\n");
|
||||
BOOST_TEST(test_attr(l"É\n", p, attr));
|
||||
BOOST_TEST(attr == "A");
|
||||
auto p = x3::standard_wide::char_ >> x3::standard_wide::lit(L"\n");
|
||||
BOOST_TEST(test_attr(L"É\n", p, attr));
|
||||
BOOST_TEST(attr == L"É");
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
{
|
||||
BOOST_TEST((test("kimpo", x3::standard::lit("kimpo"))));
|
||||
|
||||
std::basic_string<char> s("kimpo");
|
||||
std::basic_string<wchar_t> ws(L"kimpo");
|
||||
BOOST_TEST((test("kimpo", x3::standard::lit(s))));
|
||||
BOOST_TEST((test(L"kimpo", x3::standard_wide::lit(ws))));
|
||||
}
|
||||
|
||||
{
|
||||
std::basic_string<char> s("kimpo");
|
||||
BOOST_TEST((test("kimpo", x3::standard::lit(s))));
|
||||
|
||||
std::basic_string<wchar_t> ws(L"kimpo");
|
||||
BOOST_TEST((test(L"kimpo", x3::standard_wide::lit(ws))));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
{
|
||||
BOOST_TEST((test("kimpo", "kimpo")));
|
||||
BOOST_TEST((test("kimpo", x3::standard::string("kimpo"))));
|
||||
|
||||
BOOST_TEST((test("x", x3::standard::string("x"))));
|
||||
BOOST_TEST((test(L"x", x3::standard_wide::string(L"x"))));
|
||||
|
||||
std::basic_string<char> s("kimpo");
|
||||
std::basic_string<wchar_t> ws(L"kimpo");
|
||||
BOOST_TEST((test("kimpo", s)));
|
||||
BOOST_TEST((test(L"kimpo", ws)));
|
||||
BOOST_TEST((test("kimpo", x3::standard::string(s))));
|
||||
BOOST_TEST((test(L"kimpo", x3::standard_wide::string(ws))));
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST((test(L"kimpo", L"kimpo")));
|
||||
BOOST_TEST((test(L"kimpo", x3::standard_wide::string(L"kimpo"))));
|
||||
BOOST_TEST((test(L"x", x3::standard_wide::string(L"x"))));
|
||||
}
|
||||
|
||||
{
|
||||
std::basic_string<char> s("kimpo");
|
||||
BOOST_TEST((test("kimpo", x3::standard::string(s))));
|
||||
|
||||
std::basic_string<wchar_t> ws(L"kimpo");
|
||||
BOOST_TEST((test(L"kimpo", x3::standard_wide::string(ws))));
|
||||
}
|
||||
|
||||
{
|
||||
// single-element fusion vector tests
|
||||
boost::fusion::vector<std::string> s;
|
||||
BOOST_TEST(test_attr("kimpo", x3::standard::string("kimpo"), s));
|
||||
BOOST_TEST(boost::fusion::at_c<0>(s) == "kimpo");
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
http://spirit.sourceforge.net/
|
||||
|
||||
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)
|
||||
=============================================================================*/
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#include <boost/fusion/include/vector.hpp>
|
||||
|
||||
#include <string>
|
||||
#include "test.hpp"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using spirit_test::test;
|
||||
using spirit_test::test_attr;
|
||||
using boost::spirit::x3::string;
|
||||
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(string("x"));
|
||||
|
||||
{
|
||||
BOOST_TEST((test("kimpo", "kimpo")));
|
||||
BOOST_TEST((test("kimpo", string("kimpo"))));
|
||||
|
||||
BOOST_TEST((test("x", string("x"))));
|
||||
BOOST_TEST((test(L"x", string(L"x"))));
|
||||
|
||||
std::basic_string<char> s("kimpo");
|
||||
std::basic_string<wchar_t> ws(L"kimpo");
|
||||
BOOST_TEST((test("kimpo", s)));
|
||||
BOOST_TEST((test(L"kimpo", ws)));
|
||||
BOOST_TEST((test("kimpo", string(s))));
|
||||
BOOST_TEST((test(L"kimpo", string(ws))));
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST((test(L"kimpo", L"kimpo")));
|
||||
BOOST_TEST((test(L"kimpo", string(L"kimpo"))));
|
||||
BOOST_TEST((test(L"x", string(L"x"))));
|
||||
}
|
||||
|
||||
{
|
||||
std::basic_string<char> s("kimpo");
|
||||
BOOST_TEST((test("kimpo", string(s))));
|
||||
|
||||
std::basic_string<wchar_t> ws(L"kimpo");
|
||||
BOOST_TEST((test(L"kimpo", string(ws))));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
BOOST_TEST((test(" kimpo", string("kimpo"), space)));
|
||||
BOOST_TEST((test(L" kimpo", string(L"kimpo"), space)));
|
||||
BOOST_TEST((test(" x", string("x"), space)));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
BOOST_TEST((test(" kimpo", string("kimpo"), space)));
|
||||
BOOST_TEST((test(L" kimpo", string(L"kimpo"), space)));
|
||||
BOOST_TEST((test(" x", string("x"), space)));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
std::string s;
|
||||
BOOST_TEST((test_attr("kimpo", string("kimpo"), s)));
|
||||
BOOST_TEST(s == "kimpo");
|
||||
s.clear();
|
||||
BOOST_TEST((test_attr("kimpo", string("kim") >> string("po"), s)));
|
||||
BOOST_TEST(s == "kimpo");
|
||||
s.clear();
|
||||
BOOST_TEST((test_attr(L"kimpo", string(L"kimpo"), s)));
|
||||
BOOST_TEST(s == "kimpo");
|
||||
s.clear();
|
||||
BOOST_TEST((test_attr("x", string("x"), s)));
|
||||
BOOST_TEST(s == "x");
|
||||
}
|
||||
|
||||
{ // single-element fusion vector tests
|
||||
boost::fusion::vector<std::string> s;
|
||||
BOOST_TEST(test_attr("kimpo", string("kimpo"), s));
|
||||
BOOST_TEST(boost::fusion::at_c<0>(s) == "kimpo");
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
http://spirit.sourceforge.net/
|
||||
|
||||
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)
|
||||
=============================================================================*/
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include "test.hpp"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using spirit_test::test;
|
||||
using spirit_test::test_attr;
|
||||
using boost::spirit::x3::lit;
|
||||
|
||||
{
|
||||
BOOST_TEST((test("kimpo", lit("kimpo"))));
|
||||
|
||||
std::basic_string<char> s("kimpo");
|
||||
std::basic_string<wchar_t> ws(L"kimpo");
|
||||
BOOST_TEST((test("kimpo", lit(s))));
|
||||
BOOST_TEST((test(L"kimpo", lit(ws))));
|
||||
}
|
||||
|
||||
{
|
||||
std::basic_string<char> s("kimpo");
|
||||
BOOST_TEST((test("kimpo", lit(s))));
|
||||
|
||||
std::basic_string<wchar_t> ws(L"kimpo");
|
||||
BOOST_TEST((test(L"kimpo", lit(ws))));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
BOOST_TEST((test(" kimpo", lit("kimpo"), space)));
|
||||
BOOST_TEST((test(L" kimpo", lit(L"kimpo"), space)));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::iso8859_1;
|
||||
BOOST_TEST((test(" kimpo", lit("kimpo"), space)));
|
||||
BOOST_TEST((test(L" kimpo", lit(L"kimpo"), space)));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
http://spirit.sourceforge.net/
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
@@ -11,8 +11,7 @@
|
||||
#include <iostream>
|
||||
#include "test.hpp"
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
using spirit_test::test;
|
||||
using spirit_test::test_attr;
|
||||
@@ -21,7 +20,7 @@ main()
|
||||
BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(no_case['x']);
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
BOOST_TEST(test("x", no_case[char_]));
|
||||
BOOST_TEST(test("X", no_case[char_('x')]));
|
||||
BOOST_TEST(test("X", no_case[char_('X')]));
|
||||
@@ -35,7 +34,7 @@ main()
|
||||
BOOST_TEST(!test("z", no_case[char_('a', 'y')]));
|
||||
}
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
BOOST_TEST(test("X", no_case['x']));
|
||||
BOOST_TEST(test("X", no_case['X']));
|
||||
BOOST_TEST(test("x", no_case['X']));
|
||||
@@ -45,24 +44,13 @@ main()
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::iso8859_1;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
BOOST_TEST(test("X", no_case[char_("a-z")]));
|
||||
BOOST_TEST(!test("1", no_case[char_("a-z")]));
|
||||
}
|
||||
|
||||
{ // test extended ASCII characters
|
||||
using namespace boost::spirit::x3::iso8859_1;
|
||||
BOOST_TEST(test("\xC1", no_case[char_('\xE1')]));
|
||||
|
||||
BOOST_TEST(test("\xC9", no_case[char_("\xE5-\xEF")]));
|
||||
BOOST_TEST(!test("\xFF", no_case[char_("\xE5-\xEF")]));
|
||||
|
||||
BOOST_TEST(test("\xC1\xE1", no_case[lit("\xE1\xC1")]));
|
||||
BOOST_TEST(test("\xE1\xE1", no_case[no_case[lit("\xE1\xC1")]]));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
BOOST_TEST(test("Bochi Bochi", no_case[lit("bochi bochi")]));
|
||||
BOOST_TEST(test("BOCHI BOCHI", no_case[lit("bochi bochi")]));
|
||||
BOOST_TEST(!test("Vavoo", no_case[lit("bochi bochi")]));
|
||||
@@ -70,40 +58,12 @@ main()
|
||||
|
||||
{
|
||||
// should work!
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
BOOST_TEST(test("x", no_case[no_case[char_]]));
|
||||
BOOST_TEST(test("x", no_case[no_case[char_('x')]]));
|
||||
BOOST_TEST(test("yabadabadoo", no_case[no_case[lit("Yabadabadoo")]]));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
BOOST_TEST(test("X", no_case[alnum]));
|
||||
BOOST_TEST(test("6", no_case[alnum]));
|
||||
BOOST_TEST(!test(":", no_case[alnum]));
|
||||
|
||||
BOOST_TEST(test("X", no_case[lower]));
|
||||
BOOST_TEST(test("x", no_case[lower]));
|
||||
BOOST_TEST(test("X", no_case[upper]));
|
||||
BOOST_TEST(test("x", no_case[upper]));
|
||||
BOOST_TEST(!test(":", no_case[lower]));
|
||||
BOOST_TEST(!test(":", no_case[upper]));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::iso8859_1;
|
||||
BOOST_TEST(test("X", no_case[alnum]));
|
||||
BOOST_TEST(test("6", no_case[alnum]));
|
||||
BOOST_TEST(!test(":", no_case[alnum]));
|
||||
|
||||
BOOST_TEST(test("X", no_case[lower]));
|
||||
BOOST_TEST(test("x", no_case[lower]));
|
||||
BOOST_TEST(test("X", no_case[upper]));
|
||||
BOOST_TEST(test("x", no_case[upper]));
|
||||
BOOST_TEST(!test(":", no_case[lower]));
|
||||
BOOST_TEST(!test(":", no_case[upper]));
|
||||
}
|
||||
|
||||
{
|
||||
using namespace boost::spirit::x3::standard;
|
||||
BOOST_TEST(test("X", no_case[alnum]));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
@@ -21,16 +22,15 @@ private:
|
||||
char str[2];
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
using spirit_test::test;
|
||||
using spirit_test::test_attr;
|
||||
using boost::spirit::x3::symbols;
|
||||
using boost::spirit::x3::shared_symbols;
|
||||
using boost::spirit::x3::no_case;
|
||||
|
||||
{ // basics
|
||||
symbols<int> sym;
|
||||
shared_symbols<int> sym;
|
||||
|
||||
sym.add
|
||||
("Joel")
|
||||
@@ -52,7 +52,7 @@ main()
|
||||
BOOST_TEST((!test("XXX", sym)));
|
||||
|
||||
// test copy
|
||||
symbols<int> sym2;
|
||||
shared_symbols<int> sym2;
|
||||
sym2 = sym;
|
||||
BOOST_TEST((test("Joel", sym2)));
|
||||
BOOST_TEST((test("Ruby", sym2)));
|
||||
@@ -75,7 +75,7 @@ main()
|
||||
}
|
||||
|
||||
{ // comma syntax
|
||||
symbols<int> sym;
|
||||
shared_symbols<int> sym;
|
||||
sym += "Joel", "Ruby", "Tenji", "Tutit", "Kim", "Joey";
|
||||
|
||||
BOOST_TEST((test("Joel", sym)));
|
||||
@@ -93,9 +93,9 @@ main()
|
||||
}
|
||||
|
||||
{ // no-case handling
|
||||
using namespace boost::spirit::x3::ascii;
|
||||
using namespace boost::spirit::x3::standard;
|
||||
|
||||
symbols<int> sym;
|
||||
shared_symbols<int> sym;
|
||||
// NOTE: make sure all entries are in lower-case!!!
|
||||
sym = "joel", "ruby", "tenji", "tutit", "kim", "joey";
|
||||
|
||||
@@ -118,7 +118,7 @@ main()
|
||||
}
|
||||
|
||||
{ // attributes
|
||||
symbols<int> sym;
|
||||
shared_symbols<int> sym;
|
||||
|
||||
sym.add
|
||||
("Joel", 1)
|
||||
@@ -154,7 +154,7 @@ main()
|
||||
{ // actions
|
||||
using boost::spirit::x3::_attr;
|
||||
|
||||
symbols<int> sym;
|
||||
shared_symbols<int> sym;
|
||||
sym.add
|
||||
("Joel", 1)
|
||||
("Ruby", 2)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2015 Joel de Guzman
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
@@ -9,34 +10,17 @@
|
||||
#include <iostream>
|
||||
#include "test.hpp"
|
||||
|
||||
// Custom string type with a C-style string conversion.
|
||||
struct custom_string_c
|
||||
{
|
||||
custom_string_c(char c) { str[0] = c; str[1] = '\0'; }
|
||||
|
||||
operator char*() { return str; }
|
||||
operator char const*() const { return str; }
|
||||
|
||||
private:
|
||||
char str[2];
|
||||
};
|
||||
|
||||
std::string get_str(char const* str)
|
||||
{
|
||||
return std::string(str);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
using spirit_test::test;
|
||||
using spirit_test::test_attr;
|
||||
using boost::spirit::x3::symbols;
|
||||
using boost::spirit::x3::shared_symbols;
|
||||
using boost::spirit::x3::rule;
|
||||
|
||||
{ // construction from symbol array
|
||||
char const* syms[] = {"Joel","Ruby","Tenji","Tutit","Kim","Joey"};
|
||||
symbols<int> sym(syms);
|
||||
{
|
||||
// construction from symbol array
|
||||
char const* syms[] = {"Joel", "Ruby", "Tenji", "Tutit", "Kim", "Joey"};
|
||||
shared_symbols<int> sym(syms);
|
||||
|
||||
BOOST_TEST((test("Joel", sym)));
|
||||
BOOST_TEST((test("Ruby", sym)));
|
||||
@@ -47,11 +31,12 @@ main()
|
||||
BOOST_TEST((!test("XXX", sym)));
|
||||
}
|
||||
|
||||
{ // construction from 2 arrays
|
||||
{
|
||||
// construction from 2 arrays
|
||||
|
||||
char const* syms[] = {"Joel","Ruby","Tenji","Tutit","Kim","Joey"};
|
||||
int data[] = {1,2,3,4,5,6};
|
||||
symbols<int> sym(syms, data);
|
||||
char const* syms[] = {"Joel", "Ruby", "Tenji", "Tutit", "Kim", "Joey"};
|
||||
int data[] = {1, 2, 3, 4, 5, 6};
|
||||
shared_symbols<int> sym(syms, data);
|
||||
|
||||
int i;
|
||||
BOOST_TEST((test_attr("Joel", sym, i)));
|
||||
@@ -69,8 +54,9 @@ main()
|
||||
BOOST_TEST((!test_attr("XXX", sym, i)));
|
||||
}
|
||||
|
||||
{ // allow std::string and other string types
|
||||
symbols<> sym;
|
||||
{
|
||||
// allow std::string and other string types
|
||||
shared_symbols<> sym;
|
||||
|
||||
// const and non-const std::string
|
||||
std::string a("abc");
|
||||
@@ -88,19 +74,12 @@ main()
|
||||
sym = arr;
|
||||
BOOST_TEST((test("a", sym)));
|
||||
BOOST_TEST((!test("b", sym)));
|
||||
|
||||
// const and non-const custom string type
|
||||
custom_string_c c('x');
|
||||
custom_string_c const cc('y');
|
||||
sym = c, cc;
|
||||
BOOST_TEST((test("x", sym)));
|
||||
BOOST_TEST((test("y", sym)));
|
||||
BOOST_TEST((!test("z", sym)));
|
||||
}
|
||||
|
||||
{ // find
|
||||
{
|
||||
// find
|
||||
|
||||
symbols<int> sym;
|
||||
shared_symbols<int> sym;
|
||||
sym.add("a", 1)("b", 2);
|
||||
|
||||
BOOST_TEST(!sym.find("c"));
|
||||
@@ -116,7 +95,7 @@ main()
|
||||
BOOST_TEST(sym.find("b") && *sym.find("b") == 2);
|
||||
BOOST_TEST(sym.find("c") && *sym.find("c") == 0);
|
||||
|
||||
symbols<int> const_sym(sym);
|
||||
shared_symbols<int> const_sym(sym);
|
||||
|
||||
BOOST_TEST(const_sym.find("a") && *const_sym.find("a") == 1);
|
||||
BOOST_TEST(const_sym.find("b") && *const_sym.find("b") == 2);
|
||||
@@ -132,20 +111,22 @@ main()
|
||||
BOOST_TEST(!sym.prefix_find(first, last) && first == str2);
|
||||
}
|
||||
|
||||
{ // name
|
||||
symbols <int> sym,sym2;
|
||||
{
|
||||
// name
|
||||
shared_symbols<int> sym,sym2;
|
||||
sym.name("test");
|
||||
BOOST_TEST(sym.name()=="test");
|
||||
sym2 = sym;
|
||||
BOOST_TEST(sym2.name()=="test");
|
||||
|
||||
symbols <int> sym3(sym);
|
||||
shared_symbols<int> sym3(sym);
|
||||
BOOST_TEST(sym3.name()=="test");
|
||||
}
|
||||
|
||||
{ // Substrings
|
||||
{
|
||||
// Substrings
|
||||
|
||||
symbols<int> sym;
|
||||
shared_symbols<int> sym;
|
||||
BOOST_TEST(sym.at("foo") == 0);
|
||||
sym.at("foo") = 1;
|
||||
BOOST_TEST(sym.at("foo") == 1);
|
||||
@@ -175,23 +156,22 @@ main()
|
||||
}
|
||||
|
||||
{
|
||||
// remove bug
|
||||
|
||||
std::string s;
|
||||
symbols<double> vars;
|
||||
shared_symbols<double> vars;
|
||||
|
||||
vars.add("l1", 12.0);
|
||||
vars.add("l2", 0.0);
|
||||
vars.remove("l2");
|
||||
vars.find("l1");
|
||||
(void)vars.find("l1");
|
||||
double* d = vars.find("l1");
|
||||
BOOST_TEST(d != 0);
|
||||
BOOST_TEST(d != nullptr);
|
||||
}
|
||||
|
||||
{ // test for proto problem with rvalue references (10-11-2011)
|
||||
symbols<int> sym;
|
||||
sym += get_str("Joel");
|
||||
sym += get_str("Ruby");
|
||||
{
|
||||
// test for proto problem with rvalue references (10-11-2011)
|
||||
shared_symbols<int> sym;
|
||||
sym += std::string("Joel");
|
||||
sym += std::string("Ruby");
|
||||
|
||||
BOOST_TEST((test("Joel", sym)));
|
||||
BOOST_TEST((test("Ruby", sym)));
|
||||
|
||||
@@ -1,30 +1,33 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2013 Carl Barron
|
||||
Copyright (c) 2015 Joel de Guzman
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
=============================================================================*/
|
||||
|
||||
#define BOOST_SPIRIT_X3_DEBUG
|
||||
#define BOOST_SPIRIT_X3_USE_BOOST_OPTIONAL 0
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#include <boost/spirit/home/support/char_encoding/unicode.hpp>
|
||||
#include <boost/fusion/include/at.hpp>
|
||||
#include <boost/fusion/include/vector.hpp>
|
||||
#include <boost/fusion/include/adapt_struct.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <optional>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include "test.hpp"
|
||||
|
||||
struct roman
|
||||
{
|
||||
boost::optional<int> a;
|
||||
boost::optional<int> b;
|
||||
boost::optional<int> c;
|
||||
std::optional<int> a;
|
||||
std::optional<int> b;
|
||||
std::optional<int> c;
|
||||
};
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT(roman,
|
||||
@@ -33,30 +36,29 @@ BOOST_FUSION_ADAPT_STRUCT(roman,
|
||||
|
||||
int eval(roman const & c)
|
||||
{
|
||||
return c.a.get_value_or(0) + c.b.get_value_or(0) + c.c.get_value_or(0);
|
||||
return c.a.value_or(0) + c.b.value_or(0) + c.c.value_or(0);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
int main()
|
||||
{
|
||||
using spirit_test::test;
|
||||
using spirit_test::test_attr;
|
||||
using boost::spirit::x3::symbols;
|
||||
using boost::spirit::x3::shared_symbols;
|
||||
|
||||
{ // construction from initializer-list
|
||||
symbols<int> const ones =
|
||||
shared_symbols<int> const ones =
|
||||
{
|
||||
{"I", 1}, {"II", 2}, {"III", 3}, {"IV", 4},
|
||||
{"V", 5}, {"VI", 6}, {"VII", 7}, {"VIII", 8},
|
||||
{"IX", 9}
|
||||
};
|
||||
symbols<int> const tens =
|
||||
shared_symbols<int> const tens =
|
||||
{
|
||||
{"X", 10}, {"XX", 20}, {"XXX", 30}, {"XL", 40},
|
||||
{"L", 50}, {"LX", 60}, {"LXX", 70}, {"LXXX", 80},
|
||||
{"XC", 90}
|
||||
};
|
||||
symbols<int> const hundreds
|
||||
shared_symbols<int> const hundreds
|
||||
{
|
||||
{"C", 100}, {"CC", 200}, {"CCC", 300}, {"CD", 400},
|
||||
{"D", 500}, {"DC", 600}, {"DCC", 700}, {"DCCC", 800},
|
||||
@@ -71,13 +73,13 @@ main()
|
||||
}
|
||||
|
||||
{ // construction from initializer-list without attribute
|
||||
symbols<> foo = {"a1", "a2", "a3"};
|
||||
shared_symbols<> foo = {"a1", "a2", "a3"};
|
||||
|
||||
BOOST_TEST((test("a3", foo)));
|
||||
}
|
||||
|
||||
{ // assignment from initializer-list
|
||||
symbols<> foo;
|
||||
shared_symbols<> foo;
|
||||
foo = {"a1", "a2", "a3"};
|
||||
|
||||
BOOST_TEST((test("a3", foo)));
|
||||
@@ -85,7 +87,7 @@ main()
|
||||
|
||||
{ // unicode | construction from initializer-list
|
||||
using namespace boost::spirit;
|
||||
x3::symbols_parser<char_encoding::unicode, int> foo = {{U"a1", 1}, {U"a2", 2}, {U"a3", 3}};
|
||||
x3::shared_symbols_parser<char_encoding::unicode, int> foo = {{U"a1", 1}, {U"a2", 2}, {U"a3", 3}};
|
||||
|
||||
int r;
|
||||
BOOST_TEST((test_attr(U"a3", foo, r)));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2013 Joel de Guzman
|
||||
Copyright (c) 2025 Nana Sakisaka
|
||||
|
||||
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)
|
||||
@@ -10,13 +11,16 @@
|
||||
#include <boost/spirit/home/x3/core/parse.hpp>
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
#include <string_view>
|
||||
#include <iostream>
|
||||
|
||||
namespace spirit_test
|
||||
{
|
||||
template <typename Char, typename Parser>
|
||||
bool test(Char const* in, Parser const& p, bool full_match = true)
|
||||
[[nodiscard]] bool test(
|
||||
Char const* in, Parser const& p, bool full_match = true
|
||||
)
|
||||
{
|
||||
Char const* last = in;
|
||||
while (*last)
|
||||
@@ -25,9 +29,11 @@ namespace spirit_test
|
||||
&& (!full_match || (in == last));
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser>
|
||||
bool test(boost::basic_string_view<Char, std::char_traits<Char>> in,
|
||||
Parser const& p, bool full_match = true)
|
||||
template <typename Char, typename CharTraits, typename Parser>
|
||||
[[nodiscard]] bool test(
|
||||
std::basic_string_view<Char, CharTraits> in,
|
||||
Parser const& p, bool full_match = true
|
||||
)
|
||||
{
|
||||
auto const last = in.end();
|
||||
auto pos = in.begin();
|
||||
@@ -36,8 +42,10 @@ namespace spirit_test
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser, typename Skipper>
|
||||
bool test(Char const* in, Parser const& p
|
||||
, Skipper const& s, bool full_match = true)
|
||||
[[nodiscard]] bool test(
|
||||
Char const* in, Parser const& p,
|
||||
Skipper const& s, bool full_match = true
|
||||
)
|
||||
{
|
||||
Char const* last = in;
|
||||
while (*last)
|
||||
@@ -47,7 +55,7 @@ namespace spirit_test
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser>
|
||||
bool test_failure(Char const* in, Parser const& p)
|
||||
[[nodiscard]] bool test_failure(Char const* in, Parser const& p)
|
||||
{
|
||||
Char const * const start = in;
|
||||
Char const* last = in;
|
||||
@@ -57,17 +65,20 @@ namespace spirit_test
|
||||
return !boost::spirit::x3::parse(in, last, p) && (in == start);
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser>
|
||||
bool test_failure(boost::basic_string_view<Char, std::char_traits<Char>> const in,
|
||||
Parser const& p)
|
||||
template <typename Char, typename CharTraits, typename Parser>
|
||||
[[nodiscard]] bool test_failure(
|
||||
std::basic_string_view<Char, CharTraits> const in, Parser const& p
|
||||
)
|
||||
{
|
||||
auto pos = in.begin();
|
||||
return !boost::spirit::x3::parse(pos, in.end(), p) && (pos == in.begin());
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser, typename Attr>
|
||||
bool test_attr(Char const* in, Parser const& p
|
||||
, Attr& attr, bool full_match = true)
|
||||
[[nodiscard]] bool test_attr(
|
||||
Char const* in, Parser const& p,
|
||||
Attr& attr, bool full_match = true
|
||||
)
|
||||
{
|
||||
Char const* last = in;
|
||||
while (*last)
|
||||
@@ -77,8 +88,10 @@ namespace spirit_test
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser, typename Attr, typename Skipper>
|
||||
bool test_attr(Char const* in, Parser const& p
|
||||
, Attr& attr, Skipper const& s, bool full_match = true)
|
||||
[[nodiscard]] bool test_attr(
|
||||
Char const* in, Parser const& p,
|
||||
Attr& attr, Skipper const& s, bool full_match = true
|
||||
)
|
||||
{
|
||||
Char const* last = in;
|
||||
while (*last)
|
||||
@@ -88,8 +101,10 @@ namespace spirit_test
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser>
|
||||
bool binary_test(Char const* in, std::size_t size, Parser const& p,
|
||||
bool full_match = true)
|
||||
[[nodiscard]] bool binary_test(
|
||||
Char const* in, std::size_t size, Parser const& p,
|
||||
bool full_match = true
|
||||
)
|
||||
{
|
||||
Char const* last = in + size;
|
||||
return boost::spirit::x3::parse(in, last, p)
|
||||
@@ -97,8 +112,10 @@ namespace spirit_test
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser, typename Skipper>
|
||||
bool binary_test(Char const* in, std::size_t size, Parser const& p,
|
||||
Skipper const& s, bool full_match = true)
|
||||
[[nodiscard]] bool binary_test(
|
||||
Char const* in, std::size_t size, Parser const& p,
|
||||
Skipper const& s, bool full_match = true
|
||||
)
|
||||
{
|
||||
Char const* last = in + size;
|
||||
return boost::spirit::x3::phrase_parse(in, last, p, s)
|
||||
@@ -106,8 +123,10 @@ namespace spirit_test
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser, typename Attr>
|
||||
bool binary_test_attr(Char const* in, std::size_t size, Parser const& p,
|
||||
Attr& attr, bool full_match = true)
|
||||
[[nodiscard]] bool binary_test_attr(
|
||||
Char const* in, std::size_t size, Parser const& p,
|
||||
Attr& attr, bool full_match = true
|
||||
)
|
||||
{
|
||||
Char const* last = in + size;
|
||||
return boost::spirit::x3::parse(in, last, p, attr)
|
||||
@@ -115,20 +134,21 @@ namespace spirit_test
|
||||
}
|
||||
|
||||
template <typename Char, typename Parser, typename Attr, typename Skipper>
|
||||
bool binary_test_attr(Char const* in, std::size_t size, Parser const& p,
|
||||
Attr& attr, Skipper const& s, bool full_match = true)
|
||||
[[nodiscard]] bool binary_test_attr(
|
||||
Char const* in, std::size_t size, Parser const& p,
|
||||
Attr& attr, Skipper const& s, bool full_match = true
|
||||
)
|
||||
{
|
||||
Char const* last = in + size;
|
||||
return boost::spirit::x3::phrase_parse(in, last, p, s, attr)
|
||||
&& (!full_match || (in == last));
|
||||
}
|
||||
|
||||
|
||||
template <typename... T>
|
||||
constexpr bool always_true(T&&...) { return true; }
|
||||
[[nodiscard]] constexpr bool always_true(T&&...) { return true; }
|
||||
|
||||
template <typename Parser>
|
||||
constexpr bool test_ctors(Parser const& p)
|
||||
[[nodiscard]] constexpr bool test_ctors(Parser const& p)
|
||||
{
|
||||
return always_true(
|
||||
static_cast<Parser>(static_cast<Parser&&>( // test move ctor
|
||||
|
||||
Reference in New Issue
Block a user