Remy Farley 041a8a9e5a
[clang-query] Allow for trailing comma in matchers (#148018)
Allow AST matches in clang-query to have a trailing comma at the end of
matcher arguments. Makes it nicer to work with queries that span
multiple lines.

So, for example, the following is possible:

```clang-query
match namedDecl(
  isExpansionInMainFile(),
  anyOf(
    varDecl().bind("var"),
    functionDecl().bind("func"),
    # enumDecl().bind("enum"),
  ),
)
```
2025-07-15 14:09:24 -04:00

22 lines
753 B
C

void foo(void) {}
// CHECK-OK: trailing-comma.c:1:1: note: "root" binds here
// CHECK-ERR-COMMA: Invalid token <,> found when looking for a value.
// RUN: clang-query -c "match \
// RUN: functionDecl( \
// RUN: hasName( \
// RUN: \"foo\", \
// RUN: ), \
// RUN: ) \
// RUN: " %s | FileCheck --check-prefix=CHECK-OK %s
// Same with \n tokens
// RUN: echo "match functionDecl( hasName( \"foo\" , ) , )" | sed "s/ /\n/g" >%t
// RUN: clang-query -f %t %s | FileCheck --check-prefix=CHECK-OK %s
// RUN: not clang-query -c "match functionDecl(hasName(\"foo\"),,)" %s \
// RUN: | FileCheck --check-prefix=CHECK-ERR-COMMA %s
// RUN: not clang-query -c "match functionDecl(,)" %s \
// RUN: | FileCheck --check-prefix=CHECK-ERR-COMMA %s