wisp
 
(Arne Babenhauserheide)
2014-01-21: work on fixing : as only non-whitespace on a line.

work on fixing : as only non-whitespace on a line.

diff --git a/.bugs/bugs b/.bugs/bugs
--- a/.bugs/bugs
+++ b/.bugs/bugs
@@ -1,6 +1,7 @@
 fails when I add stuff at the end of end of example.w        | owner:, open:False, id:08c68e1ce0c9798184c01806d2661a3220bff3cd, time:1363789693.79
 add a testsuite for wisp parsers.                            | owner:, open:True, id:1c05d27ac916e1a823b8985a094947907c3c19af, time:1379064922.74
 wisp-mode: export wisp to html fails in org-mode: font-lock-fontify-keywords-region: Invalid regexp | owner:, open:True, id:1e46d8c05580c961c37a32d36c987a5dd1d34943, time:1389371020.39
+an empty line with : should start with double parens         | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:2e188ddf44d36e4605030d3c58607ebfa97d189e, time:1390328674.43
 wisp-in-wisp: remove the leading . for continuation lines after inferring the brackets. | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:2e42e5b64622f0cc383eb8acc3d510912e925bf0, time:1377476687.79
 wisp: handle general paren prefixes like quote, quasiquote, etc. | owner:, open:False, id:323ff94b5be635742619467e1cb44f4c0d96f63f, time:1379047798.47
 throw an exception when reducing indentation to an unknown indentation level. | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:424186bd85f186b7279c5c59e2bd42f847284719, time:1376003568.91
diff --git a/tests/syntax-colon.scm b/tests/syntax-colon.scm
--- a/tests/syntax-colon.scm
+++ b/tests/syntax-colon.scm
@@ -28,3 +28,5 @@
       '())))
 
 
+(
+  (a)
diff --git a/tests/syntax-colon.w b/tests/syntax-colon.w
--- a/tests/syntax-colon.w
+++ b/tests/syntax-colon.w
@@ -23,6 +23,9 @@ let
 let : : a ' :
 
 let 
-  : 
+  :   
     a
       '
+
+:
+  a
diff --git a/wisp-guile.w b/wisp-guile.w
--- a/wisp-guile.w
+++ b/wisp-guile.w
@@ -21,7 +21,9 @@
 define-module : wisp
    . #:export : wisp2lisp wisp-chunkreader
 
-use-modules : : srfi srfi-1
+use-modules 
+    : srfi srfi-1
+    : ice-9 regex
 
 define : endsinunevenbackslashes text ; comment
        if : = 0 : string-length text
@@ -470,29 +472,39 @@ define : line-add-starting-bracket line
 
 If line starts with one of ' , ` #` #' #, #,@, then turn it into '(... instead of ('...
 
-The line *must* have a whitespace after the prefix."
-    let loop : : paren-prefixes : list "' " ", " "` " "#` " "#' " "#, " "#,@, "
-        ; first check whether we are done checking
-        if : null-list? paren-prefixes
-            ; construct the line structure: '(indentation-depth content comment)
-            list 
-                line-indent line
-                string-append 
-                    . "("
-                    line-content line
-                line-comment line
-            ; otherwise check all possible prefixes
-            let : : prefix : car paren-prefixes
-                if : string-prefix? prefix : line-content line
-                    list 
-                        line-indent line
-                        string-append 
-                            . (string-drop-right prefix 1) "("
-                            string-drop (line-content line) : string-length prefix
-                        line-comment line
-                    ; else
-                    loop : cdr paren-prefixes
-    
+If line is indented and only contains : and optional whitespace, remove the :.
+
+The line *must* have a whitespace after the prefix, except if the prefix is the only non-whitespace on the line."
+    ; if the line only contains a colon, we just replace its content with an opening paren.
+    if : string-match "^: *$" : line-content line ; FIXME: Check for this somewhere else.
+         list 
+             line-indent line
+             string-append "(" : string-drop (line-content line) 1 ; keep whitespace
+             line-comment line
+         let loop : : paren-prefixes : list "' " ", " "` " "#` " "#' " "#, " "#,@, "
+             ; first check whether we are done checking
+             if : null-list? paren-prefixes
+                 ; construct the line structure: '(indentation-depth content comment)
+                 list 
+                     line-indent line
+                     string-append 
+                         . "("
+                         line-content line
+                     line-comment line
+                 ; otherwise check all possible prefixes
+                 let : : prefix : car paren-prefixes
+                     if 
+                         or : string-prefix? prefix : line-content line
+                              equal? prefix : line-content line
+                         list 
+                             line-indent line
+                             string-append 
+                                 . (string-drop-right prefix 1) "("
+                                 string-drop (line-content line) : string-length prefix
+                             line-comment line
+                         ; else
+                         loop : cdr paren-prefixes
+       
 define : line-add-closing-brackets line number
     . "Add a closing bracket to the line."
     list