#pragma once #include "CommandTypes.h" #include "Execute.h" #include "Token.h" #include #include #include #include #include class TokenParser { BAN_NON_COPYABLE(TokenParser); BAN_NON_MOVABLE(TokenParser); public: using InputFunction = BAN::Function(BAN::Optional)>; public: TokenParser(const InputFunction& input_function) : m_input_function(input_function) { } Execute& execute() { return m_execute; } const Execute& execute() const { return m_execute; } [[nodiscard]] bool main_loop(bool break_on_error); private: const Token& peek_token() const; Token read_token(); void consume_token(); BAN::ErrorOr feed_tokens(BAN::Vector&& tokens); BAN::ErrorOr unget_token(Token&& token); BAN::ErrorOr ask_input_tokens(BAN::StringView prompt, bool add_newline); BAN::ErrorOr run(BAN::Vector&&); BAN::ErrorOr parse_backslash(bool is_quoted); BAN::ErrorOr parse_dollar(); BAN::ErrorOr parse_single_quote(); BAN::ErrorOr parse_argument(); BAN::ErrorOr parse_single_command(); BAN::ErrorOr parse_piped_command(); BAN::ErrorOr parse_command_tree(); private: Execute m_execute; Token m_eof_token { Token::Type::EOF_ }; BAN::Queue> m_token_stream; InputFunction m_input_function; };