Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/iris/x4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include <iris/x4/attribute.hpp>
#include <iris/x4/char.hpp>
#include <iris/x4/directive.hpp>
#include <iris/x4/rule.hpp>
#include <iris/x4/numeric.hpp>
#include <iris/x4/operator.hpp>
#include <iris/x4/string.hpp>
#include <iris/x4/rule.hpp>

#include <iris/x4/debug/print_attribute.hpp>
#include <iris/x4/debug/default_error_handler.hpp>

#include <iris/x4/parse.hpp>

#endif
15 changes: 0 additions & 15 deletions include/iris/x4/char/char_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,6 @@ IRIS_X4_CHAR_CLASSES(standard_wide)
#undef IRIS_X4_CHAR_CLASS
#undef IRIS_X4_CHAR_CLASSES

// Don't put these in namespace `parsers`, these are too much

using x4::standard::alnum;
using x4::standard::alpha;
using x4::standard::digit;
using x4::standard::xdigit;
using x4::standard::cntrl;
using x4::standard::graph;
using x4::standard::lower;
using x4::standard::print;
using x4::standard::punct;
using x4::standard::space;
using x4::standard::blank;
using x4::standard::upper;


namespace detail {

Expand Down
33 changes: 32 additions & 1 deletion include/iris/x4/operator/alternative.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ struct to_alternative_attribute_list<rvariant<Ts...>>

// -------------------------------------------------------------

template<class T, class Wrapped>
struct alternative_wrapped_entry {};

template<class T>
struct alternative_entry {};

template<class T>
requires is_recursive_wrapper_v<T>
struct alternative_entry<T>
: alternative_wrapped_entry<unwrap_recursive_t<T>, T>
{};

template<class... Ts>
struct alternative_entries
: alternative_entry<Ts>...
{};

template<class T, class Wrapped>
Wrapped alternative_wrapped_form(alternative_wrapped_entry<unwrap_recursive_t<T>, Wrapped>*);

template<class T>
T alternative_wrapped_form(...);

template<class TypeList>
struct unique_alternative_list;

template<class... Ts>
struct unique_alternative_list<type_list<Ts...>>
: unique_type_list<type_list<decltype(detail::alternative_wrapped_form<Ts>(static_cast<alternative_entries<Ts...>*>(nullptr)))...>>
{};

template<class TypeList>
struct canonicalize_alternative_attribute;

Expand Down Expand Up @@ -87,7 +118,7 @@ struct alternative_layout<P0, PRest...>
typename to_alternative_attribute_list<typename parser_traits<P0>::attribute_type>::type,
typename to_alternative_attribute_list<typename parser_traits<PRest>::attribute_type>::type...
>::type;
using unique_attrs = unique_type_list<concated_attrs>::type;
using unique_attrs = unique_alternative_list<typename unique_type_list<concated_attrs>::type>::type;
using attribute_type = canonicalize_alternative_attribute<unique_attrs>::type;

// All branches share one attribute type and one slot count; the
Expand Down
4 changes: 3 additions & 1 deletion test/x4/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
TEST_CASE("action")
{
using x4::int_;
using x4::standard::digit;
using x4::standard::space;

IRIS_X4_ASSERT_CONSTEXPR_CTORS(x4::int_.on_match(std::true_type{}));

Expand All @@ -35,7 +37,7 @@ TEST_CASE("action")
next = x4::_attr(ctx);
};

REQUIRE(parse(input, x4::int_.on_match(fail) | x4::digit.on_match(setnext), x4::space).is_partial_match());
REQUIRE(parse(input, int_.on_match(fail) | digit.on_match(setnext), space).is_partial_match());
CHECK(next == '1');
}

Expand Down
16 changes: 16 additions & 0 deletions test/x4/alternative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

#include <iris/x4/rule.hpp>

#include <iris/x4/attribute/as.hpp>
#include <iris/x4/attribute/value.hpp>
#include <iris/x4/primitive/eps.hpp>

#include <iris/x4/char/char.hpp>
#include <iris/x4/char/char_class.hpp>
#include <iris/x4/char_string_literal.hpp>
#include <iris/x4/numeric/bool.hpp>
#include <iris/x4/numeric/int.hpp>
Expand Down Expand Up @@ -91,6 +93,20 @@ TEST_CASE("alternative")
STATIC_CHECK(std::same_as<x4::parser_traits<decltype(int_ | double_ | (int_ | double_))>::attribute_type, rvariant<int, double>>);
STATIC_CHECK(std::same_as<x4::parser_traits<decltype(int_ | double_ | (double_ | int_))>::attribute_type, rvariant<int, double>>);

{
// `T` and `recursive_wrapper<T>` are one alternative; the wrapped form is kept, at the first position
using iris::recursive_wrapper;
using x4::as;
using x4::standard::alpha;
constexpr auto plain = as<di_include>(+alpha);
constexpr auto wrapped = as<recursive_wrapper<di_include>>(lit('#') >> +alpha);

STATIC_CHECK(std::same_as<x4::parser_traits<decltype(plain | wrapped)>::attribute_type, recursive_wrapper<di_include>>);
STATIC_CHECK(std::same_as<x4::parser_traits<decltype(wrapped | plain)>::attribute_type, recursive_wrapper<di_include>>);
STATIC_CHECK(std::same_as<x4::parser_traits<decltype(plain | int_ | wrapped)>::attribute_type, rvariant<recursive_wrapper<di_include>, int>>);
STATIC_CHECK(std::same_as<x4::parser_traits<decltype(int_ | wrapped | plain)>::attribute_type, rvariant<int, recursive_wrapper<di_include>>>);
}

IRIS_X4_ASSERT_CONSTEXPR_CTORS(char_ | char_);

{
Expand Down
8 changes: 4 additions & 4 deletions test/x4/kleene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
TEST_CASE("kleene")
{
using x4::char_;
using x4::alpha;
using x4::upper;
using x4::space;
using x4::digit;
using x4::standard::alpha;
using x4::standard::upper;
using x4::standard::space;
using x4::standard::digit;
using x4::int_;
using x4::lexeme;

Expand Down
2 changes: 1 addition & 1 deletion test/x4/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct minimal_binary_unused_parser

TEST_CASE("parser")
{
using x4::blank;
using x4::standard::blank;

{
using It = std::string_view::const_iterator;
Expand Down
8 changes: 4 additions & 4 deletions test/x4/plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
TEST_CASE("plus")
{
using x4::char_;
using x4::alpha;
using x4::upper;
using x4::space;
using x4::digit;
using x4::standard::alpha;
using x4::standard::upper;
using x4::standard::space;
using x4::standard::digit;
using x4::no_case;
using x4::int_;
using x4::omit;
Expand Down
Loading