]> thyrsus.com Git - ctopy.git/commitdiff
Word boundary checks on control structure keywords.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 2 Oct 2006 15:00:53 +0000 (15:00 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 2 Oct 2006 15:00:53 +0000 (15:00 +0000)
Also, try to recognize if guard followed by comment.

ctopy

diff --git a/ctopy b/ctopy
index 90b69d8dc8a63ed21303a681ebd4862116bb8e30..09368c808143743a6cbcc0bc6b174bba67f84b5c 100755 (executable)
--- a/ctopy
+++ b/ctopy
@@ -104,19 +104,20 @@ post_transformations = (
     (r"#define\s+(%(id)s)\(([^)]*)\)\s+(.*\))", r"def \1(\2):\treturn \3"),
     (r"#define\s+(%(id)s)\(([^)]*)\)\s+([^(].*)", r"def \1(\2):\t\3"),
     # control structure
-    (r"if *\(", r"if "),
-    (r"while *\(", r"while "), 
-    (r"while 1:", r"while True"),
-    (r"for \(;;\)\s*{", r"while True"),
-    (r"for \((%(id)s) *= *0; *\1 *<= *([^;]+); *\1\+\+\)",
+    (r"\bif *\(", r"if "),
+    (r"\bwhile *\(", r"while "), 
+    (r"\bwhile 1:", r"while True"),
+    (r"\bfor \(;;\)\s*{", r"while True"),
+    (r"\bfor \((%(id)s) *= *0; *\1 *<= *([^;]+); *\1\+\+\)",
                                        r"for \1 in range(\2+1))"),
-    (r"for \((%(id)s) *= *(\d+); *\1 *<= *([^;]+); *\1\+\+\)",
+    (r"\bfor \((%(id)s) *= *(\d+); *\1 *<= *([^;]+); *\1\+\+\)",
                                        r"for \1 in range(\2, \3+1))"),
-    (r"for \((%(id)s) *= *0; *\1 *< *([^;]+); *\1\+\+\)",
+    (r"\bfor \((%(id)s) *= *0; *\1 *< *([^;]+); *\1\+\+\)",
                                        r"for \1 in range(\2))"),
-    (r"for \((%(id)s) *= *(\d+); *\1 *< *([^;]+); *\1\+\+\)",
+    (r"\bfor \((%(id)s) *= *(\d+); *\1 *< *([^;]+); *\1\+\+\)",
                                        r"for \1 in range(\2, \3))"),
     (r"\)\s*{", r":"),
+    (r"\)\s*\Z", r":"),                # ) followed by end of region, must be comment
     (r"(?<!\()\) *\n([ \t]+)", r":\n\1"),      # ) not followed by ; but by indent
     (r"else if", r"elif"),
     (r"else *{", r"else"),