Skip to content
Merged
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
12 changes: 6 additions & 6 deletions include/iris/x4/attribute/as.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#include <iris/x4/traits/container_traits.hpp>

#include <iris/x4/core/detail/strict_attribute_parser.hpp>
#include <iris/x4/core/traits/tuple_traits.hpp>
#include <iris/x4/core/parser.hpp>
#include <iris/x4/core/unused.hpp>
#include <iris/x4/core/traits/tuple_traits.hpp>
#include <iris/x4/core/traits/write_rank.hpp>
#include <iris/x4/core/write_attribute.hpp>
#include <iris/x4/traits/container_traits.hpp>
#include <iris/x4/core/context.hpp>
#include <iris/x4/core/action_context.hpp>

Expand Down Expand Up @@ -88,7 +88,7 @@ struct as_type_parser : unary_parser<as_type_parser<T, Subject>, Subject>
} else {
if (!this->subject.parse(first, last, ctx, attr_)) return false;
}
planner::pass_declared_attribute(outer_attr, std::move(attr_));
detail::pass_declared_attribute(outer_attr, std::move(attr_));
return true;
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ struct as_type_parser : unary_parser<as_type_parser<T, Subject>, Subject>
} else {
if (!this->subject.parse(first, last, ctx, attr_)) return false;
}
planner::pass_declared_attribute(outer_attr, iris::unwrap_recursive(std::move(attr_)));
detail::pass_declared_attribute(outer_attr, iris::unwrap_recursive(std::move(attr_)));
return true;
}
}
Expand Down
47 changes: 47 additions & 0 deletions include/iris/x4/core/detail/strict_attribute_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef IRIS_ZZ_X4_CORE_DETAIL_STRICT_ATTRIBUTE_PARSER_HPP
#define IRIS_ZZ_X4_CORE_DETAIL_STRICT_ATTRIBUTE_PARSER_HPP

/*=============================================================================
Copyright (c) 2026 The Iris Project Contributors

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 <iris/config.hpp> // IWYU pragma: keep

#include <iris/x4/traits/container_traits.hpp>

#include <iris/container_traits.hpp>

#include <ranges> // IWYU pragma: keep
#include <utility>

namespace iris::x4 {

namespace detail {

// Passes `v`, the attribute of the strict-attribute parser (e.g. `x4::rule` or `x4::as<T>`), to the
// exposed attribute `s` by the ordinary assignment. A container which holds the preceding results
// keeps them, and the value assigned to a new container is appended to it.
//
// Caller must preliminarily check the validity of such operation by `X4StrictlyWritable<S&, V&&>`.
template<class S, class V>
constexpr void pass_declared_attribute(S& s, V&& v)
{
if constexpr (traits::X4Container<S>) {
if (!std::ranges::empty(s)) {
S assigned{};
assigned = std::forward<V>(v);
iris::container::transfer_from(s, std::move(assigned));
return;
}
}
s = std::forward<V>(v);
}

} // detail

} // iris::x4

#endif
18 changes: 0 additions & 18 deletions include/iris/x4/core/write_attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <iris/config.hpp> // IWYU pragma: keep

#include <iris/x4/core/traits/write_rank.hpp>
#include <iris/x4/traits/container_traits.hpp>

#include <iris/rvariant/rvariant.hpp>
#include <iris/alloy/traits.hpp>
Expand Down Expand Up @@ -344,23 +343,6 @@ struct write_attribute_fn

} // detail

// Passes `v`, the attribute of `x4::rule` or `x4::as<T>`, to the exposed attribute `s` by the ordinary
// assignment, which the caller has checked by `X4StrictlyWritable<S&, V&&>`. A container which holds
// the preceding results keeps them: the value assigned to a new container is appended to it.
template<class S, class V>
constexpr void pass_declared_attribute(S& s, V&& v)
{
if constexpr (traits::X4Container<S>) {
if (!std::ranges::empty(s)) {
S assigned{};
assigned = std::forward<V>(v);
iris::container::transfer_from(s, std::move(assigned));
return;
}
}
s = std::forward<V>(v);
}

// Writes `v`, a part of a sequence or the value of one parse of a repetition, into the container
// `s`: as a new element, part by part, or a range appended (P(S, y))
template<class S, class V>
Expand Down
2 changes: 0 additions & 2 deletions include/iris/x4/debug/annotate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <iris/x4/core/context.hpp>
#include <iris/x4/core/attribute.hpp>

#include <iris/x4/debug/error_handler.hpp>

#include <iris/enum/enum.hpp>

#include <iterator>
Expand Down
9 changes: 4 additions & 5 deletions include/iris/x4/rule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@

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

#include <iris/x4/core/traits/tuple_traits.hpp>
#include <iris/x4/core/traits/write_rank.hpp>
#include <iris/x4/core/write_attribute.hpp>
#include <iris/x4/traits/container_traits.hpp>

#include <iris/x4/core/detail/strict_attribute_parser.hpp>
#include <iris/x4/core/traits/tuple_traits.hpp>
#include <iris/x4/core/parser.hpp>
#include <iris/x4/core/skip_over.hpp>
#include <iris/x4/core/expectation.hpp>
Expand Down Expand Up @@ -143,7 +142,7 @@ struct rule : parser<rule<RuleID>>
if (!detail::call_parse_rule<RuleID>(first, last, rule_agnostic_ctx, detail::rule_attr_ref<RuleID>{rule_attr})) {
return false;
}
planner::pass_declared_attribute(exposed_attr, std::move(rule_attr));
detail::pass_declared_attribute(exposed_attr, std::move(rule_attr));
return true;
}
}
Expand All @@ -160,7 +159,7 @@ struct rule : parser<rule<RuleID>>
if (!detail::call_parse_rule<RuleID>(first, last, rule_agnostic_ctx, detail::rule_attr_ref<RuleID>{rule_attr})) {
return false;
}
planner::pass_declared_attribute(exposed_attr, iris::unwrap_recursive(std::move(rule_attr)));
detail::pass_declared_attribute(exposed_attr, iris::unwrap_recursive(std::move(rule_attr)));
return true;
}
}
Expand Down
Loading