[IDE] Use std::regex to match the syntax that the comment URL regex strings are using.

rdar://17782541

Swift SVN r20810
This commit is contained in:
Argyrios Kyrtzidis
2014-07-31 05:04:06 +00:00
parent c0e593b533
commit 9d7f29b2d7
2 changed files with 12 additions and 8 deletions

View File

@@ -25,12 +25,11 @@
#include "swift/Subsystems.h" #include "swift/Subsystems.h"
#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Regex.h"
#include <vector> #include <vector>
#include <regex>
using namespace swift; using namespace swift;
using namespace ide; using namespace ide;
using llvm::Regex;
void SyntaxModelWalker::anchor() {} void SyntaxModelWalker::anchor() {}
@@ -150,9 +149,10 @@ class ModelASTWalker : public ASTWalker {
unsigned BufferID; unsigned BufferID;
std::vector<StructureElement> SubStructureStack; std::vector<StructureElement> SubStructureStack;
SourceLoc LastLoc; SourceLoc LastLoc;
Regex URLRxs[3] = { { RegexStrURL, Regex::Newline }, std::regex URLRxs[3] = {
{ RegexStrMailURL, Regex::Newline }, std::regex{ RegexStrURL, std::regex::ECMAScript | std::regex::nosubs },
{ RegexStrRadarURL, Regex::Newline } }; std::regex{ RegexStrMailURL, std::regex::ECMAScript | std::regex::nosubs },
std::regex{ RegexStrRadarURL, std::regex::ECMAScript | std::regex::nosubs }};
public: public:
SyntaxModelWalker &Walker; SyntaxModelWalker &Walker;
@@ -854,15 +854,16 @@ bool ModelASTWalker::searchForURL(CharSourceRange Range) {
StringRef Text = OrigText; StringRef Text = OrigText;
while (1) { while (1) {
SmallVector<StringRef, 4> Matches; std::match_results<StringRef::iterator> Matches;
for (auto &Rx : URLRxs) { for (auto &Rx : URLRxs) {
bool HadMatch = Rx.match(Text, &Matches); bool HadMatch = std::regex_search(Text.begin(), Text.end(), Matches, Rx);
if (HadMatch) if (HadMatch)
break; break;
} }
if (Matches.empty()) if (Matches.empty())
break; break;
StringRef Match = Matches[0]; auto &RxMatch = Matches[0];
StringRef Match(RxMatch.first, RxMatch.second - RxMatch.first);
SourceLoc Loc = OrigLoc.getAdvancedLoc(Match.data() - OrigText.data()); SourceLoc Loc = OrigLoc.getAdvancedLoc(Match.data() - OrigText.data());
CharSourceRange Range(Loc, Match.size()); CharSourceRange Range(Loc, Match.size());
SyntaxNode Node{ SyntaxNodeKind::CommentURL, Range }; SyntaxNode Node{ SyntaxNodeKind::CommentURL, Range };

View File

@@ -286,3 +286,6 @@ func test5() -> Int {
// CHECK: <comment-line>// <comment-url>http://whatever.com?ee=2&yy=1</comment-url> and <comment-url>radar://123456</comment-url></comment-line> // CHECK: <comment-line>// <comment-url>http://whatever.com?ee=2&yy=1</comment-url> and <comment-url>radar://123456</comment-url></comment-line>
// CHECK: <comment-block>/* <comment-url>http://whatever.com</comment-url> <comment-marker>FIXME: see in <comment-url>http://whatever.com/fixme</comment-url></comment-marker> // CHECK: <comment-block>/* <comment-url>http://whatever.com</comment-url> <comment-marker>FIXME: see in <comment-url>http://whatever.com/fixme</comment-url></comment-marker>
// CHECK: <comment-url>http://whatever.com</comment-url> */</comment-block> // CHECK: <comment-url>http://whatever.com</comment-url> */</comment-block>
// CHECK: <comment-line>// <comment-url>http://whatever.com/what-ever</comment-url></comment-line>
// http://whatever.com/what-ever