1be691f3bSpatrick //===-- CommandObjectRegexCommand.h -----------------------------*- C++ -*-===// 2be691f3bSpatrick // 3be691f3bSpatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4be691f3bSpatrick // See https://llvm.org/LICENSE.txt for license information. 5be691f3bSpatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6be691f3bSpatrick // 7be691f3bSpatrick //===----------------------------------------------------------------------===// 8be691f3bSpatrick 9be691f3bSpatrick #ifndef LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 10be691f3bSpatrick #define LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 11be691f3bSpatrick 12be691f3bSpatrick #include <list> 13be691f3bSpatrick 14be691f3bSpatrick #include "lldb/Interpreter/CommandObject.h" 15be691f3bSpatrick #include "lldb/Utility/CompletionRequest.h" 16be691f3bSpatrick #include "lldb/Utility/RegularExpression.h" 17be691f3bSpatrick 18be691f3bSpatrick namespace lldb_private { 19be691f3bSpatrick 20be691f3bSpatrick // CommandObjectRegexCommand 21be691f3bSpatrick 22be691f3bSpatrick class CommandObjectRegexCommand : public CommandObjectRaw { 23be691f3bSpatrick public: 24be691f3bSpatrick CommandObjectRegexCommand(CommandInterpreter &interpreter, 25be691f3bSpatrick llvm::StringRef name, llvm::StringRef help, 26be691f3bSpatrick llvm::StringRef syntax, uint32_t max_matches, 27be691f3bSpatrick uint32_t completion_type_mask, bool is_removable); 28be691f3bSpatrick 29be691f3bSpatrick ~CommandObjectRegexCommand() override; 30be691f3bSpatrick IsRemovable()31be691f3bSpatrick bool IsRemovable() const override { return m_is_removable; } 32be691f3bSpatrick 33be691f3bSpatrick bool AddRegexCommand(llvm::StringRef re_cstr, llvm::StringRef command_cstr); 34be691f3bSpatrick HasRegexEntries()35be691f3bSpatrick bool HasRegexEntries() const { return !m_entries.empty(); } 36be691f3bSpatrick 37be691f3bSpatrick void HandleCompletion(CompletionRequest &request) override; 38be691f3bSpatrick 39be691f3bSpatrick protected: 40be691f3bSpatrick bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override; 41be691f3bSpatrick 42*f6aab3d8Srobert /// Substitute variables of the format %\d+ in the input string. 43*f6aab3d8Srobert static llvm::Expected<std::string> SubstituteVariables( 44*f6aab3d8Srobert llvm::StringRef input, 45*f6aab3d8Srobert const llvm::SmallVectorImpl<llvm::StringRef> &replacements); 46*f6aab3d8Srobert 47be691f3bSpatrick struct Entry { 48be691f3bSpatrick RegularExpression regex; 49be691f3bSpatrick std::string command; 50be691f3bSpatrick }; 51be691f3bSpatrick 52be691f3bSpatrick typedef std::list<Entry> EntryCollection; 53be691f3bSpatrick const uint32_t m_max_matches; 54be691f3bSpatrick const uint32_t m_completion_type_mask; 55be691f3bSpatrick EntryCollection m_entries; 56be691f3bSpatrick bool m_is_removable; 57be691f3bSpatrick 58be691f3bSpatrick private: 59be691f3bSpatrick CommandObjectRegexCommand(const CommandObjectRegexCommand &) = delete; 60be691f3bSpatrick const CommandObjectRegexCommand & 61be691f3bSpatrick operator=(const CommandObjectRegexCommand &) = delete; 62be691f3bSpatrick }; 63be691f3bSpatrick 64be691f3bSpatrick } // namespace lldb_private 65be691f3bSpatrick 66be691f3bSpatrick #endif // LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 67