From 3d6ac9037deb2d3f042023719caf906cc873f6c9 Mon Sep 17 00:00:00 2001 From: Nana Sakisaka <1901813+saki7@users.noreply.github.com> Date: Sat, 14 Feb 2026 20:41:19 +0900 Subject: [PATCH] Improve error diagnostics --- include/iris/x4/core/action.hpp | 8 +++++++- include/iris/x4/core/skip_over.hpp | 19 +++++++++++++++++++ include/iris/x4/directive/skip.hpp | 19 +++++++++++++++++++ include/iris/x4/operator/alternative.hpp | 10 ++++++++++ include/iris/x4/operator/list.hpp | 10 ++++++++++ include/iris/x4/operator/sequence.hpp | 22 ++++++++++++++++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) diff --git a/include/iris/x4/core/action.hpp b/include/iris/x4/core/action.hpp index aeb90c3e6..f5aa6c5bf 100644 --- a/include/iris/x4/core/action.hpp +++ b/include/iris/x4/core/action.hpp @@ -17,11 +17,12 @@ #include #include -#include +#include // subrange #include #include #include #include +#include namespace iris::x4 { @@ -109,6 +110,11 @@ struct action : proxy_parser> constexpr void operator[](auto const&) const = delete; // You can't add semantic action for semantic action + [[nodiscard]] constexpr std::string get_x4_info() const + { + return std::format("{}[f]", get_info{}(this->subject)); + } + private: // Semantic action with no parameter: `p[([] { /* ... */ })]` template diff --git a/include/iris/x4/core/skip_over.hpp b/include/iris/x4/core/skip_over.hpp index d312c6f95..511820e64 100644 --- a/include/iris/x4/core/skip_over.hpp +++ b/include/iris/x4/core/skip_over.hpp @@ -42,6 +42,25 @@ enum struct builtin_skipper_kind : char space, }; +namespace detail { + +template +struct builtin_skipper_traits; + +template<> +struct builtin_skipper_traits +{ + static constexpr char const* name = "blank"; +}; + +template<> +struct builtin_skipper_traits +{ + static constexpr char const* name = "space"; +}; + +} // detail + template Se, class Context> requires X4Subject> constexpr void skip_over(It& first, Se const& last, Context const& ctx) diff --git a/include/iris/x4/directive/skip.hpp b/include/iris/x4/directive/skip.hpp index 33c594e3d..29aa8cde6 100644 --- a/include/iris/x4/directive/skip.hpp +++ b/include/iris/x4/directive/skip.hpp @@ -17,6 +17,7 @@ #include +#include #include #include #include @@ -49,6 +50,15 @@ struct skip_directive : proxy_parser> return this->subject.parse(first, last, x4::replace_first_context(ctx, skipper_), attr); } + [[nodiscard]] constexpr std::string get_x4_info() const + { + return std::format( + "skip({})[{}]", + get_info{}(this->skipper_), + get_info{}(this->subject) + ); + } + private: template using context_t = std::remove_cvref_tsubject.parse(first, last, x4::replace_first_context(ctx, skipper_kind), attr); } + + [[nodiscard]] constexpr std::string get_x4_info() const + { + return std::format( + "skip({})[{}]", + detail::builtin_skipper_traits::name, + get_info{}(this->subject) + ); + } }; diff --git a/include/iris/x4/operator/alternative.hpp b/include/iris/x4/operator/alternative.hpp index 84a1a323a..8c2029c29 100644 --- a/include/iris/x4/operator/alternative.hpp +++ b/include/iris/x4/operator/alternative.hpp @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -153,6 +154,15 @@ struct alternative : binary_parser> } return false; // `attr` is untouched } + + [[nodiscard]] constexpr std::string get_x4_info() const + { + return std::format( + "{} | {}", + get_info{}(this->left), + get_info{}(this->right) + ); + } }; template diff --git a/include/iris/x4/operator/list.hpp b/include/iris/x4/operator/list.hpp index 1fc2589ab..8c23f0183 100644 --- a/include/iris/x4/operator/list.hpp +++ b/include/iris/x4/operator/list.hpp @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -63,6 +64,15 @@ struct list : binary_parser> return true; } } + + [[nodiscard]] constexpr std::string get_x4_info() const + { + return std::format( + "({} % {})", + get_info{}(this->left), + get_info{}(this->right) + ); + } }; template diff --git a/include/iris/x4/operator/sequence.hpp b/include/iris/x4/operator/sequence.hpp index b2d95c11d..f6184fbd0 100644 --- a/include/iris/x4/operator/sequence.hpp +++ b/include/iris/x4/operator/sequence.hpp @@ -20,7 +20,9 @@ #include #include +#include +#include #include #include #include @@ -28,6 +30,9 @@ namespace iris::x4 { +template +struct expect_directive; + template struct sequence : binary_parser> { @@ -74,6 +79,23 @@ struct sequence : binary_parser> { return detail::parse_sequence(*this, first, last, ctx, attr); } + + [[nodiscard]] constexpr std::string get_x4_info() const + { + if constexpr (iris::is_ttp_specialization_of_v) { + return std::format( + "{} > {}", + get_info{}(this->left), + get_info{}(this->right.subject) + ); + } else { + return std::format( + "{} >> {}", + get_info{}(this->left), + get_info{}(this->right) + ); + } + } }; template