[PATCH] D128708: [pseudo] Simplify/loosen the grammar around lambda captures.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 06:56:36 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGaacefc817d93: [pseudo] Simplify/loosen the grammar around lambda captures. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128708/new/

https://reviews.llvm.org/D128708

Files:
  clang-tools-extra/pseudo/lib/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/capture-list.cpp


Index: clang-tools-extra/pseudo/test/cxx/capture-list.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/capture-list.cpp
@@ -0,0 +1,23 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+// We loosely allow capture defaults in any position/multiple times.
+auto lambda = [&, &foo, bar(x), =]{};
+// CHECK:      lambda-introducer := [ capture-list ]
+// CHECK-NEXT: ├─[
+// CHECK-NEXT: ├─capture-list
+// CHECK-NEXT: │ ├─capture-list
+// CHECK-NEXT: │ │ ├─capture-list
+// CHECK-NEXT: │ │ │ ├─capture-list~& := tok[4]
+// CHECK-NEXT: │ │ │ ├─,
+// CHECK-NEXT: │ │ │ └─capture~simple-capture
+// CHECK-NEXT: │ │ │   ├─&
+// CHECK-NEXT: │ │ │   └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │ ├─,
+// CHECK-NEXT: │ │ └─capture~init-capture
+// CHECK-NEXT: │ │   ├─IDENTIFIER := tok[9]
+// CHECK-NEXT: │ │   └─initializer := ( expression-list )
+// CHECK-NEXT: │ │     ├─(
+// CHECK-NEXT: │ │     ├─expression-list~IDENTIFIER := tok[11]
+// CHECK-NEXT: │ │     └─)
+// CHECK-NEXT: │ ├─,
+// CHECK-NEXT: │ └─capture~=
+// CHECK-NEXT: └─]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===================================================================
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -76,17 +76,17 @@
 nested-name-specifier := nested-name-specifier TEMPLATE_opt simple-template-id ::
 lambda-expression := lambda-introducer lambda-declarator_opt compound-statement
 lambda-expression := lambda-introducer < template-parameter-list > requires-clause_opt lambda-declarator_opt compound-statement
-lambda-introducer := [ lambda-capture_opt ]
+#! We allow a capture-default to appear anywhere in a capture-list.
+# This simplifies the grammar and error recovery.
+lambda-introducer := [ capture-list_opt ]
 lambda-declarator := ( parameter-declaration-clause_opt ) decl-specifier-seq_opt noexcept-specifier_opt trailing-return-type_opt requires-clause_opt
-lambda-capture := capture-default
-lambda-capture := capture-list
-lambda-capture := capture-default , capture-list
-capture-default := &
-capture-default := =
 capture-list := capture
 capture-list := capture-list , capture
+capture := capture-default
 capture := simple-capture
 capture := init-capture
+capture-default := &
+capture-default := =
 simple-capture := IDENTIFIER ..._opt
 simple-capture := & IDENTIFIER ..._opt
 simple-capture := THIS


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128708.440602.patch
Type: text/x-patch
Size: 2601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220628/67e241d3/attachment-0001.bin>


More information about the cfe-commits mailing list