From 3741a1b354b17822d1908272010d5ff6c2246605 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 2 Oct 2006 15:00:53 +0000 Subject: [PATCH] Word boundary checks on control structure keywords. Also, try to recognize if guard followed by comment. --- ctopy | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ctopy b/ctopy index 90b69d8..09368c8 100755 --- 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"(?