From 26fce8df121580802b3089c84f6229d2c748c702 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 23 Dec 2011 11:13:34 +0100
Subject: [PATCH] Add support for RE patterns to convert constants
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is a trivial conversion.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 autotools/convert-constants | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/autotools/convert-constants b/autotools/convert-constants
index 89f9f007f..ae367749a 100755
--- a/autotools/convert-constants
+++ b/autotools/convert-constants
@@ -27,8 +27,12 @@ import re
 from ganeti import constants
 from ganeti import compat
 
+#: Constant name regex
 CONSTANT_RE = re.compile("^[A-Z][A-Z0-9_-]+$")
 
+#: The type of regex objects
+RE_TYPE = type(CONSTANT_RE)
+
 
 def NameRules(name):
   """Converts the upper-cased Python name to Haskell camelCase.
@@ -129,6 +133,12 @@ def ConvertVariable(name, value):
         lines.append("-- | Skipped list/set %s, is not homogeneous" % name)
     else:
       lines.append("-- | Skipped list/set %s, cannot convert all elems" % name)
+  elif isinstance(value, RE_TYPE):
+    tvs = HaskellTypeVal(value.pattern)
+    assert tvs is not None
+    lines.append("-- | Converted from Python RE object %s" % name)
+    lines.append("%s :: %s" % (hs_name, tvs[0]))
+    lines.append("%s = %s" % (hs_name, tvs[1]))
   else:
     lines.append("-- Skipped %s, %s not handled" % (name, type(value)))
   return lines
-- 
GitLab