Skip to content

Commit

Permalink
Replace std::regex in codecomplete to use llvm::regex
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronj0 committed Jan 9, 2025
1 parent 508823a commit 118ef46
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/Interpreter/Compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -163,17 +164,24 @@ inline void codeComplete(std::vector<std::string>& Results,
std::vector<std::string> 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);
}
Expand Down

0 comments on commit 118ef46

Please sign in to comment.