[clang] 816cc43 - [ASTMatchers] Extract parsing of bind token from the bind id

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 7 07:41:35 PST 2021


Author: Stephen Kelly
Date: 2021-02-07T15:40:15Z
New Revision: 816cc432812724627835e66ed94a20a2478edef8

URL: https://github.com/llvm/llvm-project/commit/816cc432812724627835e66ed94a20a2478edef8
DIFF: https://github.com/llvm/llvm-project/commit/816cc432812724627835e66ed94a20a2478edef8.diff

LOG: [ASTMatchers] Extract parsing of bind token from the bind id

This will be extended to be able to parse "with" for mapAnyOf in
addition to "bind".

Added: 
    

Modified: 
    clang/lib/ASTMatchers/Dynamic/Parser.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/ASTMatchers/Dynamic/Parser.cpp b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
index 7715e2a17799..efe581284fb9 100644
--- a/clang/lib/ASTMatchers/Dynamic/Parser.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -366,6 +366,17 @@ bool Parser::parseIdentifierPrefixImpl(VariantValue *Value) {
       }
 
       std::string BindID;
+      Tokenizer->consumeNextToken();
+      TokenInfo BindToken = Tokenizer->consumeNextToken();
+      if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
+        addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
+        return false;
+      }
+      if (BindToken.Kind != TokenInfo::TK_Ident ||
+        BindToken.Text != TokenInfo::ID_Bind) {
+        Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
+        return false;
+      }
       if (!parseBindID(BindID))
         return false;
 
@@ -420,26 +431,13 @@ bool Parser::parseIdentifierPrefixImpl(VariantValue *Value) {
 }
 
 bool Parser::parseBindID(std::string &BindID) {
-  // Parse .bind("foo")
-  assert(Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period);
-  Tokenizer->consumeNextToken(); // consume the period.
-  const TokenInfo BindToken = Tokenizer->consumeNextToken();
-  if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
-    addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
-    return false;
-  }
-
+  // Parse the parenthesized argument to .bind("foo")
   const TokenInfo OpenToken = Tokenizer->consumeNextToken();
   const TokenInfo IDToken = Tokenizer->consumeNextTokenIgnoreNewlines();
   const TokenInfo CloseToken = Tokenizer->consumeNextTokenIgnoreNewlines();
 
   // TODO: We could use 
diff erent error codes for each/some to be more
   //       explicit about the syntax error.
-  if (BindToken.Kind != TokenInfo::TK_Ident ||
-      BindToken.Text != TokenInfo::ID_Bind) {
-    Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
-    return false;
-  }
   if (OpenToken.Kind != TokenInfo::TK_OpenParen) {
     Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr);
     return false;
@@ -518,6 +516,17 @@ bool Parser::parseMatcherExpressionImpl(const TokenInfo &NameToken,
 
   std::string BindID;
   if (Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period) {
+    Tokenizer->consumeNextToken();
+    TokenInfo BindToken = Tokenizer->consumeNextToken();
+    if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
+      addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
+      return false;
+    }
+    if (BindToken.Kind != TokenInfo::TK_Ident ||
+      BindToken.Text != TokenInfo::ID_Bind) {
+      Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
+      return false;
+    }
     if (!parseBindID(BindID))
       return false;
   }


        


More information about the cfe-commits mailing list