(Arne Babenhauserheide)
2013-03-21: don’t turn : in explicit brackets or strings into new brackets. don’t turn : in explicit brackets or strings into new brackets.
diff --git a/example.w b/example.w
--- a/example.w
+++ b/example.w
@@ -9,8 +9,8 @@ do not break me!"
; comment
` g ; comment
:
- h (I am in brackets
- do not change me)
+ h (I am in brackets:
+ do not : change "me")
. i
, ' j k
@@ -20,7 +20,7 @@ do not break me!"
a c
-defun b : n o
- . "second defun, with a docstring!"
+defun b : :n o
+ . "second defun : with a docstring!"
message "I am here"
. t
diff --git a/wisp.py b/wisp.py
--- a/wisp.py
+++ b/wisp.py
@@ -66,9 +66,20 @@ class Line:
break
# treat inline " : " as opening a bracket which gets closed at the end of the line
- toclose = self.content.count(" : ")
- self.content = self.content.replace(" : ", " (")
- self.content += ")" * toclose
+ bracketstoclose = 0
+ instring = False
+ inbrackets = 0
+ for n, i in enumerate(self.content):
+ if i == '"':
+ instring = not instring
+ if not instring and i == "(":
+ inbrackets += 1
+ elif not instring and i == ")":
+ inbrackets -= 1
+ if not instring and not inbrackets and i == ":" and self.content[n-1:n+2] == " : ":
+ bracketstoclose += 1
+ self.content = self.content[:n] + "(" + self.content[n+1:]
+ self.content += ")" * bracketstoclose
#: Is the line effectively empty?
self.empty = False