2025-12-14 23:24:59 +08:00
|
|
|
#pragma once
|
|
|
|
|
#include "../macro/class_copy_move.hpp"
|
|
|
|
|
#include <expected>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
|
|
namespace yycc::carton::lexer61 {
|
|
|
|
|
|
|
|
|
|
enum class LexerState { Space, Single, Double, Escape, Normal };
|
|
|
|
|
|
|
|
|
|
// @brief Any error occurs when lexer working.
|
|
|
|
|
enum class LexerError {
|
|
|
|
|
UnexpectedEnd, ///< The end of command line is not expected.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
using LexerResult = std::expected<T, LexerError>;
|
|
|
|
|
|
|
|
|
|
class Lexer61 {
|
|
|
|
|
public:
|
|
|
|
|
Lexer61();
|
|
|
|
|
~Lexer61();
|
|
|
|
|
YYCC_DEFAULT_COPY_MOVE(Lexer61)
|
|
|
|
|
|
|
|
|
|
public:
|
2025-12-15 13:47:07 +08:00
|
|
|
LexerResult<std::vector<std::u8string>> lex(const std::u8string_view& cmd);
|
2025-12-14 23:24:59 +08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
|
|
void proc_space();
|
|
|
|
|
void proc_single();
|
|
|
|
|
void proc_double();
|
|
|
|
|
void proc_escape();
|
|
|
|
|
void proc_normal();
|
|
|
|
|
|
2025-12-15 13:47:07 +08:00
|
|
|
std::vector<std::u8string> m_ArgsCollection; ///< Internal result holder.
|
|
|
|
|
std::u8string m_CurrentArg; ///< Holding current building commandline argument.
|
|
|
|
|
char8_t m_CurrentChar; ///< Holding current char analysing.
|
|
|
|
|
LexerState m_State; ///< Recording current state.
|
|
|
|
|
LexerState m_PrevState; ///< Recording previous state.
|
2025-12-14 23:24:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace yycc::carton::lexer61
|