diff --git a/lib/Interpreter/Compatibility.h b/lib/Interpreter/Compatibility.h index d6efc732..178bb9e6 100644 --- a/lib/Interpreter/Compatibility.h +++ b/lib/Interpreter/Compatibility.h @@ -77,6 +77,7 @@ static inline char* GetEnv(const char* Var_Name) { #include "llvm/ExecutionEngine/Orc/LLJIT.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Regex.h" #ifdef USE_CLING @@ -163,17 +164,24 @@ inline void codeComplete(std::vector& Results, std::vector results; size_t column = complete_column; I.codeComplete(code, column, results); + std::string error; + // Regex patterns + llvm::Regex removeDefinition("\\[\\#.*\\#\\]"); + llvm::Regex removeVariableName("(\\ |\\*)+(\\w+)(\\#\\>)"); + llvm::Regex removeTrailingSpace("\\ *(\\#\\>)"); + llvm::Regex removeTags("\\<\\#([^#>]*)\\#\\>"); // append cleaned results - for (auto& r : results) { - // remove the definition at the beginning (for example [#int#]) - r = std::regex_replace(r, std::regex("\\[\\#.*\\#\\]"), ""); + for (auto &r : results) { + // remove the definition at the beginning (e.g., [#int#]) + r = removeDefinition.sub("", r, &error); // remove the variable name in <#type name#> - r = std::regex_replace(r, std::regex("(\\ |\\*)+(\\w+)(\\#\\>)"), "$1$3"); + r = removeVariableName.sub("$1$3", r, &error); // remove unnecessary space at the end of <#type #> - r = std::regex_replace(r, std::regex("\\ *(\\#\\>)"), "$1"); + r = removeTrailingSpace.sub("$1", r, &error); // remove <# #> to keep only the type - r = std::regex_replace(r, std::regex("\\<\\#([^#>]*)\\#\\>"), "$1"); + r = removeTags.sub("$1", r, &error); + if (r.find(code) == 0) Results.push_back(r); }