[llvm] [clangd] Support square bracket escaping in Annotations (PR #69379)

Aleksey Fefelov via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 17 13:33:53 PDT 2023


https://github.com/fefaleksey created https://github.com/llvm/llvm-project/pull/69379

The `Annotations` class is not supporting C++ attributes `[[...]]` because the attributes are parsed as a selection. The proposed improvement allows `[`, `]` characters to be escaped (example: `\[\[nodiscard\]\]`), allowing attributes to be used.

>From 7b7141d9a84cf337e54c5fcc636b56fd296b7d87 Mon Sep 17 00:00:00 2001
From: Aleksei Fefelov <fefaleksey at gmail.com>
Date: Tue, 17 Oct 2023 20:03:39 +0300
Subject: [PATCH] Support square bracket shielding in Annotations

---
 llvm/lib/Testing/Annotations/Annotations.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/llvm/lib/Testing/Annotations/Annotations.cpp b/llvm/lib/Testing/Annotations/Annotations.cpp
index 1e6852619a874a1..6efd5ad31f408c4 100644
--- a/llvm/lib/Testing/Annotations/Annotations.cpp
+++ b/llvm/lib/Testing/Annotations/Annotations.cpp
@@ -60,6 +60,14 @@ Annotations::Annotations(llvm::StringRef Text) {
       OpenRanges.pop_back();
       continue;
     }
+    if (Text.consume_front("\\[")) {
+      Code.push_back('[');
+      continue;
+    }
+    if (Text.consume_front("\\]")) {
+      Code.push_back(']');
+      continue;
+    }
     if (Text.consume_front("$")) {
       Name =
           Text.take_while([](char C) { return llvm::isAlnum(C) || C == '_'; });



More information about the llvm-commits mailing list