aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/regex-combinators.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/regex-combinators.hh')
-rw-r--r--src/libutil/regex-combinators.hh30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libutil/regex-combinators.hh b/src/libutil/regex-combinators.hh
new file mode 100644
index 000000000..0b997b25a
--- /dev/null
+++ b/src/libutil/regex-combinators.hh
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <string_view>
+
+namespace nix::regex {
+
+// TODO use constexpr string building like
+// https://github.com/akrzemi1/static_string/blob/master/include/ak_toolkit/static_string.hpp
+
+static inline std::string either(std::string_view a, std::string_view b)
+{
+ return std::string { a } + "|" + b;
+}
+
+static inline std::string group(std::string_view a)
+{
+ return std::string { "(" } + a + ")";
+}
+
+static inline std::string many(std::string_view a)
+{
+ return std::string { "(?:" } + a + ")*";
+}
+
+static inline std::string list(std::string_view a)
+{
+ return std::string { a } + many(group("," + a));
+}
+
+}