From: Eric S. Raymond Date: Sun, 1 Oct 2006 07:41:50 +0000 (+0000) Subject: Improved comment processing. X-Git-Tag: 1.0~49 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=0b6091819d27cecc27f51ba314671e62a8e8d593;p=ctopy.git Improved comment processing. --- diff --git a/ctopy b/ctopy index b8e70aa..4a1eadd 100755 --- a/ctopy +++ b/ctopy @@ -82,9 +82,9 @@ region_transformations = ( # externs can just disappear -- this may discard a following comment (r"extern[^;]+;.*\n", r""), # macros - (r"#define\s+(%(id)s)\s+(.*)[ \t]*\n", r"\1\t= \2\n"), - (r"#define\s+(%(id)s)\(([^)]*)\)\s+(.*\))[ \t]*\n", r"def \1(\2):\treturn \3\n"), - (r"#define\s+(%(id)s)\(([^)]*)\)\s+([^(].*)[ \t]*\n", r"def \1(\2):\t\3\n"), + (r"#define\s+(%(id)s)\s+(.*)[ \t]*(?=\n|$)", r"\1\t= \2"), + (r"#define\s+(%(id)s)\(([^)]*)\)\s+(.*\))[ \t]*(?=\n|$)", r"def \1(\2):\treturn \3"), + (r"#define\s+(%(id)s)\(([^)]*)\)\s+([^(].*)[ \t]*(?=\n|$)", r"def \1(\2):\t\3"), # function headers (r"(?:^|\n)(?:static\s+)?(?:%(type)s) +(.*\)) *\n", r"\ndef \1:\n"), (r"\(void\):\n", r"():\n"), @@ -227,8 +227,8 @@ def ctopy(input, debug=0): boundaries.append(i+1) state = "text" boundaries.append(len(input)) - if boundaries[0] == 0: - boundaries.pop(0) + if debug >= 2: + print "Boundaries:", boundaries if debug: print "Regexp transformation begins" regions = []