From: Eric S. Raymond Date: Fri, 29 Sep 2006 02:29:21 +0000 (+0000) Subject: Simple for-loop translation enabled. X-Git-Tag: 1.0~58 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=6c4e6636624de692a2d8e008be8ae4fc623e88a7;p=ctopy.git Simple for-loop translation enabled. --- diff --git a/ctopy b/ctopy index b86fd98..04f6ee7 100755 --- a/ctopy +++ b/ctopy @@ -16,7 +16,9 @@ Then, apply the specified set of regular-expression mappings. Limitations: * Requires source to be syntactically valid, * Strange indentation (not one of the standard styles) will confuse it. - * Doesn't even attempt to translate for, switch/case or do/while. + * Translates simples kinds of for-loops with a straight increment of + a loop variable, but not the more complex ones. + * Doesn't even attempt to translate switch/case or do/while. * Doesn't attempt to translate ternary operator. * Won't put Python line continuations in multiline conditionals. * C comma expressions will spuriously turn into Python tuuple constructors, @@ -47,6 +49,14 @@ transformations = ( (r"while *\(", r"while "), (r"while 1:", r"while True"), (r"for \(;;\)\s*{", r"while True"), + (r"for \((%(id)s) *= *0; *\1 *< *(%(id)s); *\1\+\+\)", + r"for \1 in range(\2))"), + (r"for \((%(id)s) *= *0; *\1 *<= *(%(id)s); *\1\+\+\)", + r"for \1 in range(\2+1))"), + (r"for \((%(id)s) *= *(\d+); *\1 *< *(%(id)s); *\1\+\+\)", + r"for \1 in range(\2, \3))"), + (r"for \((%(id)s) *= *(\d+); *\1 *<= *(%(id)s); *\1\+\+\)", + r"for \1 in range(\2, \3+1))"), (r"\)\s*{", r":"), (r"(?