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
14 changes: 2 additions & 12 deletions include/iris/x4/attribute/as.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <concepts>
#include <iterator>
#include <string>
#include <format>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -79,7 +78,6 @@ struct as_type_parser : unary_parser<as_type_parser<T, Subject>, Subject>
requires std::same_as<std::remove_const_t<OuterAttr>, T>
[[nodiscard]] constexpr bool
parse(It& first, Se const& last, Context const& ctx, OuterAttr& outer_attr) const
noexcept(is_nothrow_parsable_v<Subject, It, Se, typename detail::as_type_parser_ctx_impl<Subject::has_action, Context, OuterAttr>::type, exposed_attr_for_child_t<OuterAttr>>)
{
if constexpr (Subject::has_action) {
return this->subject.parse(first, last, x4::replace_first_context<contexts::as_var>(ctx, outer_attr), unused);
Expand All @@ -94,7 +92,6 @@ struct as_type_parser : unary_parser<as_type_parser<T, Subject>, Subject>
(!std::same_as<std::remove_const_t<OuterAttr>, T>)
[[nodiscard]] constexpr bool
parse(It& first, Se const& last, Context const& ctx, OuterAttr&) const
noexcept(is_nothrow_parsable_v<Subject, It, Se, typename detail::as_type_parser_ctx_impl<Subject::has_action, Context, unused_type>::type, unused_type>)
{
if constexpr (Subject::has_action) {
return this->subject.parse(first, last, x4::replace_first_context<contexts::as_var>(ctx, unused), unused);
Expand All @@ -109,10 +106,6 @@ struct as_type_parser : unary_parser<as_type_parser<T, Subject>, Subject>
(!std::same_as<std::remove_const_t<OuterAttr>, T>)
[[nodiscard]] constexpr bool
parse(It& first, Se const& last, Context const& ctx, OuterAttr& outer_attr) const
noexcept(
is_nothrow_parsable_v<Subject, It, Se, typename detail::as_type_parser_ctx_impl<Subject::has_action, Context, T>::type, exposed_attr_for_child_t<T>> &&
noexcept(x4::move_to(std::declval<T>(), outer_attr))
)
{
// Ideally we should default to default-initialization and avoid value-initialization.
// However, there is currently no way to determine whether the attribute is ever touched
Expand All @@ -135,11 +128,8 @@ struct as_type_parser : unary_parser<as_type_parser<T, Subject>, Subject>

[[nodiscard]] /*constexpr*/ std::string get_x4_info() const
{
return std::format(
"as<{}>({})",
typeid(T).name(),
get_info<Subject>{}(this->subject)
);
return std::string("as<") + typeid(T).name() + ">("
+ get_info<Subject>{}(this->subject) + ')';
}
};

Expand Down
9 changes: 2 additions & 7 deletions include/iris/x4/attribute/smart_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <type_traits>
#include <utility>
#include <memory>
#include <format>

namespace iris::x4 {

Expand Down Expand Up @@ -95,7 +94,6 @@ struct unique_ptr_parser_base
template<std::forward_iterator It, std::sentinel_for<It> Se, class Context, X4Attribute Attr>
[[nodiscard]] constexpr bool
parse(It& it, Se const& se, Context const& ctx, Attr& ptr) const
noexcept(false) // never noexcept; requires dynamic memory allocation
{
static_assert(std::same_as<typename Attr::deleter_type, DeleterT>, "Incompatible deleter type provided for unique_ptr_parser");

Expand All @@ -122,7 +120,6 @@ struct unique_ptr_parser_base<Derived, Subject, T, std::default_delete<T>>
template<std::forward_iterator It, std::sentinel_for<It> Se, class Context, X4Attribute Attr>
[[nodiscard]] constexpr bool
parse(It& it, Se const& se, Context const& ctx, Attr& ptr) const
noexcept(false) // never noexcept; requires dynamic memory allocation
{
static_assert(std::same_as<typename Attr::deleter_type, std::default_delete<T>>, "Incompatible deleter type provided for unique_ptr_parser");

Expand Down Expand Up @@ -158,7 +155,7 @@ struct unique_ptr_parser : detail::unique_ptr_parser_base<

[[nodiscard]] constexpr std::string get_x4_info() const
{
return std::format("unique_ptr({})", get_info<Subject>{}(this->subject));
return "unique_ptr(" + get_info<Subject>{}(this->subject) + ')';
}
};

Expand Down Expand Up @@ -260,7 +257,6 @@ struct shared_ptr_parser_base
template<std::forward_iterator It, std::sentinel_for<It> Se, class Context, X4Attribute Attr>
[[nodiscard]] constexpr bool
parse(It& it, Se const& se, Context const& ctx, Attr& ptr) const
noexcept(false) // never noexcept; requires dynamic memory allocation
{
bool parse_ok = false;
auto old_ptr = std::exchange(ptr, std::shared_ptr<T>(new T(), deleter_));
Expand Down Expand Up @@ -294,7 +290,6 @@ struct shared_ptr_parser_base<Derived, Subject, T, std::default_delete<T>>
template<std::forward_iterator It, std::sentinel_for<It> Se, class Context, X4Attribute Attr>
[[nodiscard]] constexpr bool
parse(It& it, Se const& se, Context const& ctx, Attr& ptr) const
noexcept(false) // never noexcept; requires dynamic memory allocation
{
bool parse_ok = false;
auto old_ptr = std::exchange(ptr, std::make_shared<T>());
Expand Down Expand Up @@ -328,7 +323,7 @@ struct shared_ptr_parser : detail::shared_ptr_parser_base<

[[nodiscard]] constexpr std::string get_x4_info() const
{
return std::format("shared_ptr({})", get_info<Subject>{}(this->subject));
return "shared_ptr(" + get_info<Subject>{}(this->subject) + ')';
}
};

Expand Down
12 changes: 4 additions & 8 deletions include/iris/x4/char/char_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <iris/unicode/string.hpp>

#include <string_view>
#include <format>
#include <ranges>
#include <type_traits>

Expand Down Expand Up @@ -53,13 +52,11 @@ struct char_range : char_parser<char_range<Encoding, Attr>, Encoding>

[[nodiscard]] std::string get_x4_info() const
{
// TODO: make more user-friendly && make the format consistent with above
// TODO: escape
return std::format(
"char_range \"{}-{}\"",
iris::unicode::transcode<char>(typename Encoding::string_type(1, this->from)),
iris::unicode::transcode<char>(typename Encoding::string_type(1, this->to))
);
return std::string("char_(\"")
+ iris::unicode::transcode<char>(typename Encoding::string_type(1, this->from))
+ '-' + iris::unicode::transcode<char>(typename Encoding::string_type(1, this->to))
+ "\")";
}
};

Expand All @@ -74,7 +71,6 @@ struct char_set : char_parser<char_set<Encoding, Attr>, Encoding>
static constexpr bool has_attribute = !std::is_same_v<unused_type, attribute_type>;

constexpr explicit char_set(std::basic_string_view<char_type> const str)
// never noexcept; requires vector insertion
{
for (auto definition = std::ranges::begin(str); definition != std::ranges::end(str);) {
auto const ch = *definition;
Expand Down
6 changes: 1 addition & 5 deletions include/iris/x4/char/literal_char.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <iris/unicode/string.hpp>

#include <format>
#include <type_traits>
#include <concepts>

Expand Down Expand Up @@ -56,10 +55,7 @@ struct literal_char : char_parser<literal_char<Encoding, Attr>, Encoding>
[[nodiscard]] std::string get_x4_info() const
{
// TODO: escape quote
return std::format(
"'{}'",
iris::unicode::transcode<char>(typename Encoding::string_type(1, this->classify_ch_))
);
return '\'' + iris::unicode::transcode<char>(typename Encoding::string_type(1, this->classify_ch_)) + '\'';
}

private:
Expand Down
19 changes: 1 addition & 18 deletions include/iris/x4/core/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <concepts>
#include <type_traits>
#include <utility>
#include <format>

namespace iris::x4 {

Expand Down Expand Up @@ -91,10 +90,6 @@ struct action : proxy_parser<action<Subject, ActionF>, Subject>
template<std::forward_iterator It, std::sentinel_for<It> Se, class Context, X4UnusedAttribute UnusedAttr>
[[nodiscard]] constexpr bool
parse(It& first, Se const& last, Context const& ctx, UnusedAttr&) const
noexcept(
std::is_nothrow_default_constructible_v<typename base_type::attribute_type> &&
noexcept(this->parse_main(first, last, ctx, std::declval<typename base_type::attribute_type&>()))
)
{
typename base_type::attribute_type attr_temp{}; // value-initialize
return this->parse_main(first, last, ctx, attr_temp);
Expand Down Expand Up @@ -125,7 +120,6 @@ struct action : proxy_parser<action<Subject, ActionF>, Subject>
requires can_pass_exposed_attr<Attr>
[[nodiscard]] constexpr bool
parse(It& first, Se const& last, Context const& ctx, Attr& attr) const
noexcept(noexcept(this->parse_main(first, last, ctx, attr)))
{
return this->parse_main(first, last, ctx, attr);
}
Expand All @@ -135,10 +129,6 @@ struct action : proxy_parser<action<Subject, ActionF>, Subject>
requires (!can_pass_exposed_attr<Attr>)
[[nodiscard]] constexpr bool
parse(It& first, Se const& last, Context const& ctx, Attr& /* attr is discarded */) const
noexcept(
std::is_nothrow_default_constructible_v<typename base_type::attribute_type> &&
noexcept(this->parse_main(first, last, ctx, std::declval<typename base_type::attribute_type&>()))
)
{
typename base_type::attribute_type attr_temp{}; // value-initialize
return this->parse_main(first, last, ctx, attr_temp);
Expand All @@ -148,15 +138,14 @@ struct action : proxy_parser<action<Subject, ActionF>, Subject>

[[nodiscard]] constexpr std::string get_x4_info() const
{
return std::format("{}[f]", get_info<Subject>{}(this->subject));
return get_info<Subject>{}(this->subject) + "[f]";
}

private:
// Semantic action with no parameter: `p[([] { /* ... */ })]`
template<class Context, X4Attribute Attr>
[[nodiscard]] constexpr bool
call_action(Context const&, Attr&) const
noexcept(is_nothrow_directly_invocable_v<ActionF const&>)
{
// Explicitly make this hard error instead of emitting "no matching overload".
// This provides much more human-friendly errors.
Expand Down Expand Up @@ -187,7 +176,6 @@ struct action : proxy_parser<action<Subject, ActionF>, Subject>
requires directly_invocable<ActionF const&, typename detail::action_context<Context, Attr>::type>
[[nodiscard]] constexpr bool
call_action(Context const& ctx, Attr& attr) const
noexcept(is_nothrow_directly_invocable_v<ActionF const&, typename detail::action_context<Context, Attr>::type>)
{
using action_return_type = directly_invoke_result_t<ActionF const&, typename detail::action_context<Context, Attr>::type>;
constexpr bool action_returns_bool = std::same_as<action_return_type, bool>;
Expand Down Expand Up @@ -232,11 +220,6 @@ struct action : proxy_parser<action<Subject, ActionF>, Subject>
template<std::forward_iterator It, std::sentinel_for<It> Se, class Context, X4Attribute Attr>
[[nodiscard]] constexpr bool
parse_main(It& first, Se const& last, Context const& ctx, Attr& attr) const
noexcept(
std::is_copy_assignable_v<It> &&
is_nothrow_parsable_v<Subject, It, Se, Context, Attr> &&
noexcept(this->call_action(ctx, attr))
)
{
It const saved_first = first;
if (!this->subject.parse(first, last, ctx, attr)) return false;
Expand Down
19 changes: 2 additions & 17 deletions include/iris/x4/core/detail/parse_alternative.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,7 @@ template<class Parser, std::forward_iterator It, std::sentinel_for<It> Se, class
parse_alternative(
Parser const& p, It& first, Se const& last,
Context const& ctx, Attr& attribute
) noexcept(
is_nothrow_parsable_v<
Parser, It, Se, Context,
std::remove_reference_t<typename pass_variant_attribute<Parser, Attr>::type>
>
)
{
) {
return p.parse(first, last, ctx, pass_variant_attribute<Parser, Attr>::call(attribute));
}

Expand All @@ -177,16 +171,7 @@ template<class Parser, std::forward_iterator It, std::sentinel_for<It> Se, class
parse_alternative(
Parser const& p, It& first, Se const& last,
Context const& ctx, Attr& attribute
) noexcept(
is_nothrow_parsable_v<
Parser, It, Se, Context, std::remove_reference_t<typename pass_variant_attribute<Parser, Attr>::type>
> &&
noexcept(x4::move_to(
std::declval<typename pass_variant_attribute<Parser, Attr>::type>(),
attribute
))
)
{
) {
auto&& actual_attr = pass_variant_attribute<Parser, Attr>::call(attribute);
if (!p.parse(first, last, ctx, actual_attr)) return false;
x4::move_to(std::move(actual_attr), attribute);
Expand Down
16 changes: 4 additions & 12 deletions include/iris/x4/core/detail/parse_into_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#include <iris/config.hpp>
#include <iris/config.hpp> // IWYU pragma: keep

#include <iris/x4/core/parser.hpp>
#include <iris/x4/core/attribute.hpp>
#include <iris/x4/core/container_appender.hpp>

#include <iris/x4/traits/container_traits.hpp>
Expand Down Expand Up @@ -64,7 +64,6 @@ struct parse_into_container_impl_default
{
template<std::forward_iterator It, std::sentinel_for<It> Se, class Context, X4NonUnusedAttribute Attr>
static constexpr bool call(Parser const& parser, It& first, Se const& last, Context& ctx, Attr& attr)
// never noexcept (requires container insertion)
{
using unwrapped_attribute_type = iris::unwrap_recursive_t<Attr>;
auto& unwrapped_attr = iris::unwrap_recursive(attr);
Expand All @@ -88,7 +87,6 @@ struct parse_into_container_impl_default
// attribute is single element tuple-like; unwrap and try again
return parse_into_container_impl_default<Parser>::call(parser, first, last, ctx, alloy::get<0>(unwrapped_attr));
} else {
//attr = nullptr;
static_assert(false, "[BUG] parse_into_container accepts a container, a variant of container or a single element tuple-like of container");
return false;
}
Expand All @@ -102,22 +100,16 @@ struct parse_into_container_impl
: parse_into_container_impl_default<Parser>
{};

template<class Parser, class It, class Se, class Context, class Attr>
struct parse_into_container_noexcept : std::false_type {};

template<class Parser, class It, class Se, class Context, class Attr>
requires X4UnusedAttribute<Attr> || (!has_attribute_v<Parser>)
struct parse_into_container_noexcept<Parser, It, Se, Context, Attr> : is_nothrow_parsable<Parser, It, Se, Context, unused_type> {};

template<class Parser, std::forward_iterator It, std::sentinel_for<It> Se, class Context, X4Attribute Attr>
[[nodiscard]] constexpr bool
parse_into_container(
Parser const& parser, It& first, Se const& last,
Context const& ctx, Attr& attr
) noexcept(parse_into_container_noexcept<Parser, It, Se, Context, Attr>::value)
)
{
if constexpr (X4UnusedAttribute<Attr> || !has_attribute_v<Parser>) { // handle unused types first
return parser.parse(first, last, ctx, unused);

} else {
if constexpr (traits::is_variant_v<Attr>) {
// e.g. `char` when the caller is `+char_`
Expand Down
Loading
Loading