SyntaxModel: simplify the collecting of contextual keywords in PrecedenceGroup.NFC (#11819)
diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h
index 5bb47c3..73fac0f 100644
--- a/include/swift/AST/Decl.h
+++ b/include/swift/AST/Decl.h
@@ -6054,8 +6054,6 @@
return { getLowerThanBuffer(), NumLowerThan };
}
- void collectOperatorKeywordRanges(SmallVectorImpl<CharSourceRange> &Ranges);
-
static bool classof(const Decl *D) {
return D->getKind() == DeclKind::PrecedenceGroup;
}
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 1bb2355..b1fe924 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -5343,18 +5343,6 @@
lowerThan.size() * sizeof(Relation));
}
-void PrecedenceGroupDecl::collectOperatorKeywordRanges(
- SmallVectorImpl<CharSourceRange> &Ranges) {
- auto AddToRange = [&] (SourceLoc Loc, StringRef Word) {
- if (Loc.isValid())
- Ranges.push_back(CharSourceRange(Loc, strlen(Word.data())));
- };
- AddToRange(AssociativityKeywordLoc, "associativity");
- AddToRange(AssignmentKeywordLoc, "assignment");
- AddToRange(HigherThanLoc, "higherThan");
- AddToRange(LowerThanLoc, "lowerThan");
-}
-
bool FuncDecl::isDeferBody() const {
return getName() == getASTContext().getIdentifier("$defer");
}
diff --git a/lib/IDE/SyntaxModel.cpp b/lib/IDE/SyntaxModel.cpp
index ff0d714..3237870 100644
--- a/lib/IDE/SyntaxModel.cpp
+++ b/lib/IDE/SyntaxModel.cpp
@@ -832,14 +832,6 @@
CharSourceRange(ConfigD->getEndLoc(), 6/*'#endif'*/) }))
return false;
- } else if (auto PrecD = dyn_cast<PrecedenceGroupDecl>(D)) {
- // Highlight specifiers like "associativity" or "assignment" as keywords.
- SmallVector<CharSourceRange, 3> KeywordsRanges;
- PrecD->collectOperatorKeywordRanges(KeywordsRanges);
- for (auto &Range : KeywordsRanges) {
- passNonTokenNode({SyntaxNodeKind::Keyword, Range});
- };
-
} else if (auto OperD = dyn_cast<OperatorDecl>(D)) {
if (!passNonTokenNode({ SyntaxNodeKind::Keyword,
CharSourceRange(OperD->getOperatorLoc(), strlen("operator")) }))
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index c2a5b4d..788e357 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -6054,6 +6054,9 @@
auto attrName = Tok.getText();
if (attrName == "associativity") {
+ // "associativity" is considered as a contextual keyword.
+ TokReceiver->registerTokenKindChange(Tok.getLoc(),
+ tok::contextual_keyword);
parseAttributePrefix(associativityKeywordLoc);
if (!Tok.is(tok::identifier)) {
@@ -6079,6 +6082,9 @@
if (attrName == "assignment") {
parseAttributePrefix(assignmentKeywordLoc);
+ // "assignment" is considered as a contextual keyword.
+ TokReceiver->registerTokenKindChange(assignmentKeywordLoc,
+ tok::contextual_keyword);
if (consumeIf(tok::kw_true, assignmentValueLoc)) {
assignment = true;
} else if (consumeIf(tok::kw_false, assignmentValueLoc)) {
@@ -6093,6 +6099,9 @@
bool isLowerThan = false;
if (attrName == "higherThan" ||
(isLowerThan = (attrName == "lowerThan"))) {
+ // "lowerThan" and "higherThan" are contextual keywords.
+ TokReceiver->registerTokenKindChange(Tok.getLoc(),
+ tok::contextual_keyword);
parseAttributePrefix(isLowerThan ? lowerThanKeywordLoc
: higherThanKeywordLoc);
auto &relations = (isLowerThan ? lowerThan : higherThan);