@@ -77,6 +77,7 @@ static inline char* GetEnv(const char* Var_Name) {
77
77
#include " llvm/ExecutionEngine/Orc/LLJIT.h"
78
78
#include " llvm/Support/Casting.h"
79
79
#include " llvm/Support/Path.h"
80
+ #include " llvm/Support/Regex.h"
80
81
81
82
#ifdef USE_CLING
82
83
@@ -163,17 +164,24 @@ inline void codeComplete(std::vector<std::string>& Results,
163
164
std::vector<std::string> results;
164
165
size_t column = complete_column;
165
166
I.codeComplete (code, column, results);
167
+ std::string error;
168
+ // Regex patterns
169
+ llvm::Regex removeDefinition (" \\ [\\ #.*\\ #\\ ]" );
170
+ llvm::Regex removeVariableName (" (\\ |\\ *)+(\\ w+)(\\ #\\ >)" );
171
+ llvm::Regex removeTrailingSpace (" \\ *(\\ #\\ >)" );
172
+ llvm::Regex removeTags (" \\ <\\ #([^#>]*)\\ #\\ >" );
166
173
167
174
// append cleaned results
168
- for (auto & r : results) {
169
- // remove the definition at the beginning (for example [#int#])
170
- r = std::regex_replace (r, std::regex ( " \\ [ \\ #.* \\ # \\ ] " ), " " );
175
+ for (auto & r : results) {
176
+ // remove the definition at the beginning (e.g., [#int#])
177
+ r = removeDefinition. sub ( " " , r, &error );
171
178
// remove the variable name in <#type name#>
172
- r = std::regex_replace (r, std::regex ( " ( \\ | \\ *)+( \\ w+)( \\ # \\ >) " ), " $1$3" );
179
+ r = removeVariableName. sub ( " $1$3" , r, &error );
173
180
// remove unnecessary space at the end of <#type #>
174
- r = std::regex_replace (r, std::regex ( " \\ *( \\ # \\ >) " ), " $1" );
181
+ r = removeTrailingSpace. sub ( " $1" , r, &error );
175
182
// remove <# #> to keep only the type
176
- r = std::regex_replace (r, std::regex (" \\ <\\ #([^#>]*)\\ #\\ >" ), " $1" );
183
+ r = removeTags.sub (" $1" , r, &error);
184
+
177
185
if (r.find (code) == 0 )
178
186
Results.push_back (r);
179
187
}
0 commit comments