]> thyrsus.com Git - ctopy.git/commitdiff
Improved comment processing.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 1 Oct 2006 07:41:50 +0000 (07:41 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 1 Oct 2006 07:41:50 +0000 (07:41 +0000)
ctopy

diff --git a/ctopy b/ctopy
index b8e70aa765836e1ede948c43063e2d050db5f841..4a1eadd6bac0b41feef081f09708ab77cd8f7bd0 100755 (executable)
--- 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 = []