[PATCH] D33679: Make clang-query close parens for you

Matt Kulukundis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 30 08:29:03 PDT 2017


fowles created this revision.

Make clang-query close parens for you


https://reviews.llvm.org/D33679

Files:
  clang-query/QueryParser.cpp


Index: clang-query/QueryParser.cpp
===================================================================
--- clang-query/QueryParser.cpp
+++ clang-query/QueryParser.cpp
@@ -15,6 +15,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include <set>
+#include <string>
 
 using namespace llvm;
 using namespace clang::ast_matchers::dynamic;
@@ -210,13 +211,27 @@
     if (CompletionPos)
       return completeMatcherExpression();
 
-    Diagnostics Diag;
-    Optional<DynTypedMatcher> Matcher = Parser::parseMatcherExpression(
-        StringRef(Begin, End - Begin), nullptr, &QS.NamedValues, &Diag);
-    if (!Matcher) {
-      return makeInvalidQueryFromDiagnostics(Diag);
+    Diagnostics FirstDiag;
+    std::string Query = StringRef(Begin, End - Begin).str();
+    while (true) {
+      Diagnostics Diag;
+      Diagnostics* CurrentDiag = FirstDiag.errors().empty() ? &FirstDiag : &Diag;
+      Optional<DynTypedMatcher> Matcher = Parser::parseMatcherExpression(
+          Query, nullptr, &QS.NamedValues, CurrentDiag);
+      if (Matcher) {
+        return new MatchQuery(*Matcher);
+      }
+      for (const auto& Error : CurrentDiag->errors()) {
+        for (const auto &Message : Error.Messages) {
+          if (Message.Type == Diagnostics::ET_ParserNoCloseParen) {
+            Query += ")";
+          } else {
+            // Report the first error before we mucked with the query.
+            return makeInvalidQueryFromDiagnostics(FirstDiag);
+          }
+        }
+      }
     }
-    return new MatchQuery(*Matcher);
   }
 
   case PQK_Set: {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33679.100713.patch
Type: text/x-patch
Size: 1587 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170530/eb57cb30/attachment.bin>


More information about the cfe-commits mailing list