@@ -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
@@ -87,7 +88,7 @@ static inline char* GetEnv(const char* Var_Name) {
87
88
88
89
#include " cling/Utils/AST.h"
89
90
90
- #include < regex>
91
+ // #include <regex>
91
92
92
93
namespace Cpp {
93
94
namespace Cpp_utils = cling::utils;
@@ -158,17 +159,24 @@ inline void codeComplete(std::vector<std::string>& Results,
158
159
std::vector<std::string> results;
159
160
size_t column = complete_column;
160
161
I.codeComplete (code, column, results);
162
+ std::string error;
163
+ // Regex patterns
164
+ llvm::Regex removeDefinition (" \\ [\\ #.*\\ #\\ ]" );
165
+ llvm::Regex removeVariableName (" (\\ |\\ *)+(\\ w+)(\\ #\\ >)" );
166
+ llvm::Regex removeTrailingSpace (" \\ *(\\ #\\ >)" );
167
+ llvm::Regex removeTags (" \\ <\\ #([^#>]*)\\ #\\ >" );
161
168
162
169
// append cleaned results
163
170
for (auto & r : results) {
164
- // remove the definition at the beginning (for example [#int#])
165
- r = std::regex_replace (r, std::regex ( " \\ [ \\ #.* \\ # \\ ] " ), " " );
171
+ // remove the definition at the beginning (e.g., [#int#])
172
+ r = removeDefinition. sub ( " " , r, &error );
166
173
// remove the variable name in <#type name#>
167
- r = std::regex_replace (r, std::regex ( " ( \\ | \\ *)+( \\ w+)( \\ # \\ >) " ), " $1$3" );
174
+ r = removeVariableName. sub ( " $1$3" , r, &error );
168
175
// remove unnecessary space at the end of <#type #>
169
- r = std::regex_replace (r, std::regex ( " \\ *( \\ # \\ >) " ), " $1" );
176
+ r = removeTrailingSpace. sub ( " $1" , r, &error );
170
177
// remove <# #> to keep only the type
171
- r = std::regex_replace (r, std::regex (" \\ <\\ #([^#>]*)\\ #\\ >" ), " $1" );
178
+ r = removeTags.sub (" $1" , r, &error);
179
+
172
180
if (r.find (code) == 0 )
173
181
Results.push_back (r);
174
182
}
0 commit comments