1f034231aSEd Maste //===-- CommandObjectRegexCommand.h -----------------------------*- C++ -*-===// 2f034231aSEd Maste // 35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6f034231aSEd Maste // 7f034231aSEd Maste //===----------------------------------------------------------------------===// 8f034231aSEd Maste 9cfca06d7SDimitry Andric #ifndef LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 10cfca06d7SDimitry Andric #define LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 11f034231aSEd Maste 12f034231aSEd Maste #include <list> 13f034231aSEd Maste 14f034231aSEd Maste #include "lldb/Interpreter/CommandObject.h" 15f73363f1SDimitry Andric #include "lldb/Utility/CompletionRequest.h" 1674a628f7SDimitry Andric #include "lldb/Utility/RegularExpression.h" 17f034231aSEd Maste 18f034231aSEd Maste namespace lldb_private { 19f034231aSEd Maste 20f034231aSEd Maste // CommandObjectRegexCommand 21f034231aSEd Maste 2214f1b3e8SDimitry Andric class CommandObjectRegexCommand : public CommandObjectRaw { 23f034231aSEd Maste public: 24b60736ecSDimitry Andric CommandObjectRegexCommand(CommandInterpreter &interpreter, 25b60736ecSDimitry Andric llvm::StringRef name, llvm::StringRef help, 267fa27ce4SDimitry Andric llvm::StringRef syntax, 27b60736ecSDimitry Andric uint32_t completion_type_mask, bool is_removable); 28f034231aSEd Maste 29e81d9d49SDimitry Andric ~CommandObjectRegexCommand() override; 30f034231aSEd Maste IsRemovable()3114f1b3e8SDimitry Andric bool IsRemovable() const override { return m_is_removable; } 32205afe67SEd Maste 33b60736ecSDimitry Andric bool AddRegexCommand(llvm::StringRef re_cstr, llvm::StringRef command_cstr); 34f034231aSEd Maste HasRegexEntries()3514f1b3e8SDimitry Andric bool HasRegexEntries() const { return !m_entries.empty(); } 36f034231aSEd Maste 37ead24645SDimitry Andric void HandleCompletion(CompletionRequest &request) override; 38f034231aSEd Maste 39f034231aSEd Maste protected: 40b1c73532SDimitry Andric void DoExecute(llvm::StringRef command, CommandReturnObject &result) override; 41f034231aSEd Maste 42145449b1SDimitry Andric /// Substitute variables of the format %\d+ in the input string. 43145449b1SDimitry Andric static llvm::Expected<std::string> SubstituteVariables( 44145449b1SDimitry Andric llvm::StringRef input, 45145449b1SDimitry Andric const llvm::SmallVectorImpl<llvm::StringRef> &replacements); 46145449b1SDimitry Andric 4714f1b3e8SDimitry Andric struct Entry { 48f034231aSEd Maste RegularExpression regex; 49f034231aSEd Maste std::string command; 50f034231aSEd Maste }; 51f034231aSEd Maste 52f034231aSEd Maste typedef std::list<Entry> EntryCollection; 53f034231aSEd Maste const uint32_t m_completion_type_mask; 54f034231aSEd Maste EntryCollection m_entries; 55205afe67SEd Maste bool m_is_removable; 56f034231aSEd Maste 57f034231aSEd Maste private: 58cfca06d7SDimitry Andric CommandObjectRegexCommand(const CommandObjectRegexCommand &) = delete; 59cfca06d7SDimitry Andric const CommandObjectRegexCommand & 60cfca06d7SDimitry Andric operator=(const CommandObjectRegexCommand &) = delete; 61f034231aSEd Maste }; 62f034231aSEd Maste 63f034231aSEd Maste } // namespace lldb_private 64f034231aSEd Maste 65cfca06d7SDimitry Andric #endif // LLDB_INTERPRETER_COMMANDOBJECTREGEXCOMMAND_H 66