wisp
 
(Arne Babenhauserheide)
2013-08-08: FIX: comments containing a closing parenthesis could break the v0.3.1

FIX: comments containing a closing parenthesis could break the parser → the linebreak-killing-code in brackets had to be aware of comments.

diff --git a/.bugs/bugs b/.bugs/bugs
--- a/.bugs/bugs
+++ b/.bugs/bugs
@@ -2,4 +2,4 @@ fails when I add stuff at the end of end
 implement wisp in wisp                                       | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:6299306916706410702029289bf32edab1e7f17c, time:1367113341.49
 inline ' : should be '(                                      | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:72d534a8b23b4cb168017f1bb7d8816f0ea170c4, time:1366497335.26
 make this work: let : : origfile ( open-file : nth 1 : command-line ) r | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:d6de2074a5017f1f29f34d142ce797981ed270a0, time:1366529287.67
-comments containing a closing parenthesis can break the parser. | owner:, open:True, id:d9147504868960e5fbc2648474d48ce5c9bd1a02, time:1374838747.22
+comments containing a closing parenthesis can break the parser. | owner:, open:False, id:d9147504868960e5fbc2648474d48ce5c9bd1a02, time:1374838747.22
diff --git a/tests/quotecolon.w b/tests/quotecolon.w
new file mode 100755
--- /dev/null
+++ b/tests/quotecolon.w
@@ -0,0 +1,10 @@
+#!/home/arne/wisp/wisp-multiline.sh  
+; !#
+define a 1 ; test whether ' : correctly gets turned into '(
+; and whether brackets in commments are treated correctly.
+
+define a ' : 1 2 3
+
+define
+  a b
+  c
diff --git a/wisp.py b/wisp.py
--- a/wisp.py
+++ b/wisp.py
@@ -47,8 +47,8 @@ def replaceinwisp(code, string, replacem
     strlen = len(string)
     for n in range(len(code) - strlen):
         i = code[n]
-        # comments start with a ; - but only in regular wisp code.
-        if not incomment and not instring and not inbrackets and i == ";" and not code[n-2:n] == "#\\":
+        # comments start with a ; - but only in regular wisp code or in brackets.
+        if not incomment and not instring and i == ";" and not code[n-2:n] == "#\\":
             incomment = not incomment
         # a linebreak ends the comment
         if incomment:
@@ -219,9 +219,20 @@ def nostringbreaks(code):
 def nobracketbreaks(code):
     """remove linebreaks inside brackets (will be readded at the end)."""
     instring = False
+    incomment = False
     inbracket = 0
     nostringbreaks = []
     for n, char in enumerate(code):
+        # comments start with a ; - but only in regular wisp code or in brackets.
+        if not incomment and not instring and char == ";" and not code[n-2:n] == "#\\":
+            incomment = not incomment
+        # a linebreak ends the comment
+        if incomment:
+            if char == "\n":
+                incomment = not incomment
+            # all processing stops in comments
+            nostringbreaks.append(char)
+            continue
         if char == '"' and not code[n-1:n] == "\\":
             instring = not instring
         if char == '(' and not instring and not code[n-2:n] == "#\\":