From 45cbdc1a2af6d171456b44524cb085c05e40d24a Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 9 Dec 2025 23:14:49 +0800 Subject: [PATCH] fix: fix gcc build issue --- src/yycc/carton/clap/parser.cpp | 78 ++++++++++++++++----------------- src/yycc/env.hpp | 1 + 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/yycc/carton/clap/parser.cpp b/src/yycc/carton/clap/parser.cpp index 1e9c757..dad2b16 100644 --- a/src/yycc/carton/clap/parser.cpp +++ b/src/yycc/carton/clap/parser.cpp @@ -61,45 +61,6 @@ namespace yycc::carton::clap::parser { #pragma region Core - /// @brief Core capture function. - template - static TYPES::ClapResult>> capture(const APPLICATION::Application& app, V&& args) { - // Create context. - ParserContext ctx(app); - - // Fetch commandline arguments - // And skip the first argument because it is the path to executable. - // Then start to execute until all arguments are consumed. - for (const auto& arg : args | std::views::drop(1)) { - // Fetch argument kind - ClassifiedArgument classified_arg(arg); - - // Execute handler according to state. - TYPES::ClapResult rv; - switch (ctx.state) { - case ParserState::Normal: - rv = normal_state(ctx, classified_arg); - break; - case ParserState::WaitingValue: - rv = waiting_value_state(ctx, classified_arg); - break; - } - if (!rv.has_value()) { - return std::unexpected(rv.error()); - } - } - - // If the final state is waiting value, - // it means that the last option lose its asociated value. - // So we need report error. - if (ctx.state == ParserState::WaitingValue && ctx.opt_waiting.has_value()) { - return std::unexpected(TYPES::ClapError::LostValue); - } - - // Return capture result. - return ctx.values; - } - /// @brief The handler for state machine Normal state. static TYPES::ClapResult normal_state(ParserContext& ctx, const ClassifiedArgument& arg) { // Do thing according all registered options. @@ -167,6 +128,45 @@ namespace yycc::carton::clap::parser { return {}; } + /// @brief Core capture function. + template + static TYPES::ClapResult>> capture(const APPLICATION::Application& app, V&& args) { + // Create context. + ParserContext ctx(app); + + // Fetch commandline arguments + // And skip the first argument because it is the path to executable. + // Then start to execute until all arguments are consumed. + for (const auto& arg : args | std::views::drop(1)) { + // Fetch argument kind + ClassifiedArgument classified_arg(arg); + + // Execute handler according to state. + TYPES::ClapResult rv; + switch (ctx.state) { + case ParserState::Normal: + rv = normal_state(ctx, classified_arg); + break; + case ParserState::WaitingValue: + rv = waiting_value_state(ctx, classified_arg); + break; + } + if (!rv.has_value()) { + return std::unexpected(rv.error()); + } + } + + // If the final state is waiting value, + // it means that the last option lose its asociated value. + // So we need report error. + if (ctx.state == ParserState::WaitingValue && ctx.opt_waiting.has_value()) { + return std::unexpected(TYPES::ClapError::LostValue); + } + + // Return capture result. + return ctx.values; + } + #pragma endregion #pragma region Parser Class diff --git a/src/yycc/env.hpp b/src/yycc/env.hpp index 5ff4f22..5d74b03 100644 --- a/src/yycc/env.hpp +++ b/src/yycc/env.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include