[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

Nicolas van Kempen via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 05:28:48 PST 2025


================
@@ -0,0 +1,785 @@
+//===-- Mustache.cpp ------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include <sstream>
+
+using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
+
+namespace {
+
+static bool isFalsey(const Value &V) {
+  return V.getAsNull() || (V.getAsBoolean() && !V.getAsBoolean().value()) ||
+         (V.getAsArray() && V.getAsArray()->empty()) ||
+         (V.getAsObject() && V.getAsObject()->empty());
+}
----------------
nicovank wrote:

```suggestion
static bool isFalsey(const Value &V) {
  return V.getAsNull() || (V.getAsBoolean() && !V.getAsBoolean().value()) ||
         (V.getAsArray() && V.getAsArray()->empty());
}
```

>From manual:

> If the person key exists and has a value of false or an empty list ...

Seems like empty objects are truthy. I quickly checked in some online Mustache playground: at least one other implementation agrees.

(All of these should have a test).

https://github.com/llvm/llvm-project/pull/105893


More information about the llvm-commits mailing list