Re: [PATCH master 14/52] Add support for RE patterns to convert constants

2012-01-11 Thread René Nussbaumer
On Wed, Jan 11, 2012 at 11:15, Iustin Pop  wrote:
> On Wed, Jan 11, 2012 at 10:51:56AM +0100, René Nussbaumer wrote:
>> On Mon, Jan 9, 2012 at 11:58, Iustin Pop  wrote:
>> > This is a trivial conversion.
>> > ---
>> >  autotools/convert-constants |   10 ++
>> >  1 files changed, 10 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/autotools/convert-constants b/autotools/convert-constants
>> > index 89f9f00..ae36774 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)
>>
>> According to the doc, this is always a string. Any reason to anyway
>> going over HaskellTypeVal?
>
> Oh, just because the HaskellTypeVal will do the quoting correctly for
> us; otherwise we'd have to re-do it. So yes, we could use directly
> String for the type, but we're using it for the Value.

Fair enough :). LGTM.

René


Re: [PATCH master 14/52] Add support for RE patterns to convert constants

2012-01-11 Thread Iustin Pop
On Wed, Jan 11, 2012 at 10:51:56AM +0100, René Nussbaumer wrote:
> On Mon, Jan 9, 2012 at 11:58, Iustin Pop  wrote:
> > This is a trivial conversion.
> > ---
> >  autotools/convert-constants |   10 ++
> >  1 files changed, 10 insertions(+), 0 deletions(-)
> >
> > diff --git a/autotools/convert-constants b/autotools/convert-constants
> > index 89f9f00..ae36774 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)
> 
> According to the doc, this is always a string. Any reason to anyway
> going over HaskellTypeVal?

Oh, just because the HaskellTypeVal will do the quoting correctly for
us; otherwise we'd have to re-do it. So yes, we could use directly
String for the type, but we're using it for the Value.

iustin


Re: [PATCH master 14/52] Add support for RE patterns to convert constants

2012-01-11 Thread René Nussbaumer
On Mon, Jan 9, 2012 at 11:58, Iustin Pop  wrote:
> This is a trivial conversion.
> ---
>  autotools/convert-constants |   10 ++
>  1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/autotools/convert-constants b/autotools/convert-constants
> index 89f9f00..ae36774 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)

According to the doc, this is always a string. Any reason to anyway
going over HaskellTypeVal?

Rest LGTM

René


[PATCH master 14/52] Add support for RE patterns to convert constants

2012-01-09 Thread Iustin Pop
This is a trivial conversion.
---
 autotools/convert-constants |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/autotools/convert-constants b/autotools/convert-constants
index 89f9f00..ae36774 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
-- 
1.7.3.1