]> gitweb.factorcode.org Git - factor.git/commitdiff
Multiline cleanup and bug fix
authorDaniel Ehrenberg <littledan@Macintosh-103.local>
Tue, 20 Jan 2009 22:12:09 +0000 (16:12 -0600)
committerDaniel Ehrenberg <littledan@Macintosh-103.local>
Tue, 20 Jan 2009 22:12:09 +0000 (16:12 -0600)
basis/multiline/multiline-tests.factor
basis/multiline/multiline.factor

index 357fd2cb6c15069100bd4e1b10169d764ae540da..25acd9400b9cbb98490b8ad403f09d5eb88db600 100644 (file)
@@ -14,3 +14,5 @@ bar
 
 [ "hello\nworld" ] [ <" hello
 world"> ] unit-test
+
+[ "hello" "world" ] [ <" hello"> <" world"> ] unit-test
index 930e5b9f1ce63936d40298c39eca1cbec1247dd5..87379519442c68546a2814ab64e4d5c6ba83d61e 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
 USING: namespaces make parser lexer kernel sequences words
-quotations math accessors ;
+quotations math accessors locals ;
 IN: multiline
 
 <PRIVATE
@@ -26,20 +26,26 @@ PRIVATE>
     (( -- string )) define-inline ; parsing
 
 <PRIVATE
-: (parse-multiline-string) ( start-index end-text -- end-index )
-    lexer get line-text>> [
-        2dup start
-        [ rot dupd [ swap subseq % ] 2dip length + ] [
-            rot tail % "\n" % 0
-            lexer get next-line swap (parse-multiline-string)
+
+:: (parse-multiline-string) ( i end -- j )
+    lexer get line-text>> :> text
+    text [
+        end text i start*
+        [| j | i j text subseq % j end length + ] [
+            text i tail % CHAR: \n ,
+            lexer get next-line
+            0 end (parse-multiline-string)
         ] if*
-    ] [ nip unexpected-eof ] if* ;
+    ] [ end unexpected-eof ] if ;
+        
 PRIVATE>
 
 : parse-multiline-string ( end-text -- str )
     [
-        lexer get [ swap (parse-multiline-string) ] change-column drop
-    ] "" make rest ;
+        lexer get
+        [ 1+ swap (parse-multiline-string) ]
+        change-column drop
+    ] "" make ;
 
 : <"
     "\">" parse-multiline-string parsed ; parsing