[libc-commits] [libc] [libc][regex] Wire regex entrypoints to ExprPool matcher (PR #232291)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Fri Oct 16 07:57:00 PDT 2026


================
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Brzozowski derivative evaluation and regular expression matching
+/// implementation.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/regex/regex_matcher.h"
+
+#include "src/__support/CPP/string_view.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/regex/regex_ast.h"
+#include "src/__support/regex/regex_expr_pool.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace regex {
+
+ErrorOr<ExprId> derivative(ExprId id, char c, ExprPool &pool) {
+  const Expr e = pool.get(id);
+  switch (e.kind) {
+  case ExprKind::EmptySet:
+  case ExprKind::EmptyStr:
+    return EMPTY_SET_ID;
+  case ExprKind::Literal:
+    return (c == e.ch) ? EMPTY_STR_ID : EMPTY_SET_ID;
+  case ExprKind::Concat: {
+    // Product Rule:
+    // D_c(L . R) = (D_c(L) . R) | (nullable(L) ? D_c(R) : EmptySet)
+    const bool left_nullable = pool.is_nullable(e.bin.left);
+    ErrorOr<ExprId> d_l = derivative(e.bin.left, c, pool);
+    if (!d_l.has_value())
+      return d_l;
+    ErrorOr<ExprId> lhs = pool.make_concat(d_l.value(), e.bin.right);
----------------
kaladron wrote:

I've updated these to use operator*

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


More information about the libc-commits mailing list